public abstract class AbstractPollingIoConnector<T extends AbstractIoSession,H> extends AbstractIoConnector
Executor
will be used
for running client connection, and an AbstractPollingIoProcessor
will
be used for processing connected client I/O operations like reading, writing
and closing.
All the low level methods for binding, connecting, closing need to be
provided by the subclassing implementation.for a example of implementation
Modifier and Type | Class and Description |
---|---|
class |
AbstractPollingIoConnector.ConnectionRequest |
AbstractIoService.ServiceOperationFuture
disposalLock
Modifier | Constructor and Description |
---|---|
protected |
AbstractPollingIoConnector(IoSessionConfig sessionConfig,
java.lang.Class<? extends IoProcessor<T>> processorClass)
Constructor for
AbstractPollingIoConnector . |
protected |
AbstractPollingIoConnector(IoSessionConfig sessionConfig,
java.lang.Class<? extends IoProcessor<T>> processorClass,
int processorCount)
Constructor for
AbstractPollingIoConnector . |
protected |
AbstractPollingIoConnector(IoSessionConfig sessionConfig,
java.util.concurrent.Executor executor,
IoProcessor<T> processor)
Constructor for
AbstractPollingIoConnector . |
protected |
AbstractPollingIoConnector(IoSessionConfig sessionConfig,
IoProcessor<T> processor)
Constructor for
AbstractPollingIoConnector . |
Modifier and Type | Method and Description |
---|---|
protected abstract java.util.Iterator<H> |
allHandles()
Iterator for all the client sockets polled for connection. |
protected abstract void |
close(H handle)
Close a client socket.
|
protected abstract boolean |
connect(H handle,
java.net.SocketAddress remoteAddress)
Connect a newly created client socket handle to a remote
SocketAddress . |
protected ConnectFuture |
connect0(java.net.SocketAddress remoteAddress,
java.net.SocketAddress localAddress,
IoSessionInitializer<? extends ConnectFuture> sessionInitializer)
Implement this method to perform the actual connect operation.
|
protected abstract void |
destroy()
Destroy the polling system, will be called when this
IoConnector
implementation will be disposed. |
protected void |
dispose0()
Implement this method to release any acquired resources.
|
protected abstract boolean |
finishConnect(H handle)
Finish the connection process of a client socket after it was marked as ready to process
by the
select(int) call. |
protected abstract AbstractPollingIoConnector.ConnectionRequest |
getConnectionRequest(H handle)
get the
AbstractPollingIoConnector.ConnectionRequest for a given client socket handle |
protected abstract void |
init()
Initialize the polling system, will be called at construction time.
|
protected abstract H |
newHandle(java.net.SocketAddress localAddress)
Create a new client socket handle from a local
SocketAddress |
protected abstract T |
newSession(IoProcessor<T> processor,
H handle)
Create a new
IoSession from a connected socket client handle. |
protected abstract void |
register(H handle,
AbstractPollingIoConnector.ConnectionRequest request)
Register a new client socket for connection, add it to connection polling
|
protected abstract int |
select(int timeout)
Check for connected sockets, interrupt when at least a connection is processed (connected or
failed to connect).
|
protected abstract java.util.Iterator<H> |
selectedHandles()
Iterator for the set of client sockets found connected or
failed to connect during the last #select() call. |
protected abstract void |
wakeup()
Interrupt the
#select() method. |
connect, connect, connect, connect, connect, connect, finishSessionInitialization0, getConnectTimeout, getConnectTimeoutCheckInterval, getConnectTimeoutMillis, getDefaultRemoteAddress, setConnectTimeout, setConnectTimeoutCheckInterval, setConnectTimeoutMillis, setDefaultRemoteAddress, toString
addListener, broadcast, dispose, dispose, executeWorker, executeWorker, getActivationTime, getFilterChain, getFilterChainBuilder, getHandler, getListeners, getManagedSessionCount, getManagedSessions, getScheduledWriteBytes, getScheduledWriteMessages, getSessionConfig, getSessionDataStructureFactory, getStatistics, initSession, isActive, isDisposed, isDisposing, removeListener, setFilterChainBuilder, setHandler, setSessionDataStructureFactory
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addListener, broadcast, dispose, dispose, getActivationTime, getFilterChain, getFilterChainBuilder, getHandler, getManagedSessionCount, getManagedSessions, getScheduledWriteBytes, getScheduledWriteMessages, getSessionConfig, getSessionDataStructureFactory, getStatistics, getTransportMetadata, isActive, isDisposed, isDisposing, removeListener, setFilterChainBuilder, setHandler, setSessionDataStructureFactory
protected AbstractPollingIoConnector(IoSessionConfig sessionConfig, java.lang.Class<? extends IoProcessor<T>> processorClass)
AbstractPollingIoConnector
. You need to provide a default
session configuration, a class of IoProcessor
which will be instantiated in a
SimpleIoProcessorPool
for better scaling in multiprocessor systems. The default
pool size will be used.sessionConfig
- the default configuration for the managed IoSession
processorClass
- a Class
of IoProcessor
for the associated IoSession
type.SimpleIoProcessorPool
protected AbstractPollingIoConnector(IoSessionConfig sessionConfig, java.lang.Class<? extends IoProcessor<T>> processorClass, int processorCount)
AbstractPollingIoConnector
. You need to provide a default
session configuration, a class of IoProcessor
which will be instantiated in a
SimpleIoProcessorPool
for using multiple thread for better scaling in multiprocessor
systems.sessionConfig
- the default configuration for the managed IoSession
processorClass
- a Class
of IoProcessor
for the associated IoSession
type.processorCount
- the amount of processor to instantiate for the poolSimpleIoProcessorPool
protected AbstractPollingIoConnector(IoSessionConfig sessionConfig, IoProcessor<T> processor)
AbstractPollingIoConnector
. You need to provide a default
session configuration, a default Executor
will be created using
Executors.newCachedThreadPool()
.
AbstractIoService#AbstractIoService(IoSessionConfig, Executor)
sessionConfig
- the default configuration for the managed IoSession
processor
- the IoProcessor
for processing the IoSession
of this transport, triggering
events to the bound IoHandler
and processing the chains of IoFilter
protected AbstractPollingIoConnector(IoSessionConfig sessionConfig, java.util.concurrent.Executor executor, IoProcessor<T> processor)
AbstractPollingIoConnector
. You need to provide a default
session configuration and an Executor
for handling I/O events. If
null Executor
is provided, a default one will be created using
Executors.newCachedThreadPool()
.
AbstractIoService#AbstractIoService(IoSessionConfig, Executor)
sessionConfig
- the default configuration for the managed IoSession
executor
- the Executor
used for handling asynchronous execution of I/O
events. Can be null
.processor
- the IoProcessor
for processing the IoSession
of this transport, triggering
events to the bound IoHandler
and processing the chains of IoFilter
protected abstract void init() throws java.lang.Exception
java.lang.Exception
- any exception thrown by the underlying system callsprotected abstract void destroy() throws java.lang.Exception
IoConnector
implementation will be disposed.java.lang.Exception
- any exception thrown by the underlying systems callsprotected abstract H newHandle(java.net.SocketAddress localAddress) throws java.lang.Exception
SocketAddress
localAddress
- the socket address for binding the new client socketjava.lang.Exception
- any exception thrown by the underlying systems callsprotected abstract boolean connect(H handle, java.net.SocketAddress remoteAddress) throws java.lang.Exception
SocketAddress
.
This operation is non-blocking, so at end of the call the socket can be still in connection
process.handle
- the client socket handleremoteAddress
- the remote address where to connectjava.lang.Exception
protected abstract boolean finishConnect(H handle) throws java.lang.Exception
select(int)
call. The socket will be connected or reported as connection
failed.handle
- the client socket handle to finsh to connectjava.lang.Exception
- any exception thrown by the underlying systems callsprotected abstract T newSession(IoProcessor<T> processor, H handle) throws java.lang.Exception
IoSession
from a connected socket client handle.
Will assign the created IoSession
to the given IoProcessor
for
managing future I/O events.processor
- the processor in charge of this sessionhandle
- the newly connected client socket handleIoSession
java.lang.Exception
- any exception thrown by the underlying systems callsprotected abstract void close(H handle) throws java.lang.Exception
handle
- the client socketjava.lang.Exception
- any exception thrown by the underlying systems callsprotected abstract void wakeup()
#select()
method. Used when the poll set need to be modified.protected abstract int select(int timeout) throws java.lang.Exception
selectedHandles()
java.lang.Exception
- any exception thrown by the underlying systems callsprotected abstract java.util.Iterator<H> selectedHandles()
Iterator
for the set of client sockets found connected or
failed to connect during the last #select()
call.protected abstract java.util.Iterator<H> allHandles()
Iterator
for all the client sockets polled for connection.protected abstract void register(H handle, AbstractPollingIoConnector.ConnectionRequest request) throws java.lang.Exception
handle
- client socket handlerequest
- the associated AbstractPollingIoConnector.ConnectionRequest
java.lang.Exception
- any exception thrown by the underlying systems callsprotected abstract AbstractPollingIoConnector.ConnectionRequest getConnectionRequest(H handle)
AbstractPollingIoConnector.ConnectionRequest
for a given client socket handlehandle
- the socket client handlenull
protected final void dispose0() throws java.lang.Exception
AbstractIoService.dispose()
.dispose0
in class AbstractIoService
java.lang.Exception
protected final ConnectFuture connect0(java.net.SocketAddress remoteAddress, java.net.SocketAddress localAddress, IoSessionInitializer<? extends ConnectFuture> sessionInitializer)
connect0
in class AbstractIoConnector
localAddress
- null if no local address is specifiedCopyright © 2004-2019 Apache MINA Project. All Rights Reserved.