Package org.apache.mina.core.service
Class AbstractIoConnector
- java.lang.Object
-
- org.apache.mina.core.service.AbstractIoService
-
- org.apache.mina.core.service.AbstractIoConnector
-
- All Implemented Interfaces:
IoConnector
,IoService
- Direct Known Subclasses:
AbstractPollingIoConnector
,ProxyConnector
,SerialConnector
,VmPipeConnector
public abstract class AbstractIoConnector extends AbstractIoService implements IoConnector
A base implementation ofIoConnector
.- Author:
- Apache MINA Project
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.mina.core.service.AbstractIoService
AbstractIoService.ServiceOperationFuture
-
-
Field Summary
-
Fields inherited from class org.apache.mina.core.service.AbstractIoService
disposalLock, LOGGER, sessionConfig
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractIoConnector(IoSessionConfig sessionConfig, Executor executor)
Constructor forAbstractIoConnector
.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description ConnectFuture
connect()
Connects to thedefault remote address
.ConnectFuture
connect(SocketAddress remoteAddress)
Connects to the specified remote address.ConnectFuture
connect(SocketAddress remoteAddress, SocketAddress localAddress)
Connects to the specified remote address binding to the specified local address.ConnectFuture
connect(SocketAddress remoteAddress, SocketAddress localAddress, IoSessionInitializer<? extends ConnectFuture> sessionInitializer)
Connects to the specified remote address binding to the specified local address and and invokes theioSessionInitializer
when the IoSession is created but beforeIoHandler.sessionCreated(IoSession)
is invoked.ConnectFuture
connect(SocketAddress remoteAddress, IoSessionInitializer<? extends ConnectFuture> sessionInitializer)
Connects to the specified remote address and invokes theioSessionInitializer
when the IoSession is created but beforeIoHandler.sessionCreated(IoSession)
is invoked.ConnectFuture
connect(IoSessionInitializer<? extends ConnectFuture> sessionInitializer)
Connects to thedefault remote address
and invokes theioSessionInitializer
when the IoSession is created but beforeIoHandler.sessionCreated(IoSession)
is invoked.protected abstract ConnectFuture
connect0(SocketAddress remoteAddress, SocketAddress localAddress, IoSessionInitializer<? extends ConnectFuture> sessionInitializer)
Implement this method to perform the actual connect operation.protected void
finishSessionInitialization0(IoSession session, IoFuture future)
Adds required internal attributes andIoFutureListener
s related with event notifications to the specifiedsession
andfuture
.int
getConnectTimeout()
Deprecated.Take a look atgetConnectTimeoutMillis()
long
getConnectTimeoutCheckInterval()
long
getConnectTimeoutMillis()
SocketAddress
getDefaultLocalAddress()
SocketAddress
getDefaultRemoteAddress()
void
setConnectTimeout(int connectTimeout)
Deprecated.Take a look atsetConnectTimeoutMillis(long)
void
setConnectTimeoutCheckInterval(long minimumConnectTimeout)
Sets the timeout for the connection checkvoid
setConnectTimeoutMillis(long connectTimeoutInMillis)
Sets the connect timeout value in milliseconds.void
setDefaultLocalAddress(SocketAddress localAddress)
Sets the default local addressvoid
setDefaultRemoteAddress(SocketAddress defaultRemoteAddress)
Sets the default remote address to connect to when no argument is specified inIoConnector.connect()
method.String
toString()
-
Methods inherited from class org.apache.mina.core.service.AbstractIoService
addListener, broadcast, dispose, dispose, dispose0, executeWorker, executeWorker, getActivationTime, getFilterChain, getFilterChainBuilder, getHandler, getListeners, getManagedSessionCount, getManagedSessions, getScheduledWriteBytes, getScheduledWriteMessages, getSessionDataStructureFactory, getStatistics, initSession, isActive, isDisposed, isDisposing, removeListener, setFilterChainBuilder, setHandler, setSessionDataStructureFactory
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.mina.core.service.IoService
addListener, broadcast, dispose, dispose, getActivationTime, getFilterChain, getFilterChainBuilder, getHandler, getManagedSessionCount, getManagedSessions, getScheduledWriteBytes, getScheduledWriteMessages, getSessionConfig, getSessionDataStructureFactory, getStatistics, getTransportMetadata, isActive, isDisposed, isDisposing, removeListener, setFilterChainBuilder, setHandler, setSessionDataStructureFactory
-
-
-
-
Constructor Detail
-
AbstractIoConnector
protected AbstractIoConnector(IoSessionConfig sessionConfig, Executor executor)
Constructor forAbstractIoConnector
. You need to provide a default session configuration and anExecutor
for handling I/O events. If nullExecutor
is provided, a default one will be created usingExecutors.newCachedThreadPool()
.- Parameters:
sessionConfig
- the default configuration for the managedIoSession
executor
- theExecutor
used for handling execution of I/O events. Can benull
.- See Also:
AbstractIoService(IoSessionConfig, Executor)
-
-
Method Detail
-
getConnectTimeoutCheckInterval
public long getConnectTimeoutCheckInterval()
- Returns:
- The minimum time that this connector can have for a connection timeout in milliseconds.
-
setConnectTimeoutCheckInterval
public void setConnectTimeoutCheckInterval(long minimumConnectTimeout)
Sets the timeout for the connection check- Parameters:
minimumConnectTimeout
- The delay we wait before checking the connection
-
getConnectTimeout
@Deprecated public final int getConnectTimeout()
Deprecated.Take a look atgetConnectTimeoutMillis()
- Specified by:
getConnectTimeout
in interfaceIoConnector
- Returns:
- the connect timeout in seconds. The default value is 1 minute.
-
getConnectTimeoutMillis
public final long getConnectTimeoutMillis()
- Specified by:
getConnectTimeoutMillis
in interfaceIoConnector
- Returns:
- the connect timeout in milliseconds. The default value is 1 minute.
-
setConnectTimeout
@Deprecated public final void setConnectTimeout(int connectTimeout)
Deprecated.Take a look atsetConnectTimeoutMillis(long)
Description copied from interface:IoConnector
Sets the connect timeout in seconds. The default value is 1 minute.- Specified by:
setConnectTimeout
in interfaceIoConnector
- Parameters:
connectTimeout
- The time out for the connection
-
setConnectTimeoutMillis
public final void setConnectTimeoutMillis(long connectTimeoutInMillis)
Sets the connect timeout value in milliseconds.- Specified by:
setConnectTimeoutMillis
in interfaceIoConnector
- Parameters:
connectTimeoutInMillis
- The time out for the connection
-
getDefaultRemoteAddress
public SocketAddress getDefaultRemoteAddress()
- Specified by:
getDefaultRemoteAddress
in interfaceIoConnector
- Returns:
- the default remote address to connect to when no argument
is specified in
IoConnector.connect()
method.
-
setDefaultLocalAddress
public final void setDefaultLocalAddress(SocketAddress localAddress)
Sets the default local address- Specified by:
setDefaultLocalAddress
in interfaceIoConnector
- Parameters:
localAddress
- The default local address
-
getDefaultLocalAddress
public final SocketAddress getDefaultLocalAddress()
- Specified by:
getDefaultLocalAddress
in interfaceIoConnector
- Returns:
- the default local address
-
setDefaultRemoteAddress
public final void setDefaultRemoteAddress(SocketAddress defaultRemoteAddress)
Sets the default remote address to connect to when no argument is specified inIoConnector.connect()
method.- Specified by:
setDefaultRemoteAddress
in interfaceIoConnector
- Parameters:
defaultRemoteAddress
- The default remote address
-
connect
public final ConnectFuture connect()
Connects to thedefault remote address
.- Specified by:
connect
in interfaceIoConnector
- Returns:
- the
ConnectFuture
instance which is completed when the connection attempt initiated by this call succeeds or fails.
-
connect
public ConnectFuture connect(IoSessionInitializer<? extends ConnectFuture> sessionInitializer)
Connects to thedefault remote address
and invokes theioSessionInitializer
when the IoSession is created but beforeIoHandler.sessionCreated(IoSession)
is invoked. There is no guarantee that theioSessionInitializer
will be invoked before this method returns.- Specified by:
connect
in interfaceIoConnector
- Parameters:
sessionInitializer
- the callback to invoke when theIoSession
object is created- Returns:
- the
ConnectFuture
instance which is completed when the connection attempt initiated by this call succeeds or fails.
-
connect
public final ConnectFuture connect(SocketAddress remoteAddress)
Connects to the specified remote address.- Specified by:
connect
in interfaceIoConnector
- Parameters:
remoteAddress
- The remote address to connect to- Returns:
- the
ConnectFuture
instance which is completed when the connection attempt initiated by this call succeeds or fails.
-
connect
public ConnectFuture connect(SocketAddress remoteAddress, IoSessionInitializer<? extends ConnectFuture> sessionInitializer)
Connects to the specified remote address and invokes theioSessionInitializer
when the IoSession is created but beforeIoHandler.sessionCreated(IoSession)
is invoked. There is no guarantee that theioSessionInitializer
will be invoked before this method returns.- Specified by:
connect
in interfaceIoConnector
- Parameters:
remoteAddress
- the remote address to connect tosessionInitializer
- the callback to invoke when theIoSession
object is created- Returns:
- the
ConnectFuture
instance which is completed when the connection attempt initiated by this call succeeds or fails.
-
connect
public ConnectFuture connect(SocketAddress remoteAddress, SocketAddress localAddress)
Connects to the specified remote address binding to the specified local address.- Specified by:
connect
in interfaceIoConnector
- Parameters:
remoteAddress
- The remote address to connectlocalAddress
- The local address to bind- Returns:
- the
ConnectFuture
instance which is completed when the connection attempt initiated by this call succeeds or fails.
-
connect
public final ConnectFuture connect(SocketAddress remoteAddress, SocketAddress localAddress, IoSessionInitializer<? extends ConnectFuture> sessionInitializer)
Connects to the specified remote address binding to the specified local address and and invokes theioSessionInitializer
when the IoSession is created but beforeIoHandler.sessionCreated(IoSession)
is invoked. There is no guarantee that theioSessionInitializer
will be invoked before this method returns.- Specified by:
connect
in interfaceIoConnector
- Parameters:
remoteAddress
- the remote address to connect tolocalAddress
- the local interface to bind tosessionInitializer
- the callback to invoke when theIoSession
object is created- Returns:
- the
ConnectFuture
instance which is completed when the connection attempt initiated by this call succeeds or fails.
-
connect0
protected abstract ConnectFuture connect0(SocketAddress remoteAddress, SocketAddress localAddress, IoSessionInitializer<? extends ConnectFuture> sessionInitializer)
Implement this method to perform the actual connect operation.- Parameters:
remoteAddress
- The remote address to connect fromlocalAddress
-null
if no local address is specifiedsessionInitializer
- The IoSessionInitializer to use when the connection s successful- Returns:
- The ConnectFuture associated with this asynchronous operation
-
finishSessionInitialization0
protected final void finishSessionInitialization0(IoSession session, IoFuture future)
Adds required internal attributes andIoFutureListener
s related with event notifications to the specifiedsession
andfuture
. Do not call this method directly;- Overrides:
finishSessionInitialization0
in classAbstractIoService
- Parameters:
session
- The session to initializefuture
- The Future to use
-
-