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,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 protectedAbstractIoConnector(IoSessionConfig sessionConfig, Executor executor)Constructor forAbstractIoConnector.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description ConnectFutureconnect()Connects to thedefault remote address.ConnectFutureconnect(SocketAddress remoteAddress)Connects to the specified remote address.ConnectFutureconnect(SocketAddress remoteAddress, SocketAddress localAddress)Connects to the specified remote address binding to the specified local address.ConnectFutureconnect(SocketAddress remoteAddress, SocketAddress localAddress, IoSessionInitializer<? extends ConnectFuture> sessionInitializer)Connects to the specified remote address binding to the specified local address and and invokes theioSessionInitializerwhen the IoSession is created but beforeIoHandler.sessionCreated(IoSession)is invoked.ConnectFutureconnect(SocketAddress remoteAddress, IoSessionInitializer<? extends ConnectFuture> sessionInitializer)Connects to the specified remote address and invokes theioSessionInitializerwhen the IoSession is created but beforeIoHandler.sessionCreated(IoSession)is invoked.ConnectFutureconnect(IoSessionInitializer<? extends ConnectFuture> sessionInitializer)Connects to thedefault remote addressand invokes theioSessionInitializerwhen the IoSession is created but beforeIoHandler.sessionCreated(IoSession)is invoked.protected abstract ConnectFutureconnect0(SocketAddress remoteAddress, SocketAddress localAddress, IoSessionInitializer<? extends ConnectFuture> sessionInitializer)Implement this method to perform the actual connect operation.protected voidfinishSessionInitialization0(IoSession session, IoFuture future)Adds required internal attributes andIoFutureListeners related with event notifications to the specifiedsessionandfuture.intgetConnectTimeout()Deprecated.Take a look atgetConnectTimeoutMillis()longgetConnectTimeoutCheckInterval()longgetConnectTimeoutMillis()SocketAddressgetDefaultLocalAddress()SocketAddressgetDefaultRemoteAddress()voidsetConnectTimeout(int connectTimeout)Deprecated.Take a look atsetConnectTimeoutMillis(long)voidsetConnectTimeoutCheckInterval(long minimumConnectTimeout)Sets the timeout for the connection checkvoidsetConnectTimeoutMillis(long connectTimeoutInMillis)Sets the connect timeout value in milliseconds.voidsetDefaultLocalAddress(SocketAddress localAddress)Sets the default local addressvoidsetDefaultRemoteAddress(SocketAddress defaultRemoteAddress)Sets the default remote address to connect to when no argument is specified inIoConnector.connect()method.StringtoString()-
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 anExecutorfor handling I/O events. If nullExecutoris provided, a default one will be created usingExecutors.newCachedThreadPool().- Parameters:
sessionConfig- the default configuration for the managedIoSessionexecutor- theExecutorused 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:
getConnectTimeoutin interfaceIoConnector- Returns:
- the connect timeout in seconds. The default value is 1 minute.
-
getConnectTimeoutMillis
public final long getConnectTimeoutMillis()
- Specified by:
getConnectTimeoutMillisin 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:IoConnectorSets the connect timeout in seconds. The default value is 1 minute.- Specified by:
setConnectTimeoutin 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:
setConnectTimeoutMillisin interfaceIoConnector- Parameters:
connectTimeoutInMillis- The time out for the connection
-
getDefaultRemoteAddress
public SocketAddress getDefaultRemoteAddress()
- Specified by:
getDefaultRemoteAddressin 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:
setDefaultLocalAddressin interfaceIoConnector- Parameters:
localAddress- The default local address
-
getDefaultLocalAddress
public final SocketAddress getDefaultLocalAddress()
- Specified by:
getDefaultLocalAddressin 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:
setDefaultRemoteAddressin interfaceIoConnector- Parameters:
defaultRemoteAddress- The default remote address
-
connect
public final ConnectFuture connect()
Connects to thedefault remote address.- Specified by:
connectin interfaceIoConnector- Returns:
- the
ConnectFutureinstance 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 addressand invokes theioSessionInitializerwhen the IoSession is created but beforeIoHandler.sessionCreated(IoSession)is invoked. There is no guarantee that theioSessionInitializerwill be invoked before this method returns.- Specified by:
connectin interfaceIoConnector- Parameters:
sessionInitializer- the callback to invoke when theIoSessionobject is created- Returns:
- the
ConnectFutureinstance 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:
connectin interfaceIoConnector- Parameters:
remoteAddress- The remote address to connect to- Returns:
- the
ConnectFutureinstance 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 theioSessionInitializerwhen the IoSession is created but beforeIoHandler.sessionCreated(IoSession)is invoked. There is no guarantee that theioSessionInitializerwill be invoked before this method returns.- Specified by:
connectin interfaceIoConnector- Parameters:
remoteAddress- the remote address to connect tosessionInitializer- the callback to invoke when theIoSessionobject is created- Returns:
- the
ConnectFutureinstance 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:
connectin interfaceIoConnector- Parameters:
remoteAddress- The remote address to connectlocalAddress- The local address to bind- Returns:
- the
ConnectFutureinstance 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 theioSessionInitializerwhen the IoSession is created but beforeIoHandler.sessionCreated(IoSession)is invoked. There is no guarantee that theioSessionInitializerwill be invoked before this method returns.- Specified by:
connectin interfaceIoConnector- Parameters:
remoteAddress- the remote address to connect tolocalAddress- the local interface to bind tosessionInitializer- the callback to invoke when theIoSessionobject is created- Returns:
- the
ConnectFutureinstance 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-nullif 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 andIoFutureListeners related with event notifications to the specifiedsessionandfuture. Do not call this method directly;- Overrides:
finishSessionInitialization0in classAbstractIoService- Parameters:
session- The session to initializefuture- The Future to use
-
-