Class AprSocketAcceptor
java.lang.Object
org.apache.mina.core.service.AbstractIoService
org.apache.mina.core.service.AbstractIoAcceptor
org.apache.mina.core.polling.AbstractPollingIoAcceptor<AprSession, Long>
org.apache.mina.transport.socket.apr.AprSocketAcceptor
- All Implemented Interfaces:
IoAcceptor, IoService
IoAcceptor for APR based socket transport (TCP/IP).-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractIoAcceptor
AbstractIoAcceptor.AcceptorOperationFutureNested classes/interfaces inherited from class AbstractIoService
AbstractIoService.ServiceOperationFuture -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intThis constant is deduced from the APR code.private final long[]private longprivate static final intprivate longprivate booleanprivate final Objectprivate longFields inherited from class AbstractPollingIoAcceptor
backlog, reuseAddressFields inherited from class AbstractIoAcceptor
bindLockFields inherited from class AbstractIoService
disposalLock, LOGGER, sessionConfig -
Constructor Summary
ConstructorsConstructorDescriptionConstructor forAprSocketAcceptorusing default parameters (multiple thread model).AprSocketAcceptor(int processorCount) Constructor forAprSocketAcceptorusing default parameters, and given number ofAprIoProcessorfor multithreading I/O operations.AprSocketAcceptor(Executor executor, IoProcessor<AprSession> processor) Constructor forAprSocketAcceptorwith a givenExecutorfor handling connection events and a givenAprIoProcessorfor handling I/O events, useful for sharing the same processor and executor over multipleIoServiceof the same type.AprSocketAcceptor(IoProcessor<AprSession> processor) Constructor forAprSocketAcceptorwith default configuration but a specificAprIoProcessor, useful for sharing the same processor over multipleIoServiceof the same type. -
Method Summary
Modifier and TypeMethodDescriptionprotected AprSessionaccept(IoProcessor<AprSession> processor, Long handle) Accept a client connection for a server socket and return a newIoSessionassociated with the givenIoProcessorprotected voidClose a server socket.protected voiddestroy()Destroy the polling system, will be called when thisIoAcceptorimplementation will be disposed.Returns the default local address to bind when no argument is specified inIoAcceptor.bind()method.Returns the local address which is bound currently.protected voidinit()Initialize the polling system, will be called at construction time.protected voidinit(SelectorProvider selectorProvider) Initialize the polling system, will be called at construction time.protected SocketAddresslocalAddress(Long handle) Get the local address associated with a given server socketprotected Longopen(SocketAddress localAddress) Open a server socket for a given local address.protected intselect()Check for acceptable connections, interrupt when at least a server is ready for accepting.Iteratorfor the set of server sockets found with acceptable incoming connections during the lastAbstractPollingIoAcceptor.select()call.voidsetDefaultLocalAddress(InetSocketAddress localAddress) private voidthrowException(int code) Convert an APR code into an Exception with the corresponding messageprotected voidwakeup()Interrupt theAbstractPollingIoAcceptor.select()method.Methods inherited from class AbstractPollingIoAcceptor
bindInternal, bindRequestAdded, dispose0, getBacklog, getSessionConfig, handleUnbound, hasUnbindings, isReuseAddress, newSession, processHandles, setBacklog, setReuseAddress, unbind0Methods inherited from class AbstractIoAcceptor
bind, bind, bind, bind, bind, getDefaultLocalAddresses, getLocalAddresses, isCloseOnDeactivation, setCloseOnDeactivation, setDefaultLocalAddress, setDefaultLocalAddresses, setDefaultLocalAddresses, setDefaultLocalAddresses, toString, unbind, unbind, unbind, unbindMethods inherited from class AbstractIoService
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, setSessionDataStructureFactoryMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface IoService
addListener, broadcast, dispose, dispose, getActivationTime, getFilterChain, getFilterChainBuilder, getHandler, getManagedSessionCount, getManagedSessions, getScheduledWriteBytes, getScheduledWriteMessages, getSessionDataStructureFactory, getStatistics, isActive, isDisposed, isDisposing, removeListener, setFilterChainBuilder, setHandler, setSessionDataStructureFactory
-
Field Details
-
APR_TIMEUP_ERROR
private static final int APR_TIMEUP_ERRORThis constant is deduced from the APR code. It is used when the timeout has expired while doing a poll() operation.- See Also:
-
POLLSET_SIZE
private static final int POLLSET_SIZE- See Also:
-
wakeupLock
-
wakeupSocket
private volatile long wakeupSocket -
toBeWakenUp
private volatile boolean toBeWakenUp -
pool
private volatile long pool -
pollset
private volatile long pollset -
polledSockets
private final long[] polledSockets -
polledHandles
-
-
Constructor Details
-
AprSocketAcceptor
public AprSocketAcceptor()Constructor forAprSocketAcceptorusing default parameters (multiple thread model). -
AprSocketAcceptor
public AprSocketAcceptor(int processorCount) Constructor forAprSocketAcceptorusing default parameters, and given number ofAprIoProcessorfor multithreading I/O operations.- Parameters:
processorCount- the number of processor to create and place in aSimpleIoProcessorPool
-
AprSocketAcceptor
Constructor forAprSocketAcceptorwith default configuration but a specificAprIoProcessor, useful for sharing the same processor over multipleIoServiceof the same type.- Parameters:
processor- the processor to use for managing I/O events
-
AprSocketAcceptor
Constructor forAprSocketAcceptorwith a givenExecutorfor handling connection events and a givenAprIoProcessorfor 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 Details
-
accept
Accept a client connection for a server socket and return a newIoSessionassociated with the givenIoProcessor- Specified by:
acceptin classAbstractPollingIoAcceptor<AprSession, Long>- Parameters:
processor- theIoProcessorto associate with theIoSessionhandle- the server handle- Returns:
- the created
IoSession - Throws:
Exception- any exception thrown by the underlying systems calls
-
open
Open a server socket for a given local address.- Specified by:
openin classAbstractPollingIoAcceptor<AprSession, Long>- Parameters:
localAddress- the associated local address- Returns:
- the opened server socket
- Throws:
Exception- any exception thrown by the underlying systems calls
-
init
Initialize the polling system, will be called at construction time.- Specified by:
initin classAbstractPollingIoAcceptor<AprSession, Long>- Throws:
Exception- any exception thrown by the underlying system calls
-
destroy
Destroy the polling system, will be called when thisIoAcceptorimplementation will be disposed.- Specified by:
destroyin classAbstractPollingIoAcceptor<AprSession, Long>- Throws:
Exception- any exception thrown by the underlying systems calls
-
localAddress
Get the local address associated with a given server socket- Specified by:
localAddressin classAbstractPollingIoAcceptor<AprSession, Long>- Parameters:
handle- the server socket- Returns:
- the local
SocketAddressassociated with this handle - Throws:
Exception- any exception thrown by the underlying systems calls
-
select
Check for acceptable connections, interrupt when at least a server is ready for accepting. All the ready server socket descriptors need to be returned byAbstractPollingIoAcceptor.selectedHandles()- Specified by:
selectin classAbstractPollingIoAcceptor<AprSession, Long>- Returns:
- The number of sockets having got incoming client
- Throws:
Exception- any exception thrown by the underlying systems calls
-
selectedHandles
Iteratorfor the set of server sockets found with acceptable incoming connections during the lastAbstractPollingIoAcceptor.select()call.- Specified by:
selectedHandlesin classAbstractPollingIoAcceptor<AprSession, Long>- Returns:
- the list of server handles ready
-
close
Close a server socket.- Specified by:
closein classAbstractPollingIoAcceptor<AprSession, Long>- Parameters:
handle- the server socket- Throws:
Exception- any exception thrown by the underlying systems calls
-
wakeup
protected void wakeup()Interrupt theAbstractPollingIoAcceptor.select()method. Used when the poll set need to be modified.- Specified by:
wakeupin classAbstractPollingIoAcceptor<AprSession, Long>
-
getLocalAddress
Returns the local address which is bound currently. If more than one address are bound, only one of them will be returned, but it's not necessarily the firstly bound address.- Specified by:
getLocalAddressin interfaceIoAcceptor- Overrides:
getLocalAddressin classAbstractIoAcceptor- Returns:
- The bound LocalAddress
-
getDefaultLocalAddress
Returns the default local address to bind when no argument is specified inIoAcceptor.bind()method. Please note that the default will not be used if any local address is specified. If more than one address are set, only one of them will be returned, but it's not necessarily the firstly specified address inIoAcceptor.setDefaultLocalAddresses(List).- Specified by:
getDefaultLocalAddressin interfaceIoAcceptor- Overrides:
getDefaultLocalAddressin classAbstractIoAcceptor- Returns:
- The default bound LocalAddress
-
setDefaultLocalAddress
- Parameters:
localAddress- The localAddress to set- See Also:
-
getTransportMetadata
- Returns:
- the
TransportMetadatathat this service runs on.
-
throwException
Convert an APR code into an Exception with the corresponding message- Parameters:
code- error number- Throws:
IOException- the generated exception
-
init
Description copied from class:AbstractPollingIoAcceptorInitialize the polling system, will be called at construction time.- Specified by:
initin classAbstractPollingIoAcceptor<AprSession, Long>- Parameters:
selectorProvider- The Selector Provider that will be used by this polling acceptor- Throws:
Exception- any exception thrown by the underlying system calls
-