public final class NioSocketConnector extends AbstractPollingIoConnector<NioSession,java.nio.channels.SocketChannel> implements SocketConnector
IoConnector
for socket transport (TCP/IP).AbstractPollingIoConnector.ConnectionRequest
AbstractIoService.ServiceOperationFuture
disposalLock, sessionConfig
构造器和说明 |
---|
NioSocketConnector()
Constructor for
NioSocketConnector with default configuration (multiple thread model). |
NioSocketConnector(java.lang.Class<? extends IoProcessor<NioSession>> processorClass)
Constructor for
NioSocketConnector with default configuration with default configuration which will use a built-in
thread pool executor to manage the default number of processor instances. |
NioSocketConnector(java.lang.Class<? extends IoProcessor<NioSession>> processorClass,
int processorCount)
Constructor for
NioSocketConnector with default configuration which will use a built-in
thread pool executor to manage the given number of processor instances. |
NioSocketConnector(java.util.concurrent.Executor executor,
IoProcessor<NioSession> processor)
Constructor for
NioSocketConnector 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. |
NioSocketConnector(int processorCount)
Constructor for
NioSocketConnector with default configuration, and
given number of NioProcessor for multithreading I/O operations |
NioSocketConnector(IoProcessor<NioSession> processor)
Constructor for
NioSocketConnector with default configuration but a
specific IoProcessor , useful for sharing the same processor over multiple
IoService of the same type. |
限定符和类型 | 方法和说明 |
---|---|
protected java.util.Iterator<java.nio.channels.SocketChannel> |
allHandles()
Iterator for all the client sockets polled for connection. |
protected void |
close(java.nio.channels.SocketChannel handle)
Close a client socket.
|
protected boolean |
connect(java.nio.channels.SocketChannel handle,
java.net.SocketAddress remoteAddress)
Connect a newly created client socket handle to a remote
SocketAddress . |
protected void |
destroy()
Destroy the polling system, will be called when this
IoConnector
implementation will be disposed. |
protected boolean |
finishConnect(java.nio.channels.SocketChannel handle)
Finish the connection process of a client socket after it was marked as
ready to process by the
AbstractPollingIoConnector.select(int) call. |
protected AbstractPollingIoConnector.ConnectionRequest |
getConnectionRequest(java.nio.channels.SocketChannel handle)
get the
AbstractPollingIoConnector.ConnectionRequest for a given client socket handle |
java.net.InetSocketAddress |
getDefaultRemoteAddress() |
SocketSessionConfig |
getSessionConfig() |
TransportMetadata |
getTransportMetadata() |
protected void |
init()
Initialize the polling system, will be called at construction time.
|
protected java.nio.channels.SocketChannel |
newHandle(java.net.SocketAddress localAddress)
Create a new client socket handle from a local
SocketAddress |
protected NioSession |
newSession(IoProcessor<NioSession> processor,
java.nio.channels.SocketChannel handle)
Create a new
IoSession from a connected socket client handle. |
protected void |
register(java.nio.channels.SocketChannel handle,
AbstractPollingIoConnector.ConnectionRequest request)
Register a new client socket for connection, add it to connection polling
|
protected int |
select(int timeout)
Check for connected sockets, interrupt when at least a connection is
processed (connected or failed to connect).
|
protected java.util.Iterator<java.nio.channels.SocketChannel> |
selectedHandles()
Iterator for the set of client sockets found connected or failed
to connect during the last AbstractPollingIoConnector.select(int) call. |
void |
setDefaultRemoteAddress(java.net.InetSocketAddress defaultRemoteAddress)
Sets the default remote InetSocketAddress to connect to when no argument is
specified in
IoConnector.connect() method. |
protected void |
wakeup()
Interrupt the
AbstractPollingIoConnector.select(int) method. |
connect0, dispose0
connect, connect, connect, connect, connect, connect, finishSessionInitialization0, getConnectTimeout, getConnectTimeoutCheckInterval, getConnectTimeoutMillis, getDefaultLocalAddress, setConnectTimeout, setConnectTimeoutCheckInterval, setConnectTimeoutMillis, setDefaultLocalAddress, setDefaultRemoteAddress, toString
addListener, broadcast, dispose, dispose, executeWorker, executeWorker, 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
connect, connect, connect, connect, connect, connect, getConnectTimeout, getConnectTimeoutMillis, getDefaultLocalAddress, setConnectTimeout, setConnectTimeoutMillis, setDefaultLocalAddress, setDefaultRemoteAddress
addListener, broadcast, dispose, dispose, getActivationTime, getFilterChain, getFilterChainBuilder, getHandler, getManagedSessionCount, getManagedSessions, getScheduledWriteBytes, getScheduledWriteMessages, getSessionDataStructureFactory, getStatistics, isActive, isDisposed, isDisposing, removeListener, setFilterChainBuilder, setHandler, setSessionDataStructureFactory
public NioSocketConnector()
NioSocketConnector
with default configuration (multiple thread model).public NioSocketConnector(int processorCount)
NioSocketConnector
with default configuration, and
given number of NioProcessor
for multithreading I/O operationsprocessorCount
- the number of processor to create and place in a
SimpleIoProcessorPool
public NioSocketConnector(IoProcessor<NioSession> processor)
NioSocketConnector
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 NioSocketConnector(java.util.concurrent.Executor executor, IoProcessor<NioSession> processor)
NioSocketConnector
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 operationspublic NioSocketConnector(java.lang.Class<? extends IoProcessor<NioSession>> processorClass, int processorCount)
NioSocketConnector
with default configuration which will use a built-in
thread pool executor to manage the given number of processor instances. The processor class must have
a constructor that accepts ExecutorService or Executor as its single argument, or, failing that, a
no-arg constructor.processorClass
- the processor class.processorCount
- the number of processors to instantiate.SimpleIoProcessorPool.SimpleIoProcessorPool(Class, Executor, int, java.nio.channels.spi.SelectorProvider)
public NioSocketConnector(java.lang.Class<? extends IoProcessor<NioSession>> processorClass)
NioSocketConnector
with default configuration with default configuration which will use a built-in
thread pool executor to manage the default number of processor instances. The processor class must have
a constructor that accepts ExecutorService or Executor as its single argument, or, failing that, a
no-arg constructor. The default number of instances is equal to the number of processor cores
in the system, plus one.processorClass
- the processor class.SimpleIoProcessorPool.SimpleIoProcessorPool(Class, Executor, int, java.nio.channels.spi.SelectorProvider)
,
SimpleIoProcessorPool.DEFAULT_SIZE
protected void init() throws java.lang.Exception
init
在类中 AbstractPollingIoConnector<NioSession,java.nio.channels.SocketChannel>
java.lang.Exception
- any exception thrown by the underlying system callsprotected void destroy() throws java.lang.Exception
IoConnector
implementation will be disposed.destroy
在类中 AbstractPollingIoConnector<NioSession,java.nio.channels.SocketChannel>
java.lang.Exception
- any exception thrown by the underlying systems callspublic TransportMetadata getTransportMetadata()
getTransportMetadata
在接口中 IoService
TransportMetadata
that this service runs on.public SocketSessionConfig getSessionConfig()
getSessionConfig
在接口中 IoService
getSessionConfig
在接口中 SocketConnector
public java.net.InetSocketAddress getDefaultRemoteAddress()
getDefaultRemoteAddress
在接口中 IoConnector
getDefaultRemoteAddress
在接口中 SocketConnector
getDefaultRemoteAddress
在类中 AbstractIoConnector
IoConnector.connect()
method.public void setDefaultRemoteAddress(java.net.InetSocketAddress defaultRemoteAddress)
IoConnector.connect()
method.
This method overrides the IoConnector.setDefaultRemoteAddress(java.net.SocketAddress)
method.setDefaultRemoteAddress
在接口中 SocketConnector
defaultRemoteAddress
- The remote address to setprotected java.util.Iterator<java.nio.channels.SocketChannel> allHandles()
Iterator
for all the client sockets polled for connection.allHandles
在类中 AbstractPollingIoConnector<NioSession,java.nio.channels.SocketChannel>
protected boolean connect(java.nio.channels.SocketChannel 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.connect
在类中 AbstractPollingIoConnector<NioSession,java.nio.channels.SocketChannel>
handle
- the client socket handleremoteAddress
- the remote address where to connectjava.lang.Exception
- If the connect failedprotected AbstractPollingIoConnector.ConnectionRequest getConnectionRequest(java.nio.channels.SocketChannel handle)
AbstractPollingIoConnector.ConnectionRequest
for a given client socket handlegetConnectionRequest
在类中 AbstractPollingIoConnector<NioSession,java.nio.channels.SocketChannel>
handle
- the socket client handlenull
protected void close(java.nio.channels.SocketChannel handle) throws java.lang.Exception
close
在类中 AbstractPollingIoConnector<NioSession,java.nio.channels.SocketChannel>
handle
- the client socketjava.lang.Exception
- any exception thrown by the underlying systems callsprotected boolean finishConnect(java.nio.channels.SocketChannel handle) throws java.lang.Exception
AbstractPollingIoConnector.select(int)
call. The socket will be
connected or reported as connection failed.finishConnect
在类中 AbstractPollingIoConnector<NioSession,java.nio.channels.SocketChannel>
handle
- the client socket handle to finish to connectjava.lang.Exception
- any exception thrown by the underlying systems callsprotected java.nio.channels.SocketChannel newHandle(java.net.SocketAddress localAddress) throws java.lang.Exception
SocketAddress
newHandle
在类中 AbstractPollingIoConnector<NioSession,java.nio.channels.SocketChannel>
localAddress
- the socket address for binding the new client socketjava.lang.Exception
- any exception thrown by the underlying systems callsprotected NioSession newSession(IoProcessor<NioSession> processor, java.nio.channels.SocketChannel handle)
IoSession
from a connected socket client handle.
Will assign the created IoSession
to the given
IoProcessor
for managing future I/O events.newSession
在类中 AbstractPollingIoConnector<NioSession,java.nio.channels.SocketChannel>
processor
- the processor in charge of this sessionhandle
- the newly connected client socket handleIoSession
protected void register(java.nio.channels.SocketChannel handle, AbstractPollingIoConnector.ConnectionRequest request) throws java.lang.Exception
register
在类中 AbstractPollingIoConnector<NioSession,java.nio.channels.SocketChannel>
handle
- client socket handlerequest
- the associated AbstractPollingIoConnector.ConnectionRequest
java.lang.Exception
- any exception thrown by the underlying systems callsprotected int select(int timeout) throws java.lang.Exception
AbstractPollingIoConnector.selectedHandles()
select
在类中 AbstractPollingIoConnector<NioSession,java.nio.channels.SocketChannel>
timeout
- The timeout for the select() methodjava.lang.Exception
- any exception thrown by the underlying systems callsprotected java.util.Iterator<java.nio.channels.SocketChannel> selectedHandles()
Iterator
for the set of client sockets found connected or failed
to connect during the last AbstractPollingIoConnector.select(int)
call.selectedHandles
在类中 AbstractPollingIoConnector<NioSession,java.nio.channels.SocketChannel>
protected void wakeup()
AbstractPollingIoConnector.select(int)
method. Used when the poll set need to
be modified.wakeup
在类中 AbstractPollingIoConnector<NioSession,java.nio.channels.SocketChannel>