public final class NioDatagramAcceptor extends AbstractIoAcceptor implements DatagramAcceptor, IoProcessor<NioSession>
IoAcceptor for datagram transport (UDP/IP).| Modifier and Type | Class and Description |
|---|---|
private class |
NioDatagramAcceptor.Acceptor
This private class is used to accept incoming connection from
clients.
|
AbstractIoAcceptor.AcceptorOperationFutureAbstractIoService.ServiceOperationFuture| Modifier and Type | Field and Description |
|---|---|
private NioDatagramAcceptor.Acceptor |
acceptor
The thread responsible of accepting incoming requests
|
private java.util.Map<java.net.SocketAddress,java.nio.channels.DatagramChannel> |
boundHandles |
private java.util.Queue<AbstractIoAcceptor.AcceptorOperationFuture> |
cancelQueue |
private static IoSessionRecycler |
DEFAULT_RECYCLER
A session recycler that is used to retrieve an existing session, unless it's too old.
|
private AbstractIoService.ServiceOperationFuture |
disposalFuture |
private java.util.Queue<NioSession> |
flushingSessions |
private long |
lastIdleCheckTime |
private java.util.concurrent.Semaphore |
lock
A lock used to protect the selector to be waked up before it's created
|
private java.util.Queue<AbstractIoAcceptor.AcceptorOperationFuture> |
registerQueue
A queue used to store the list of pending Binds
|
private static long |
SELECT_TIMEOUT
A timeout used for the select, as we need to get out to deal with idle
sessions
|
private boolean |
selectable |
private java.nio.channels.Selector |
selector
The Selector used by this acceptor
|
private IoSessionRecycler |
sessionRecycler |
bindLockdisposalLock, sessionConfig| Modifier | Constructor and Description |
|---|---|
|
NioDatagramAcceptor()
Creates a new instance.
|
|
NioDatagramAcceptor(java.util.concurrent.Executor executor)
Creates a new instance.
|
private |
NioDatagramAcceptor(IoSessionConfig sessionConfig,
java.util.concurrent.Executor executor)
Creates a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(NioSession session)
Adds the specified
session to the I/O processor so that
the I/O processor starts to perform any I/O operations related
with the session. |
protected java.util.Set<java.net.SocketAddress> |
bindInternal(java.util.List<? extends java.net.SocketAddress> localAddresses)
Starts the acceptor, and register the given addresses
|
protected void |
close(java.nio.channels.DatagramChannel handle) |
protected void |
destroy() |
protected void |
dispose0()
Implement this method to release any acquired resources.
|
void |
flush(NioSession session)
Flushes the internal write request queue of the specified
session. |
private boolean |
flush(NioSession session,
long currentTime) |
private void |
flushSessions(long currentTime) |
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.
|
DatagramSessionConfig |
getSessionConfig()
Returns the default Datagram configuration of the new
IoSessions
created by this service. |
IoSessionRecycler |
getSessionRecycler()
Returns the
IoSessionRecycler for this service. |
TransportMetadata |
getTransportMetadata()
Returns the
TransportMetadata that this service runs on. |
protected void |
init() |
protected boolean |
isReadable(java.nio.channels.DatagramChannel handle) |
protected boolean |
isWritable(java.nio.channels.DatagramChannel handle) |
protected java.net.SocketAddress |
localAddress(java.nio.channels.DatagramChannel handle) |
protected NioSession |
newSession(IoProcessor<NioSession> processor,
java.nio.channels.DatagramChannel handle,
java.net.SocketAddress remoteAddress) |
IoSession |
newSession(java.net.SocketAddress remoteAddress,
java.net.SocketAddress localAddress)
(Optional) Returns an
IoSession that is bound to the specified
localAddress and the specified remoteAddress which
reuses the local address that is already bound by this service. |
private IoSession |
newSessionWithoutLock(java.net.SocketAddress remoteAddress,
java.net.SocketAddress localAddress) |
private void |
notifyIdleSessions(long currentTime) |
protected java.nio.channels.DatagramChannel |
open(java.net.SocketAddress localAddress) |
private void |
processReadySessions(java.util.Set<java.nio.channels.SelectionKey> handles) |
private void |
readHandle(java.nio.channels.DatagramChannel handle) |
protected java.net.SocketAddress |
receive(java.nio.channels.DatagramChannel handle,
IoBuffer buffer) |
private int |
registerHandles() |
void |
remove(NioSession session)
Removes and closes the specified
session from the I/O
processor so that the I/O processor closes the connection
associated with the session and releases any other related
resources. |
private boolean |
scheduleFlush(NioSession session) |
protected int |
select() |
protected int |
select(long timeout) |
protected java.util.Set<java.nio.channels.SelectionKey> |
selectedHandles() |
protected int |
send(NioSession session,
IoBuffer buffer,
java.net.SocketAddress remoteAddress) |
void |
setDefaultLocalAddress(java.net.InetSocketAddress localAddress)
Sets the default local InetSocketAddress to bind when no argument is specified in
IoAcceptor.bind() method. |
protected void |
setInterestedInWrite(NioSession session,
boolean isInterested) |
void |
setSessionRecycler(IoSessionRecycler sessionRecycler)
Sets the
IoSessionRecycler for this service. |
private void |
startupAcceptor()
Starts the inner Acceptor thread.
|
protected void |
unbind0(java.util.List<? extends java.net.SocketAddress> localAddresses)
Implement this method to perform the actual unbind operation.
|
private int |
unregisterHandles() |
void |
updateTrafficControl(NioSession session)
Controls the traffic of the specified
session depending of the
IoSession.isReadSuspended() and IoSession.isWriteSuspended()
flags |
protected void |
wakeup() |
void |
write(NioSession session,
WriteRequest writeRequest)
Writes the WriteRequest for the specified
session. |
bind, bind, bind, bind, bind, getDefaultLocalAddresses, getLocalAddresses, isCloseOnDeactivation, setCloseOnDeactivation, setDefaultLocalAddress, setDefaultLocalAddresses, setDefaultLocalAddresses, setDefaultLocalAddresses, toString, unbind, unbind, unbind, unbindaddListener, broadcast, dispose, dispose, executeWorker, executeWorker, finishSessionInitialization0, getActivationTime, getFilterChain, getFilterChainBuilder, getHandler, getListeners, getManagedSessionCount, getManagedSessions, getScheduledWriteBytes, getScheduledWriteMessages, getSessionDataStructureFactory, getStatistics, initSession, isActive, isDisposed, isDisposing, removeListener, setFilterChainBuilder, setHandler, setSessionDataStructureFactoryclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitbind, bind, bind, bind, bind, getDefaultLocalAddresses, getLocalAddresses, isCloseOnDeactivation, setCloseOnDeactivation, setDefaultLocalAddress, setDefaultLocalAddresses, setDefaultLocalAddresses, setDefaultLocalAddresses, unbind, unbind, unbind, unbindaddListener, broadcast, dispose, dispose, getActivationTime, getFilterChain, getFilterChainBuilder, getHandler, getManagedSessionCount, getManagedSessions, getScheduledWriteBytes, getScheduledWriteMessages, getSessionDataStructureFactory, getStatistics, isActive, isDisposed, isDisposing, removeListener, setFilterChainBuilder, setHandler, setSessionDataStructureFactorydispose, isDisposed, isDisposingprivate static final IoSessionRecycler DEFAULT_RECYCLER
private static final long SELECT_TIMEOUT
private final java.util.concurrent.Semaphore lock
private final java.util.Queue<AbstractIoAcceptor.AcceptorOperationFuture> registerQueue
private final java.util.Queue<AbstractIoAcceptor.AcceptorOperationFuture> cancelQueue
private final java.util.Queue<NioSession> flushingSessions
private final java.util.Map<java.net.SocketAddress,java.nio.channels.DatagramChannel> boundHandles
private IoSessionRecycler sessionRecycler
private final AbstractIoService.ServiceOperationFuture disposalFuture
private volatile boolean selectable
private NioDatagramAcceptor.Acceptor acceptor
private long lastIdleCheckTime
private volatile java.nio.channels.Selector selector
public NioDatagramAcceptor()
public NioDatagramAcceptor(java.util.concurrent.Executor executor)
private NioDatagramAcceptor(IoSessionConfig sessionConfig, java.util.concurrent.Executor executor)
private int registerHandles()
private void processReadySessions(java.util.Set<java.nio.channels.SelectionKey> handles)
private boolean scheduleFlush(NioSession session)
private void readHandle(java.nio.channels.DatagramChannel handle)
throws java.lang.Exception
java.lang.Exceptionprivate IoSession newSessionWithoutLock(java.net.SocketAddress remoteAddress, java.net.SocketAddress localAddress) throws java.lang.Exception
java.lang.Exceptionprivate void flushSessions(long currentTime)
private boolean flush(NioSession session, long currentTime) throws java.lang.Exception
java.lang.Exceptionprivate int unregisterHandles()
private void notifyIdleSessions(long currentTime)
private void startupAcceptor()
throws java.lang.InterruptedException
java.lang.InterruptedExceptionprotected void init()
throws java.lang.Exception
java.lang.Exceptionpublic void add(NioSession session)
session to the I/O processor so that
the I/O processor starts to perform any I/O operations related
with the session.add in interface IoProcessor<NioSession>session - The added sessionprotected final java.util.Set<java.net.SocketAddress> bindInternal(java.util.List<? extends java.net.SocketAddress> localAddresses)
throws java.lang.Exception
bindInternal in class AbstractIoAcceptorSet of the local addresses which is bound actuallyjava.lang.Exceptionprotected void close(java.nio.channels.DatagramChannel handle)
throws java.lang.Exception
java.lang.Exceptionprotected void destroy()
throws java.lang.Exception
java.lang.Exceptionprotected void dispose0()
throws java.lang.Exception
AbstractIoService.dispose().dispose0 in class AbstractIoServicejava.lang.Exceptionpublic void flush(NioSession session)
session.flush in interface IoProcessor<NioSession>session - The session we want the message to be writtenpublic java.net.InetSocketAddress getDefaultLocalAddress()
AbstractIoAcceptorIoAcceptor.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 IoAcceptorgetDefaultLocalAddress in interface DatagramAcceptorgetDefaultLocalAddress in class AbstractIoAcceptorpublic java.net.InetSocketAddress getLocalAddress()
AbstractIoAcceptorgetLocalAddress in interface IoAcceptorgetLocalAddress in interface DatagramAcceptorgetLocalAddress in class AbstractIoAcceptorpublic DatagramSessionConfig getSessionConfig()
IoSessions
created by this service.getSessionConfig in interface IoServicegetSessionConfig in interface DatagramAcceptorpublic final IoSessionRecycler getSessionRecycler()
DatagramAcceptorIoSessionRecycler for this service.getSessionRecycler in interface DatagramAcceptorpublic TransportMetadata getTransportMetadata()
IoServiceTransportMetadata that this service runs on.getTransportMetadata in interface IoServiceprotected boolean isReadable(java.nio.channels.DatagramChannel handle)
protected boolean isWritable(java.nio.channels.DatagramChannel handle)
protected java.net.SocketAddress localAddress(java.nio.channels.DatagramChannel handle)
throws java.lang.Exception
java.lang.Exceptionprotected NioSession newSession(IoProcessor<NioSession> processor, java.nio.channels.DatagramChannel handle, java.net.SocketAddress remoteAddress)
public final IoSession newSession(java.net.SocketAddress remoteAddress, java.net.SocketAddress localAddress)
IoSession that is bound to the specified
localAddress and the specified remoteAddress which
reuses the local address that is already bound by this service.
This operation is optional. Please throw UnsupportedOperationException
if the transport type doesn't support this operation. This operation is
usually implemented for connectionless transport types.
newSession in interface IoAcceptorprotected java.nio.channels.DatagramChannel open(java.net.SocketAddress localAddress)
throws java.lang.Exception
java.lang.Exceptionprotected java.net.SocketAddress receive(java.nio.channels.DatagramChannel handle,
IoBuffer buffer)
throws java.lang.Exception
java.lang.Exceptionpublic void remove(NioSession session)
session from the I/O
processor so that the I/O processor closes the connection
associated with the session and releases any other related
resources.remove in interface IoProcessor<NioSession>protected int select()
throws java.lang.Exception
java.lang.Exceptionprotected int select(long timeout)
throws java.lang.Exception
java.lang.Exceptionprotected java.util.Set<java.nio.channels.SelectionKey> selectedHandles()
protected int send(NioSession session, IoBuffer buffer, java.net.SocketAddress remoteAddress) throws java.lang.Exception
java.lang.Exceptionpublic void setDefaultLocalAddress(java.net.InetSocketAddress localAddress)
DatagramAcceptorIoAcceptor.bind() method. Please note that the default will not be used
if any local InetSocketAddress is specified.
This method overrides the IoAcceptor.setDefaultLocalAddress(java.net.SocketAddress) method.setDefaultLocalAddress in interface DatagramAcceptorprotected void setInterestedInWrite(NioSession session, boolean isInterested) throws java.lang.Exception
java.lang.Exceptionpublic final void setSessionRecycler(IoSessionRecycler sessionRecycler)
DatagramAcceptorIoSessionRecycler for this service.setSessionRecycler in interface DatagramAcceptorsessionRecycler - null to use the default recyclerprotected final void unbind0(java.util.List<? extends java.net.SocketAddress> localAddresses)
throws java.lang.Exception
unbind0 in class AbstractIoAcceptorjava.lang.Exceptionpublic void updateTrafficControl(NioSession session)
session depending of the
IoSession.isReadSuspended() and IoSession.isWriteSuspended()
flagsupdateTrafficControl in interface IoProcessor<NioSession>protected void wakeup()
public void write(NioSession session, WriteRequest writeRequest)
session.write in interface IoProcessor<NioSession>session - The session we want the message to be writtenwriteRequest - the WriteRequest to write