Class AprSocketConnector
- java.lang.Object
-
- org.apache.mina.core.service.AbstractIoService
-
- org.apache.mina.core.service.AbstractIoConnector
-
- org.apache.mina.core.polling.AbstractPollingIoConnector<AprSession,java.lang.Long>
-
- org.apache.mina.transport.socket.apr.AprSocketConnector
-
- All Implemented Interfaces:
IoConnector,IoService,SocketConnector
public final class AprSocketConnector extends AbstractPollingIoConnector<AprSession,java.lang.Long> implements SocketConnector
IoConnectorfor APR based socket transport (TCP/IP).- Author:
- Apache MINA Project
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.mina.core.polling.AbstractPollingIoConnector
AbstractPollingIoConnector.ConnectionRequest
-
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 Constructor Description AprSocketConnector()Create anAprSocketConnectorwith default configuration (multiple thread model).AprSocketConnector(int processorCount)Constructor forAprSocketConnectorwith default configuration, and given number ofAprIoProcessorfor multithreading I/O operationsAprSocketConnector(java.util.concurrent.Executor executor, IoProcessor<AprSession> processor)Constructor forAprSocketConnectorwith a givenExecutorfor handling connection events and a givenIoProcessorfor handling I/O events, useful for sharing the same processor and executor over multipleIoServiceof the same type.AprSocketConnector(IoProcessor<AprSession> processor)Constructor forAprSocketConnectorwith default configuration but a specificIoProcessor, useful for sharing the same processor over multipleIoServiceof the same type.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.util.Iterator<java.lang.Long>allHandles()Iteratorfor all the client sockets polled for connection.protected voidclose(java.lang.Long handle)Close a client socket.protected booleanconnect(java.lang.Long handle, java.net.SocketAddress remoteAddress)Connect a newly created client socket handle to a remoteSocketAddress.protected voiddestroy()Destroy the polling system, will be called when thisIoConnectorimplementation will be disposed.protected booleanfinishConnect(java.lang.Long handle)Finish the connection process of a client socket after it was marked as ready to process by theAbstractPollingIoConnector.select(int)call.protected AbstractPollingIoConnector.ConnectionRequestgetConnectionRequest(java.lang.Long handle)get theAbstractPollingIoConnector.ConnectionRequestfor a given client socket handlejava.net.InetSocketAddressgetDefaultRemoteAddress()SocketSessionConfiggetSessionConfig()TransportMetadatagetTransportMetadata()protected voidinit()Initialize the polling system, will be called at construction time.protected java.lang.LongnewHandle(java.net.SocketAddress localAddress)Create a new client socket handle from a localSocketAddressprotected AprSessionnewSession(IoProcessor<AprSession> processor, java.lang.Long handle)Create a newIoSessionfrom a connected socket client handle.protected voidregister(java.lang.Long handle, AbstractPollingIoConnector.ConnectionRequest request)Register a new client socket for connection, add it to connection pollingprotected intselect(int timeout)Check for connected sockets, interrupt when at least a connection is processed (connected or failed to connect).protected java.util.Iterator<java.lang.Long>selectedHandles()Iteratorfor the set of client sockets found connected or failed to connect during the lastAbstractPollingIoConnector.select(int)call.voidsetDefaultRemoteAddress(java.net.InetSocketAddress defaultRemoteAddress)Sets the default remote InetSocketAddress to connect to when no argument is specified inIoConnector.connect()method.protected voidwakeup()Interrupt theAbstractPollingIoConnector.select(int)method.-
Methods inherited from class org.apache.mina.core.polling.AbstractPollingIoConnector
connect0, dispose0
-
Methods inherited from class org.apache.mina.core.service.AbstractIoConnector
connect, connect, connect, connect, connect, connect, finishSessionInitialization0, getConnectTimeout, getConnectTimeoutCheckInterval, getConnectTimeoutMillis, getDefaultLocalAddress, setConnectTimeout, setConnectTimeoutCheckInterval, setConnectTimeoutMillis, setDefaultLocalAddress, setDefaultRemoteAddress, toString
-
Methods inherited from class org.apache.mina.core.service.AbstractIoService
addListener, broadcast, dispose, dispose, 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.IoConnector
connect, connect, connect, connect, connect, connect, getConnectTimeout, getConnectTimeoutMillis, getDefaultLocalAddress, setConnectTimeout, setConnectTimeoutMillis, setDefaultLocalAddress, setDefaultRemoteAddress
-
Methods inherited from interface org.apache.mina.core.service.IoService
addListener, broadcast, dispose, dispose, getActivationTime, getFilterChain, getFilterChainBuilder, getHandler, getManagedSessionCount, getManagedSessions, getScheduledWriteBytes, getScheduledWriteMessages, getSessionDataStructureFactory, getStatistics, isActive, isDisposed, isDisposing, removeListener, setFilterChainBuilder, setHandler, setSessionDataStructureFactory
-
-
-
-
Constructor Detail
-
AprSocketConnector
public AprSocketConnector()
Create anAprSocketConnectorwith default configuration (multiple thread model).
-
AprSocketConnector
public AprSocketConnector(int processorCount)
Constructor forAprSocketConnectorwith default configuration, and given number ofAprIoProcessorfor multithreading I/O operations- Parameters:
processorCount- the number of processor to create and place in aSimpleIoProcessorPool
-
AprSocketConnector
public AprSocketConnector(IoProcessor<AprSession> processor)
Constructor forAprSocketConnectorwith default configuration but a specificIoProcessor, useful for sharing the same processor over multipleIoServiceof the same type.- Parameters:
processor- the processor to use for managing I/O events
-
AprSocketConnector
public AprSocketConnector(java.util.concurrent.Executor executor, IoProcessor<AprSession> processor)Constructor forAprSocketConnectorwith a givenExecutorfor handling connection events and a givenIoProcessorfor handling I/O events, useful for sharing the same processor and executor over multipleIoServiceof the same type.- Parameters:
executor- the executor for connectionprocessor- the processor for I/O operations
-
-
Method Detail
-
init
protected void init() throws java.lang.ExceptionInitialize the polling system, will be called at construction time.- Specified by:
initin classAbstractPollingIoConnector<AprSession,java.lang.Long>- Throws:
java.lang.Exception- any exception thrown by the underlying system calls
-
destroy
protected void destroy() throws java.lang.ExceptionDestroy the polling system, will be called when thisIoConnectorimplementation will be disposed.- Specified by:
destroyin classAbstractPollingIoConnector<AprSession,java.lang.Long>- Throws:
java.lang.Exception- any exception thrown by the underlying systems calls
-
allHandles
protected java.util.Iterator<java.lang.Long> allHandles()
Iteratorfor all the client sockets polled for connection.- Specified by:
allHandlesin classAbstractPollingIoConnector<AprSession,java.lang.Long>- Returns:
- the list of client sockets currently polled for connection
-
connect
protected boolean connect(java.lang.Long handle, java.net.SocketAddress remoteAddress) throws java.lang.ExceptionConnect a newly created client socket handle to a remoteSocketAddress. This operation is non-blocking, so at end of the call the socket can be still in connection process.- Specified by:
connectin classAbstractPollingIoConnector<AprSession,java.lang.Long>- Parameters:
handle- the client socket handleremoteAddress- the remote address where to connect- Returns:
- true if a connection was established, false if this client socket is in non-blocking mode and the connection operation is in progress
- Throws:
java.lang.Exception- If the connect failed
-
getConnectionRequest
protected AbstractPollingIoConnector.ConnectionRequest getConnectionRequest(java.lang.Long handle)
get theAbstractPollingIoConnector.ConnectionRequestfor a given client socket handle- Specified by:
getConnectionRequestin classAbstractPollingIoConnector<AprSession,java.lang.Long>- Parameters:
handle- the socket client handle- Returns:
- the connection request if the socket is connecting otherwise
null
-
close
protected void close(java.lang.Long handle) throws java.lang.ExceptionClose a client socket.- Specified by:
closein classAbstractPollingIoConnector<AprSession,java.lang.Long>- Parameters:
handle- the client socket- Throws:
java.lang.Exception- any exception thrown by the underlying systems calls
-
finishConnect
protected boolean finishConnect(java.lang.Long handle) throws java.lang.ExceptionFinish the connection process of a client socket after it was marked as ready to process by theAbstractPollingIoConnector.select(int)call. The socket will be connected or reported as connection failed.- Specified by:
finishConnectin classAbstractPollingIoConnector<AprSession,java.lang.Long>- Parameters:
handle- the client socket handle to finish to connect- Returns:
- true if the socket is connected
- Throws:
java.lang.Exception- any exception thrown by the underlying systems calls
-
newHandle
protected java.lang.Long newHandle(java.net.SocketAddress localAddress) throws java.lang.ExceptionCreate a new client socket handle from a localSocketAddress- Specified by:
newHandlein classAbstractPollingIoConnector<AprSession,java.lang.Long>- Parameters:
localAddress- the socket address for binding the new client socket- Returns:
- a new client socket handle
- Throws:
java.lang.Exception- any exception thrown by the underlying systems calls
-
newSession
protected AprSession newSession(IoProcessor<AprSession> processor, java.lang.Long handle) throws java.lang.Exception
Create a newIoSessionfrom a connected socket client handle. Will assign the createdIoSessionto the givenIoProcessorfor managing future I/O events.- Specified by:
newSessionin classAbstractPollingIoConnector<AprSession,java.lang.Long>- Parameters:
processor- the processor in charge of this sessionhandle- the newly connected client socket handle- Returns:
- a new
IoSession - Throws:
java.lang.Exception- any exception thrown by the underlying systems calls
-
register
protected void register(java.lang.Long handle, AbstractPollingIoConnector.ConnectionRequest request) throws java.lang.ExceptionRegister a new client socket for connection, add it to connection polling- Specified by:
registerin classAbstractPollingIoConnector<AprSession,java.lang.Long>- Parameters:
handle- client socket handlerequest- the associatedAbstractPollingIoConnector.ConnectionRequest- Throws:
java.lang.Exception- any exception thrown by the underlying systems calls
-
select
protected int select(int timeout) throws java.lang.ExceptionCheck for connected sockets, interrupt when at least a connection is processed (connected or failed to connect). All the client socket descriptors processed need to be returned byAbstractPollingIoConnector.selectedHandles()- Specified by:
selectin classAbstractPollingIoConnector<AprSession,java.lang.Long>- Parameters:
timeout- The timeout for the select() method- Returns:
- The number of socket having received some data
- Throws:
java.lang.Exception- any exception thrown by the underlying systems calls
-
selectedHandles
protected java.util.Iterator<java.lang.Long> selectedHandles()
Iteratorfor the set of client sockets found connected or failed to connect during the lastAbstractPollingIoConnector.select(int)call.- Specified by:
selectedHandlesin classAbstractPollingIoConnector<AprSession,java.lang.Long>- Returns:
- the list of client socket handles to process
-
wakeup
protected void wakeup()
Interrupt theAbstractPollingIoConnector.select(int)method. Used when the poll set need to be modified.- Specified by:
wakeupin classAbstractPollingIoConnector<AprSession,java.lang.Long>
-
getTransportMetadata
public TransportMetadata getTransportMetadata()
- Specified by:
getTransportMetadatain interfaceIoService- Returns:
- the
TransportMetadatathat this service runs on.
-
getSessionConfig
public SocketSessionConfig getSessionConfig()
- Specified by:
getSessionConfigin interfaceIoService- Specified by:
getSessionConfigin interfaceSocketConnector- Returns:
- the default configuration of the new SocketSessions created by this connect service.
-
getDefaultRemoteAddress
public java.net.InetSocketAddress getDefaultRemoteAddress()
- Specified by:
getDefaultRemoteAddressin interfaceIoConnector- Specified by:
getDefaultRemoteAddressin interfaceSocketConnector- Overrides:
getDefaultRemoteAddressin classAbstractIoConnector- Returns:
- the default remote address to connect to when no argument
is specified in
IoConnector.connect()method.
-
setDefaultRemoteAddress
public void setDefaultRemoteAddress(java.net.InetSocketAddress defaultRemoteAddress)
Sets the default remote InetSocketAddress to connect to when no argument is specified inIoConnector.connect()method. This method overrides theIoConnector.setDefaultRemoteAddress(java.net.SocketAddress)method.- Specified by:
setDefaultRemoteAddressin interfaceSocketConnector- Parameters:
defaultRemoteAddress- The remote address to set
-
-