public final class NioSocketAcceptor extends AbstractPollingIoAcceptor<NioSession,java.nio.channels.ServerSocketChannel> implements SocketAcceptor
IoAcceptor
for socket transport (TCP/IP). This class
handles incoming TCP/IP based socket connections.AbstractIoAcceptor.AcceptorOperationFuture
AbstractIoService.ServiceOperationFuture
bindLock
disposalLock
Constructor and Description |
---|
NioSocketAcceptor()
Constructor for
NioSocketAcceptor using default parameters (multiple thread model). |
NioSocketAcceptor(java.util.concurrent.Executor executor,
IoProcessor<NioSession> processor)
Constructor for
NioSocketAcceptor with a given Executor for handling
connection events and a given IoProcessor for handling I/O events, useful for
sharing the same processor and executor over multiple IoService of the same type. |
NioSocketAcceptor(int processorCount)
Constructor for
NioSocketAcceptor using default parameters, and
given number of NioProcessor for multithreading I/O operations. |
NioSocketAcceptor(IoProcessor<NioSession> processor)
Constructor for
NioSocketAcceptor with default configuration but a
specific IoProcessor , useful for sharing the same processor over multiple
IoService of the same type. |
Modifier and Type | Method and Description |
---|---|
protected NioSession |
accept(IoProcessor<NioSession> processor,
java.nio.channels.ServerSocketChannel handle)
Accept a client connection for a server socket and return a new
IoSession
associated with the given IoProcessor |
protected void |
close(java.nio.channels.ServerSocketChannel handle)
Close a server socket.
|
protected void |
destroy()
Destroy the polling system, will be called when this
IoAcceptor
implementation will be disposed. |
int |
getBacklog()
Returns the size of the backlog.
|
java.net.InetSocketAddress |
getDefaultLocalAddress()
Returns the default local address to bind when no argument is specified
in
IoAcceptor.bind() method. |
java.net.InetSocketAddress |
getLocalAddress()
Returns the local address which is bound currently.
|
SocketSessionConfig |
getSessionConfig()
Returns the default configuration of the new
IoSession s
created by this service. |
TransportMetadata |
getTransportMetadata()
Returns the
TransportMetadata that this service runs on. |
protected void |
init()
Initialize the polling system, will be called at construction time.
|
boolean |
isReuseAddress() |
protected java.net.SocketAddress |
localAddress(java.nio.channels.ServerSocketChannel handle)
Get the local address associated with a given server socket
|
protected java.nio.channels.ServerSocketChannel |
open(java.net.SocketAddress localAddress)
Open a server socket for a given local address.
|
protected int |
select()
Check if we have at least one key whose corresponding channels is
ready for I/O operations.
|
protected java.util.Iterator<java.nio.channels.ServerSocketChannel> |
selectedHandles()
Iterator for the set of server sockets found with acceptable incoming connections
during the last AbstractPollingIoAcceptor.select() call. |
void |
setBacklog(int backlog)
Sets the size of the backlog.
|
void |
setDefaultLocalAddress(java.net.InetSocketAddress localAddress) |
void |
setReuseAddress(boolean reuseAddress) |
protected void |
wakeup()
Interrupt the
AbstractPollingIoAcceptor.select() method. |
bindInternal, dispose0, newSession, unbind0
bind, bind, bind, bind, getDefaultLocalAddresses, 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
bind, bind, bind, bind, getDefaultLocalAddresses, getLocalAddresses, isCloseOnDeactivation, newSession, setCloseOnDeactivation, setDefaultLocalAddress, setDefaultLocalAddresses, setDefaultLocalAddresses, setDefaultLocalAddresses, unbind, unbind, unbind, unbind
addListener, broadcast, dispose, dispose, getActivationTime, getFilterChain, getFilterChainBuilder, getHandler, getManagedSessionCount, getManagedSessions, getScheduledWriteBytes, getScheduledWriteMessages, getSessionDataStructureFactory, getStatistics, isActive, isDisposed, isDisposing, removeListener, setFilterChainBuilder, setHandler, setSessionDataStructureFactory
public NioSocketAcceptor()
NioSocketAcceptor
using default parameters (multiple thread model).public NioSocketAcceptor(int processorCount)
NioSocketAcceptor
using default parameters, and
given number of NioProcessor
for multithreading I/O operations.processorCount
- the number of processor to create and place in a
SimpleIoProcessorPool
public NioSocketAcceptor(IoProcessor<NioSession> processor)
NioSocketAcceptor
with default configuration but a
specific IoProcessor
, useful for sharing the same processor over multiple
IoService
of the same type.processor
- the processor to use for managing I/O eventspublic NioSocketAcceptor(java.util.concurrent.Executor executor, IoProcessor<NioSession> processor)
NioSocketAcceptor
with a given Executor
for handling
connection events and a given IoProcessor
for handling I/O events, useful for
sharing the same processor and executor over multiple IoService
of the same type.executor
- the executor for connectionprocessor
- the processor for I/O operationsprotected void init() throws java.lang.Exception
init
in class AbstractPollingIoAcceptor<NioSession,java.nio.channels.ServerSocketChannel>
java.lang.Exception
- any exception thrown by the underlying system callsprotected void destroy() throws java.lang.Exception
IoAcceptor
implementation will be disposed.destroy
in class AbstractPollingIoAcceptor<NioSession,java.nio.channels.ServerSocketChannel>
java.lang.Exception
- any exception thrown by the underlying systems callspublic TransportMetadata getTransportMetadata()
TransportMetadata
that this service runs on.getTransportMetadata
in interface IoService
public SocketSessionConfig getSessionConfig()
IoSession
s
created by this service.getSessionConfig
in interface IoService
getSessionConfig
in interface SocketAcceptor
getSessionConfig
in class AbstractIoService
public java.net.InetSocketAddress getLocalAddress()
getLocalAddress
in interface IoAcceptor
getLocalAddress
in interface SocketAcceptor
getLocalAddress
in class AbstractIoAcceptor
public java.net.InetSocketAddress getDefaultLocalAddress()
IoAcceptor.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 in IoAcceptor.setDefaultLocalAddresses(List)
.getDefaultLocalAddress
in interface IoAcceptor
getDefaultLocalAddress
in interface SocketAcceptor
getDefaultLocalAddress
in class AbstractIoAcceptor
public void setDefaultLocalAddress(java.net.InetSocketAddress localAddress)
setDefaultLocalAddress
in interface SocketAcceptor
public boolean isReuseAddress()
isReuseAddress
in interface SocketAcceptor
ServerSocket.getReuseAddress()
public void setReuseAddress(boolean reuseAddress)
setReuseAddress
in interface SocketAcceptor
ServerSocket.setReuseAddress(boolean)
public int getBacklog()
getBacklog
in interface SocketAcceptor
public void setBacklog(int backlog)
setBacklog
in interface SocketAcceptor
protected NioSession accept(IoProcessor<NioSession> processor, java.nio.channels.ServerSocketChannel handle) throws java.lang.Exception
IoSession
associated with the given IoProcessor
accept
in class AbstractPollingIoAcceptor<NioSession,java.nio.channels.ServerSocketChannel>
processor
- the IoProcessor
to associate with the IoSession
handle
- the server handleIoSession
java.lang.Exception
- any exception thrown by the underlying systems callsprotected java.nio.channels.ServerSocketChannel open(java.net.SocketAddress localAddress) throws java.lang.Exception
open
in class AbstractPollingIoAcceptor<NioSession,java.nio.channels.ServerSocketChannel>
localAddress
- the associated local addressjava.lang.Exception
- any exception thrown by the underlying systems callsprotected java.net.SocketAddress localAddress(java.nio.channels.ServerSocketChannel handle) throws java.lang.Exception
localAddress
in class AbstractPollingIoAcceptor<NioSession,java.nio.channels.ServerSocketChannel>
handle
- the server socketSocketAddress
associated with this handlejava.lang.Exception
- any exception thrown by the underlying systems callsprotected int select() throws java.lang.Exception
select
in class AbstractPollingIoAcceptor<NioSession,java.nio.channels.ServerSocketChannel>
IOException
- If an I/O error occursClosedSelectorException
- If this selector is closedjava.lang.Exception
- any exception thrown by the underlying systems callsprotected java.util.Iterator<java.nio.channels.ServerSocketChannel> selectedHandles()
Iterator
for the set of server sockets found with acceptable incoming connections
during the last AbstractPollingIoAcceptor.select()
call.selectedHandles
in class AbstractPollingIoAcceptor<NioSession,java.nio.channels.ServerSocketChannel>
protected void close(java.nio.channels.ServerSocketChannel handle) throws java.lang.Exception
close
in class AbstractPollingIoAcceptor<NioSession,java.nio.channels.ServerSocketChannel>
handle
- the server socketjava.lang.Exception
- any exception thrown by the underlying systems callsprotected void wakeup()
AbstractPollingIoAcceptor.select()
method. Used when the poll set need to be modified.wakeup
in class AbstractPollingIoAcceptor<NioSession,java.nio.channels.ServerSocketChannel>
Copyright © 2004-2019 Apache MINA Project. All Rights Reserved.