H
- The type of IoHandlerS
- The type of IoSessionpublic abstract class AbstractPollingIoAcceptor<S extends AbstractIoSession,H> extends AbstractIoAcceptor
Executor
will be used
for running client accepting and an AbstractPollingIoProcessor
will
be used for processing client I/O operations like reading, writing and
closing.
All the low level methods for binding, accepting, closing need to be provided
by the subclassing implementation.for a example of implementation
AbstractIoAcceptor.AcceptorOperationFuture
AbstractIoService.ServiceOperationFuture
Modifier and Type | Field and Description |
---|---|
protected int |
backlog
Define the number of socket that can wait to be accepted.
|
protected boolean |
reuseAddress |
bindLock
disposalLock, LOGGER, sessionConfig
Modifier | Constructor and Description |
---|---|
protected |
AbstractPollingIoAcceptor(IoSessionConfig sessionConfig,
Class<? extends IoProcessor<S>> processorClass)
Constructor for
AbstractPollingIoAcceptor . |
protected |
AbstractPollingIoAcceptor(IoSessionConfig sessionConfig,
Class<? extends IoProcessor<S>> processorClass,
int processorCount)
Constructor for
AbstractPollingIoAcceptor . |
protected |
AbstractPollingIoAcceptor(IoSessionConfig sessionConfig,
Class<? extends IoProcessor<S>> processorClass,
int processorCount,
SelectorProvider selectorProvider)
Constructor for
AbstractPollingIoAcceptor . |
protected |
AbstractPollingIoAcceptor(IoSessionConfig sessionConfig,
Executor executor,
IoProcessor<S> processor)
Constructor for
AbstractPollingIoAcceptor . |
protected |
AbstractPollingIoAcceptor(IoSessionConfig sessionConfig,
IoProcessor<S> processor)
Constructor for
AbstractPollingIoAcceptor . |
Modifier and Type | Method and Description |
---|---|
protected abstract S |
accept(IoProcessor<S> processor,
H handle)
Accept a client connection for a server socket and return a new
IoSession
associated with the given IoProcessor |
protected Set<SocketAddress> |
bindInternal(List<? extends SocketAddress> localAddresses)
Starts the acceptor, and register the given addresses
|
protected abstract void |
close(H handle)
Close a server socket.
|
protected abstract void |
destroy()
Destroy the polling system, will be called when this
IoAcceptor
implementation will be disposed. |
protected void |
dispose0()
Implement this method to release any acquired resources.
|
int |
getBacklog() |
SocketSessionConfig |
getSessionConfig() |
protected abstract void |
init()
Initialize the polling system, will be called at construction time.
|
protected abstract void |
init(SelectorProvider selectorProvider)
Initialize the polling system, will be called at construction time.
|
boolean |
isReuseAddress() |
protected abstract SocketAddress |
localAddress(H handle)
Get the local address associated with a given server socket
|
IoSession |
newSession(SocketAddress remoteAddress,
SocketAddress localAddress)
(Optional) Returns an
IoSession that is bound to the specified
localAddress and the specified remoteAddress which
reuses the local address that is already bound by this service. |
protected abstract H |
open(SocketAddress localAddress)
Open a server socket for a given local address.
|
protected abstract int |
select()
Check for acceptable connections, interrupt when at least a server is ready for accepting.
|
protected abstract Iterator<H> |
selectedHandles()
|
void |
setBacklog(int backlog)
Sets the Backlog parameter
|
void |
setReuseAddress(boolean reuseAddress)
Set the Reuse Address flag
|
protected void |
unbind0(List<? extends SocketAddress> localAddresses)
Implement this method to perform the actual unbind operation.
|
protected abstract void |
wakeup()
Interrupt the
select() method. |
bind, bind, bind, bind, bind, getDefaultLocalAddress, getDefaultLocalAddresses, getLocalAddress, getLocalAddresses, isCloseOnDeactivation, setCloseOnDeactivation, setDefaultLocalAddress, setDefaultLocalAddresses, setDefaultLocalAddresses, setDefaultLocalAddresses, toString, unbind, unbind, unbind, unbind
addListener, broadcast, dispose, dispose, executeWorker, executeWorker, finishSessionInitialization0, getActivationTime, getFilterChain, getFilterChainBuilder, getHandler, getListeners, getManagedSessionCount, getManagedSessions, getScheduledWriteBytes, getScheduledWriteMessages, 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, getSessionDataStructureFactory, getStatistics, getTransportMetadata, isActive, isDisposed, isDisposing, removeListener, setFilterChainBuilder, setHandler, setSessionDataStructureFactory
protected boolean reuseAddress
protected int backlog
protected AbstractPollingIoAcceptor(IoSessionConfig sessionConfig, Class<? extends IoProcessor<S>> processorClass)
AbstractPollingIoAcceptor
. 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 AbstractPollingIoAcceptor(IoSessionConfig sessionConfig, Class<? extends IoProcessor<S>> processorClass, int processorCount)
AbstractPollingIoAcceptor
. 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 AbstractPollingIoAcceptor(IoSessionConfig sessionConfig, Class<? extends IoProcessor<S>> processorClass, int processorCount, SelectorProvider selectorProvider)
AbstractPollingIoAcceptor
. 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 poolselectorProvider
- The SelectorProvider to useSimpleIoProcessorPool
protected AbstractPollingIoAcceptor(IoSessionConfig sessionConfig, IoProcessor<S> processor)
AbstractPollingIoAcceptor
. You need to provide a default
session configuration, a default Executor
will be created using
Executors.newCachedThreadPool()
.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
AbstractIoService
protected AbstractPollingIoAcceptor(IoSessionConfig sessionConfig, Executor executor, IoProcessor<S> processor)
AbstractPollingIoAcceptor
. You need to provide a
default session configuration and an Executor
for handling I/O
events. If a null Executor
is provided, a default one will be
created using Executors.newCachedThreadPool()
.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
AbstractIoService.AbstractIoService(IoSessionConfig, Executor)
protected abstract void init() throws Exception
Exception
- any exception thrown by the underlying system callsprotected abstract void init(SelectorProvider selectorProvider) throws Exception
selectorProvider
- The Selector Provider that will be used by this polling acceptorException
- any exception thrown by the underlying system callsprotected abstract void destroy() throws Exception
IoAcceptor
implementation will be disposed.Exception
- any exception thrown by the underlying systems callsprotected abstract int select() throws Exception
selectedHandles()
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 Iterator<H> selectedHandles()
Iterator
for the set of server sockets found with acceptable incoming connections
during the last select()
call.protected abstract H open(SocketAddress localAddress) throws Exception
localAddress
- the associated local addressException
- any exception thrown by the underlying systems callsprotected abstract SocketAddress localAddress(H handle) throws Exception
handle
- the server socketSocketAddress
associated with this handleException
- any exception thrown by the underlying systems callsprotected abstract S accept(IoProcessor<S> processor, H handle) throws Exception
IoSession
associated with the given IoProcessor
processor
- the IoProcessor
to associate with the IoSession
handle
- the server handleIoSession
Exception
- any exception thrown by the underlying systems callsprotected abstract void close(H handle) throws Exception
handle
- the server socketException
- any exception thrown by the underlying systems callsprotected void dispose0() throws Exception
AbstractIoService.dispose()
.dispose0
in class AbstractIoService
Exception
- If the dispose failedprotected final Set<SocketAddress> bindInternal(List<? extends SocketAddress> localAddresses) throws Exception
bindInternal
in class AbstractIoAcceptor
localAddresses
- The address to bind toSet
of the local addresses which is bound actuallyException
- If the bind failedprotected final void unbind0(List<? extends SocketAddress> localAddresses) throws Exception
unbind0
in class AbstractIoAcceptor
localAddresses
- The address to unbind fromException
- If the unbind failedpublic final IoSession newSession(SocketAddress remoteAddress, SocketAddress localAddress)
IoSession
that is bound to the specified
localAddress and the specified remoteAddress which
reuses the local address that is already bound by this service.
This operation is optional. Please throw UnsupportedOperationException
if the transport type doesn't support this operation. This operation is
usually implemented for connectionless transport types.
remoteAddress
- The remote address bound to the servicelocalAddress
- The local address the session will be bound topublic int getBacklog()
public void setBacklog(int backlog)
backlog
- the backlog variablepublic boolean isReuseAddress()
public void setReuseAddress(boolean reuseAddress)
reuseAddress
- The flag to setpublic SocketSessionConfig getSessionConfig()
IoSession
s
created by this service.Copyright © 2004–2018 Apache MINA Project. All rights reserved.