public final class NioDatagramAcceptor extends AbstractIoAcceptor implements DatagramAcceptor, IoProcessor<NioSession>
IoAcceptor
for datagram transport (UDP/IP).AbstractIoAcceptor.AcceptorOperationFuture
AbstractIoService.ServiceOperationFuture
bindLock
disposalLock, LOGGER, sessionConfig
Constructor and Description |
---|
NioDatagramAcceptor()
Creates a new instance.
|
NioDatagramAcceptor(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 Set<SocketAddress> |
bindInternal(List<? extends SocketAddress> localAddresses)
Starts the acceptor, and register the given addresses
|
protected void |
close(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 . |
InetSocketAddress |
getDefaultLocalAddress()
Returns the default local address to bind when no argument is specified
in
IoAcceptor.bind() method. |
InetSocketAddress |
getLocalAddress()
Returns the local address which is bound currently.
|
DatagramSessionConfig |
getSessionConfig() |
IoSessionRecycler |
getSessionRecycler() |
TransportMetadata |
getTransportMetadata() |
protected void |
init() |
protected boolean |
isReadable(DatagramChannel handle) |
protected boolean |
isWritable(DatagramChannel handle) |
protected SocketAddress |
localAddress(DatagramChannel handle) |
protected NioSession |
newSession(IoProcessor<NioSession> processor,
DatagramChannel handle,
SocketAddress remoteAddress) |
IoSession |
newSession(SocketAddress remoteAddress,
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. |
protected DatagramChannel |
open(SocketAddress localAddress) |
protected SocketAddress |
receive(DatagramChannel handle,
IoBuffer buffer) |
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. |
protected int |
select() |
protected int |
select(long timeout) |
protected Set<SelectionKey> |
selectedHandles() |
protected int |
send(NioSession session,
IoBuffer buffer,
SocketAddress remoteAddress) |
void |
setDefaultLocalAddress(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. |
protected void |
unbind0(List<? extends SocketAddress> localAddresses)
Implement this method to perform the actual unbind operation.
|
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, 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, bind, getDefaultLocalAddresses, getLocalAddresses, isCloseOnDeactivation, 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
dispose, isDisposed, isDisposing
public NioDatagramAcceptor()
public NioDatagramAcceptor(Executor executor)
executor
- The executor to usepublic 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 Set<SocketAddress> bindInternal(List<? extends SocketAddress> localAddresses) throws Exception
bindInternal
in class AbstractIoAcceptor
localAddresses
- The address to bind toSet
of the local addresses which is bound actuallyException
- If the bind failedprotected void close(DatagramChannel handle) throws Exception
Exception
protected void dispose0() throws Exception
AbstractIoService.dispose()
.dispose0
in class AbstractIoService
Exception
- If the dispose failedpublic void flush(NioSession session)
session
.flush
in interface IoProcessor<NioSession>
session
- The session we want the message to be writtenpublic InetSocketAddress getDefaultLocalAddress()
AbstractIoAcceptor
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 DatagramAcceptor
getDefaultLocalAddress
in class AbstractIoAcceptor
public InetSocketAddress getLocalAddress()
AbstractIoAcceptor
getLocalAddress
in interface IoAcceptor
getLocalAddress
in interface DatagramAcceptor
getLocalAddress
in class AbstractIoAcceptor
public DatagramSessionConfig getSessionConfig()
getSessionConfig
in interface IoService
getSessionConfig
in interface DatagramAcceptor
IoSession
s
created by this service.public final IoSessionRecycler getSessionRecycler()
getSessionRecycler
in interface DatagramAcceptor
IoSessionRecycler
for this service.public TransportMetadata getTransportMetadata()
getTransportMetadata
in interface IoService
TransportMetadata
that this service runs on.protected boolean isReadable(DatagramChannel handle)
protected boolean isWritable(DatagramChannel handle)
protected SocketAddress localAddress(DatagramChannel handle) throws Exception
Exception
protected NioSession newSession(IoProcessor<NioSession> processor, DatagramChannel handle, SocketAddress remoteAddress)
public final IoSession newSession(SocketAddress remoteAddress, 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 IoAcceptor
remoteAddress
- The remote address bound to the servicelocalAddress
- The local address the session will be bound toprotected DatagramChannel open(SocketAddress localAddress) throws Exception
Exception
protected SocketAddress receive(DatagramChannel handle, IoBuffer buffer) throws Exception
Exception
public 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>
session
- The session to be removedprotected Set<SelectionKey> selectedHandles()
protected int send(NioSession session, IoBuffer buffer, SocketAddress remoteAddress) throws Exception
Exception
public void setDefaultLocalAddress(InetSocketAddress localAddress)
DatagramAcceptor
IoAcceptor.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 DatagramAcceptor
localAddress
- The local addressprotected void setInterestedInWrite(NioSession session, boolean isInterested) throws Exception
Exception
public final void setSessionRecycler(IoSessionRecycler sessionRecycler)
DatagramAcceptor
IoSessionRecycler
for this service.setSessionRecycler
in interface DatagramAcceptor
sessionRecycler
- null to use the default recyclerprotected final void unbind0(List<? extends SocketAddress> localAddresses) throws Exception
unbind0
in class AbstractIoAcceptor
localAddresses
- The address to unbind fromException
- If the unbind failedpublic void updateTrafficControl(NioSession session)
session
depending of the
IoSession.isReadSuspended()
and IoSession.isWriteSuspended()
flagsupdateTrafficControl
in interface IoProcessor<NioSession>
session
- The session to be updatedprotected 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 writeCopyright © 2004–2018 Apache MINA Project. All rights reserved.