public final class NioDatagramConnector extends AbstractPollingIoConnector<NioSession,java.nio.channels.DatagramChannel> implements DatagramConnector
IoConnector
for datagram transport (UDP/IP).AbstractPollingIoConnector.ConnectionRequest
AbstractIoService.ServiceOperationFuture
disposalLock
Constructor and Description |
---|
NioDatagramConnector()
Creates a new instance.
|
NioDatagramConnector(java.lang.Class<? extends IoProcessor<NioSession>> processorClass)
Constructor for
NioDatagramConnector with default configuration with default configuration which will use a built-in
thread pool executor to manage the default number of processor instances. |
NioDatagramConnector(java.lang.Class<? extends IoProcessor<NioSession>> processorClass,
int processorCount)
Constructor for
NioDatagramConnector with default configuration which will use a built-in
thread pool executor to manage the given number of processor instances. |
NioDatagramConnector(int processorCount)
Creates a new instance.
|
NioDatagramConnector(IoProcessor<NioSession> processor)
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
protected java.util.Iterator<java.nio.channels.DatagramChannel> |
allHandles()
Iterator for all the client sockets polled for connection. |
protected void |
close(java.nio.channels.DatagramChannel handle)
Close a client socket.
|
protected boolean |
connect(java.nio.channels.DatagramChannel 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.DatagramChannel 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.DatagramChannel handle)
get the
AbstractPollingIoConnector.ConnectionRequest for a given client socket handle |
java.net.InetSocketAddress |
getDefaultRemoteAddress()
Returns the default remote address to connect to when no argument
is specified in
IoConnector.connect() method. |
DatagramSessionConfig |
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.
|
protected java.nio.channels.DatagramChannel |
newHandle(java.net.SocketAddress localAddress)
Create a new client socket handle from a local
SocketAddress |
protected NioSession |
newSession(IoProcessor<NioSession> processor,
java.nio.channels.DatagramChannel handle)
Create a new
IoSession from a connected socket client handle. |
protected void |
register(java.nio.channels.DatagramChannel 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.DatagramChannel> |
selectedHandles()
Iterator for the set of client sockets found connected or
failed to connect during the last #select() call. |
void |
setDefaultRemoteAddress(java.net.InetSocketAddress defaultRemoteAddress) |
protected void |
wakeup()
Interrupt the
#select() method. |
connect0, dispose0
connect, connect, connect, connect, connect, connect, finishSessionInitialization0, getConnectTimeout, getConnectTimeoutCheckInterval, getConnectTimeoutMillis, setConnectTimeout, setConnectTimeoutCheckInterval, setConnectTimeoutMillis, 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, setConnectTimeout, setConnectTimeoutMillis, setDefaultRemoteAddress
addListener, broadcast, dispose, dispose, getActivationTime, getFilterChain, getFilterChainBuilder, getHandler, getManagedSessionCount, getManagedSessions, getScheduledWriteBytes, getScheduledWriteMessages, getSessionDataStructureFactory, getStatistics, isActive, isDisposed, isDisposing, removeListener, setFilterChainBuilder, setHandler, setSessionDataStructureFactory
public NioDatagramConnector()
public NioDatagramConnector(int processorCount)
public NioDatagramConnector(IoProcessor<NioSession> processor)
public NioDatagramConnector(java.lang.Class<? extends IoProcessor<NioSession>> processorClass, int processorCount)
NioDatagramConnector
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)
public NioDatagramConnector(java.lang.Class<? extends IoProcessor<NioSession>> processorClass)
NioDatagramConnector
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)
,
SimpleIoProcessorPool.DEFAULT_SIZE
public TransportMetadata getTransportMetadata()
IoService
TransportMetadata
that this service runs on.getTransportMetadata
in interface IoService
public DatagramSessionConfig getSessionConfig()
AbstractIoService
IoSession
s
created by this service.getSessionConfig
in interface IoService
getSessionConfig
in class AbstractIoService
public java.net.InetSocketAddress getDefaultRemoteAddress()
AbstractIoConnector
IoConnector.connect()
method.getDefaultRemoteAddress
in interface IoConnector
getDefaultRemoteAddress
in interface DatagramConnector
getDefaultRemoteAddress
in class AbstractIoConnector
public void setDefaultRemoteAddress(java.net.InetSocketAddress defaultRemoteAddress)
setDefaultRemoteAddress
in interface DatagramConnector
protected void init() throws java.lang.Exception
AbstractPollingIoConnector
init
in class AbstractPollingIoConnector<NioSession,java.nio.channels.DatagramChannel>
java.lang.Exception
- any exception thrown by the underlying system callsprotected java.nio.channels.DatagramChannel newHandle(java.net.SocketAddress localAddress) throws java.lang.Exception
AbstractPollingIoConnector
SocketAddress
newHandle
in class AbstractPollingIoConnector<NioSession,java.nio.channels.DatagramChannel>
localAddress
- the socket address for binding the new client socketjava.lang.Exception
- any exception thrown by the underlying systems callsprotected boolean connect(java.nio.channels.DatagramChannel handle, java.net.SocketAddress remoteAddress) throws java.lang.Exception
AbstractPollingIoConnector
SocketAddress
.
This operation is non-blocking, so at end of the call the socket can be still in connection
process.connect
in class AbstractPollingIoConnector<NioSession,java.nio.channels.DatagramChannel>
handle
- the client socket handleremoteAddress
- the remote address where to connectjava.lang.Exception
protected NioSession newSession(IoProcessor<NioSession> processor, java.nio.channels.DatagramChannel handle)
AbstractPollingIoConnector
IoSession
from a connected socket client handle.
Will assign the created IoSession
to the given IoProcessor
for
managing future I/O events.newSession
in class AbstractPollingIoConnector<NioSession,java.nio.channels.DatagramChannel>
processor
- the processor in charge of this sessionhandle
- the newly connected client socket handleIoSession
protected void close(java.nio.channels.DatagramChannel handle) throws java.lang.Exception
AbstractPollingIoConnector
close
in class AbstractPollingIoConnector<NioSession,java.nio.channels.DatagramChannel>
handle
- the client socketjava.lang.Exception
- any exception thrown by the underlying systems callsprotected java.util.Iterator<java.nio.channels.DatagramChannel> allHandles()
AbstractPollingIoConnector
Iterator
for all the client sockets polled for connection.allHandles
in class AbstractPollingIoConnector<NioSession,java.nio.channels.DatagramChannel>
protected AbstractPollingIoConnector.ConnectionRequest getConnectionRequest(java.nio.channels.DatagramChannel handle)
AbstractPollingIoConnector
AbstractPollingIoConnector.ConnectionRequest
for a given client socket handlegetConnectionRequest
in class AbstractPollingIoConnector<NioSession,java.nio.channels.DatagramChannel>
handle
- the socket client handlenull
protected void destroy() throws java.lang.Exception
AbstractPollingIoConnector
IoConnector
implementation will be disposed.destroy
in class AbstractPollingIoConnector<NioSession,java.nio.channels.DatagramChannel>
java.lang.Exception
- any exception thrown by the underlying systems callsprotected boolean finishConnect(java.nio.channels.DatagramChannel handle) throws java.lang.Exception
AbstractPollingIoConnector
AbstractPollingIoConnector.select(int)
call. The socket will be connected or reported as connection
failed.finishConnect
in class AbstractPollingIoConnector<NioSession,java.nio.channels.DatagramChannel>
handle
- the client socket handle to finsh to connectjava.lang.Exception
- any exception thrown by the underlying systems callsprotected void register(java.nio.channels.DatagramChannel handle, AbstractPollingIoConnector.ConnectionRequest request) throws java.lang.Exception
AbstractPollingIoConnector
register
in class AbstractPollingIoConnector<NioSession,java.nio.channels.DatagramChannel>
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
AbstractPollingIoConnector.selectedHandles()
select
in class AbstractPollingIoConnector<NioSession,java.nio.channels.DatagramChannel>
java.lang.Exception
- any exception thrown by the underlying systems callsprotected java.util.Iterator<java.nio.channels.DatagramChannel> selectedHandles()
AbstractPollingIoConnector
Iterator
for the set of client sockets found connected or
failed to connect during the last #select()
call.selectedHandles
in class AbstractPollingIoConnector<NioSession,java.nio.channels.DatagramChannel>
protected void wakeup()
AbstractPollingIoConnector
#select()
method. Used when the poll set need to be modified.wakeup
in class AbstractPollingIoConnector<NioSession,java.nio.channels.DatagramChannel>
Copyright © 2004-2019 Apache MINA Project. All Rights Reserved.