Class NioSocketAcceptor
java.lang.Object
org.apache.mina.core.service.AbstractIoService
org.apache.mina.core.service.AbstractIoAcceptor
org.apache.mina.core.polling.AbstractPollingIoAcceptor<NioSession, ServerSocketChannel>
org.apache.mina.transport.socket.nio.NioSocketAcceptor
- All Implemented Interfaces:
IoAcceptor, IoService, SocketAcceptor
public class NioSocketAcceptor
extends AbstractPollingIoAcceptor<NioSession, ServerSocketChannel>
implements SocketAcceptor
IoAcceptor for socket transport (TCP/IP). This class
handles incoming TCP/IP based socket connections.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classDefines an iterator for the selected-key Set returned by the selector.selectedKeys().Nested classes/interfaces inherited from class AbstractIoAcceptor
AbstractIoAcceptor.AcceptorOperationFutureNested classes/interfaces inherited from class AbstractIoService
AbstractIoService.ServiceOperationFuture -
Field Summary
FieldsFields inherited from class AbstractPollingIoAcceptor
backlog, reuseAddressFields inherited from class AbstractIoAcceptor
bindLockFields inherited from class AbstractIoService
disposalLock, LOGGER, sessionConfig -
Constructor Summary
ConstructorsConstructorDescriptionConstructor forNioSocketAcceptorusing default parameters (multiple thread model).NioSocketAcceptor(int processorCount) Constructor forNioSocketAcceptorusing default parameters, and given number ofNioProcessorfor multithreading I/O operations.NioSocketAcceptor(int processorCount, SelectorProvider selectorProvider) Constructor forNioSocketAcceptorusing default parameters, and given number ofNioProcessorfor multithreading I/O operations, and a custom SelectorProvider for NIONioSocketAcceptor(Executor executor, IoProcessor<NioSession> processor) Constructor forNioSocketAcceptorwith 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.NioSocketAcceptor(IoProcessor<NioSession> processor) Constructor forNioSocketAcceptorwith default configuration but a specificIoProcessor, useful for sharing the same processor over multipleIoServiceof the same type. -
Method Summary
Modifier and TypeMethodDescriptionprotected NioSessionaccept(IoProcessor<NioSession> processor, ServerSocketChannel handle) Accept a client connection for a server socket and return a newIoSessionassociated with the givenIoProcessorprotected voidclose(ServerSocketChannel handle) Close 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 voidhandleUnbound(Collection<AbstractIoAcceptor.AcceptorOperationFuture> unboundFutures) Processes the futures for executed unbindings, marking all futures as done.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(ServerSocketChannel handle) Get the local address associated with a given server socketprotected ServerSocketChannelopen(SocketAddress localAddress) Open a server socket for a given local address.protected intselect()Check if we have at least one key whose corresponding channels is ready for I/O operations.protected Iterator<ServerSocketChannel> Iteratorfor the set of server sockets found with acceptable incoming connections during the lastAbstractPollingIoAcceptor.select()call.voidsetDefaultLocalAddress(InetSocketAddress localAddress) Sets the default local InetSocketAddress to bind when no argument is specified inIoAcceptor.bind()method.protected voidwakeup()Interrupt theAbstractPollingIoAcceptor.select()method.Methods inherited from class AbstractPollingIoAcceptor
bindInternal, bindRequestAdded, dispose0, getBacklog, getSessionConfig, 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 IoAcceptor
bind, bind, bind, bind, bind, getDefaultLocalAddresses, getLocalAddresses, isCloseOnDeactivation, newSession, setCloseOnDeactivation, setDefaultLocalAddress, setDefaultLocalAddresses, setDefaultLocalAddresses, setDefaultLocalAddresses, unbind, unbind, unbind, unbindMethods inherited from interface IoService
addListener, broadcast, dispose, dispose, getActivationTime, getFilterChain, getFilterChainBuilder, getHandler, getManagedSessionCount, getManagedSessions, getScheduledWriteBytes, getScheduledWriteMessages, getSessionDataStructureFactory, getStatistics, isActive, isDisposed, isDisposing, removeListener, setFilterChainBuilder, setHandler, setSessionDataStructureFactoryMethods inherited from interface SocketAcceptor
getBacklog, getSessionConfig, isReuseAddress, setBacklog, setReuseAddress
-
Field Details
-
selector
-
selectorProvider
-
-
Constructor Details
-
NioSocketAcceptor
public NioSocketAcceptor()Constructor forNioSocketAcceptorusing default parameters (multiple thread model). -
NioSocketAcceptor
public NioSocketAcceptor(int processorCount) Constructor forNioSocketAcceptorusing default parameters, and given number ofNioProcessorfor multithreading I/O operations.- Parameters:
processorCount- the number of processor to create and place in aSimpleIoProcessorPool
-
NioSocketAcceptor
Constructor forNioSocketAcceptorwith 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
-
NioSocketAcceptor
Constructor forNioSocketAcceptorwith 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
-
NioSocketAcceptor
Constructor forNioSocketAcceptorusing default parameters, and given number ofNioProcessorfor multithreading I/O operations, and a custom SelectorProvider for NIO- Parameters:
processorCount- the number of processor to create and place in aselectorProvider- teh SelectorProvider to useSimpleIoProcessorPool
-
-
Method Details
-
init
Initialize the polling system, will be called at construction time.- Specified by:
initin classAbstractPollingIoAcceptor<NioSession, ServerSocketChannel>- Throws:
Exception- any exception thrown by the underlying system calls
-
init
Initialize the polling system, will be called at construction time.- Specified by:
initin classAbstractPollingIoAcceptor<NioSession, ServerSocketChannel>- Parameters:
selectorProvider- The Selector Provider that will be used by this polling acceptor- Throws:
Exception- any exception thrown by the underlying system calls
-
handleUnbound
protected void handleUnbound(Collection<AbstractIoAcceptor.AcceptorOperationFuture> unboundFutures) throws Exception Processes the futures for executed unbindings, marking all futures as done.- Overrides:
handleUnboundin classAbstractPollingIoAcceptor<NioSession, ServerSocketChannel>- Parameters:
unboundFutures- describing the unbindings- Throws:
Exception- on errors
-
destroy
Destroy the polling system, will be called when thisIoAcceptorimplementation will be disposed.- Specified by:
destroyin classAbstractPollingIoAcceptor<NioSession, ServerSocketChannel>- Throws:
Exception- any exception thrown by the underlying systems calls
-
getTransportMetadata
- Specified by:
getTransportMetadatain interfaceIoService- Returns:
- the
TransportMetadatathat this service runs on.
-
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- Specified by:
getLocalAddressin interfaceSocketAcceptor- 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- Specified by:
getDefaultLocalAddressin interfaceSocketAcceptor- Overrides:
getDefaultLocalAddressin classAbstractIoAcceptor- Returns:
- The default bound LocalAddress
-
setDefaultLocalAddress
Sets the default local InetSocketAddress to bind when no argument is specified inIoAcceptor.bind()method. Please note that the default will not be used if any local InetSocketAddress is specified. This method overrides theIoAcceptor.setDefaultLocalAddress(java.net.SocketAddress)method.- Specified by:
setDefaultLocalAddressin interfaceSocketAcceptor- Parameters:
localAddress- The local address
-
accept
protected NioSession accept(IoProcessor<NioSession> processor, ServerSocketChannel handle) throws Exception Accept a client connection for a server socket and return a newIoSessionassociated with the givenIoProcessor- Specified by:
acceptin classAbstractPollingIoAcceptor<NioSession, ServerSocketChannel>- 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<NioSession, ServerSocketChannel>- Parameters:
localAddress- the associated local address- Returns:
- the opened server socket
- 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<NioSession, ServerSocketChannel>- Parameters:
handle- the server socket- Returns:
- the local
SocketAddressassociated with this handle - Throws:
Exception- any exception thrown by the underlying systems calls
-
select
Check if we have at least one key whose corresponding channels is ready for I/O operations. This method performs a blocking selection operation. It returns only after at least one channel is selected, this selector's wakeup method is invoked, or the current thread is interrupted, whichever comes first.- Specified by:
selectin classAbstractPollingIoAcceptor<NioSession, ServerSocketChannel>- Returns:
- The number of keys having their ready-operation set updated
- Throws:
IOException- If an I/O error occursException- 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<NioSession, ServerSocketChannel>- Returns:
- the list of server handles ready
-
close
Close a server socket.- Specified by:
closein classAbstractPollingIoAcceptor<NioSession, ServerSocketChannel>- 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<NioSession, ServerSocketChannel>
-