Class UDPNIOTransport
- java.lang.Object
-
- org.glassfish.grizzly.AbstractTransport
-
- org.glassfish.grizzly.nio.NIOTransport
-
- org.glassfish.grizzly.nio.transport.UDPNIOTransport
-
- All Implemented Interfaces:
AsyncQueueEnabledTransport
,ConnectorHandler<SocketAddress>
,FilterChainEnabledTransport
,MonitoringAware<TransportProbe>
,TemporarySelectorsEnabledTransport
,SocketBinder
,SocketConnectorHandler
,Transport
public final class UDPNIOTransport extends NIOTransport implements FilterChainEnabledTransport
UDP NIO transport implementation- Author:
- Alexey Stashok
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
UDPNIOTransport.RegisterChannelCompletionHandler
protected class
UDPNIOTransport.TransportConnectorHandler
Transport defaultUDPNIOConnectorHandler
.-
Nested classes/interfaces inherited from interface org.glassfish.grizzly.Transport
Transport.State
-
-
Field Summary
Fields Modifier and Type Field Description protected AsyncQueueIO<SocketAddress>
asyncQueueIO
Transport AsyncQueueIOstatic ChannelConfigurator
DEFAULT_CHANNEL_CONFIGURATOR
DefaultChannelConfigurator
used to configure client and server side channels.protected UDPNIOTransport.RegisterChannelCompletionHandler
registerChannelCompletionHandler
protected Collection<UDPNIOServerConnection>
serverConnections
The Server connections.-
Fields inherited from class org.glassfish.grizzly.nio.NIOTransport
channelConfigurator, DEFAULT_CLIENT_SOCKET_SO_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT, DEFAULT_OPTIMIZED_FOR_MULTIPLEXING, DEFAULT_REUSE_ADDRESS, DEFAULT_SELECTOR_RUNNER_COUNT, DEFAULT_SERVER_SOCKET_SO_TIMEOUT, nioChannelDistributor, selectionKeyHandler, selectorHandler, selectorProvider, selectorRunners, shutdownFuture, shutdownListeners, shutdownService, temporarySelectorIO
-
Fields inherited from class org.glassfish.grizzly.AbstractTransport
attributeBuilder, connectionMonitoringConfig, isBlocking, isStandalone, kernelPool, kernelPoolConfig, managedWorkerPool, memoryManager, name, processor, processorSelector, readBufferSize, readTimeout, state, strategy, threadPoolMonitoringConfig, transportMonitoringConfig, workerPoolConfig, workerThreadPool, writeBufferSize, writeTimeout
-
Fields inherited from interface org.glassfish.grizzly.Transport
DEFAULT_READ_BUFFER_SIZE, DEFAULT_READ_TIMEOUT, DEFAULT_WRITE_BUFFER_SIZE, DEFAULT_WRITE_TIMEOUT
-
-
Constructor Summary
Constructors Constructor Description UDPNIOTransport()
UDPNIOTransport(String name)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addShutdownListener(GracefulShutdownListener shutdownListener)
Adds aGracefulShutdownListener
which will be called whenTransport.shutdown()
is called to enable graceful shutdown of transports.UDPNIOServerConnection
bind(int port)
Binds Transport to the specific port on localhost.UDPNIOServerConnection
bind(String host, int port)
Binds Transport to the specific host and port.UDPNIOServerConnection
bind(String host, int port, int backlog)
Binds Transport to the specific host and port.UDPNIOServerConnection
bind(String host, PortRange portRange, boolean randomStartPort, int backlog)
Binds Transport to the specific host, and port within aPortRange
.UDPNIOServerConnection
bind(String host, PortRange portRange, int backlog)
Binds Transport to the specific host, and port within aPortRange
.UDPNIOServerConnection
bind(SocketAddress socketAddress)
Binds Transport to the specific SocketAddress.UDPNIOServerConnection
bind(SocketAddress socketAddress, int backlog)
Binds Transport to the specific SocketAddress.Connection<?>
bindToInherited()
Binds the Transport to the channel inherited from the entity that created this Java virtual machine.protected void
closeConnection(Connection connection)
Close the connection, managed by Transportvoid
configureStandalone(boolean isStandalone)
GrizzlyFuture<Connection>
connect()
Creates non-connected UDPConnection
.GrizzlyFuture<Connection>
connect(String host, int port)
Creates, initializes and connects socket to the specific remote host and port and returnsConnection
, representing socket.GrizzlyFuture<Connection>
connect(SocketAddress remoteAddress)
Creates, initializes and connects socket to the specificSocketAddress
and returnsConnection
, representing socket.GrizzlyFuture<Connection>
connect(SocketAddress remoteAddress, SocketAddress localAddress)
Creates, initializes socket, binds it to the specific local and remoteSocketAddress
and returnsConnection
, representing socket.void
connect(SocketAddress remoteAddress, SocketAddress localAddress, CompletionHandler<Connection> completionHandler)
Creates, initializes socket, binds it to the specific local and remoteSocketAddress
and returnsConnection
, representing socket.void
connect(SocketAddress remoteAddress, CompletionHandler<Connection> completionHandler)
Creates, initializes and connects socket to the specificSocketAddress
and returnsConnection
, representing socket.protected Object
createJmxManagementObject()
Create the Transport JMX management object.protected TemporarySelectorIO
createTemporarySelectorIO()
void
fireIOEvent(IOEvent ioEvent, Connection connection, IOEventLifeCycleListener listener)
Fires specificIOEvent
on theConnection
AsyncQueueIO
getAsyncQueueIO()
Get asynchronous queue implementation.ChannelConfigurator
getChannelConfigurator()
Reader
getReader(boolean isBlocking)
Get theReader
implementation, depending on the requested mode.Reader
getReader(Connection connection)
Get theReader
to read data from theConnection
.TemporarySelectorIO
getTemporarySelectorIO()
Filter
getTransportFilter()
Get transportFilter
, which is aware ofTransport
specifics; knows how to read/write from/toTransport
specificConnection
streams.Writer
getWriter(boolean isBlocking)
Get theWriter
implementation, depending on the requested mode.Writer
getWriter(Connection connection)
Get theWriter
to write data to theConnection
.protected void
listen()
int
read(UDPNIOConnection connection, Buffer buffer)
int
read(UDPNIOConnection connection, Buffer buffer, ReadResult<Buffer,SocketAddress> currentResult)
void
unbind(Connection connection)
Unbinds boundTransport
connection.void
unbindAll()
Unbinds all boundTransport
connections.long
write(UDPNIOConnection connection, SocketAddress dstAddress, WritableMessage message)
long
write(UDPNIOConnection connection, SocketAddress dstAddress, WritableMessage message, WriteResult<WritableMessage,SocketAddress> currentResult)
-
Methods inherited from class org.glassfish.grizzly.nio.NIOTransport
configureNIOConnection, createShutdownExecutorService, finalizeShutdown, getClientSocketSoTimeout, getConnectionTimeout, getDefaultSelectorRunnersCount, getNIOChannelDistributor, getSelectionKeyHandler, getSelectorHandler, getSelectorProvider, getSelectorRunners, getSelectorRunnersCount, getServerSocketSoTimeout, isOptimizedForMultiplexing, isReuseAddress, notifyProbesError, notifyProbesPause, notifyProbesResume, notifyProbesStart, notifyProbesStop, notifyTransportError, pause, resume, setChannelConfigurator, setClientSocketSoTimeout, setConnectionTimeout, setNIOChannelDistributor, setOptimizedForMultiplexing, setReuseAddress, setSelectionKeyHandler, setSelectorHandler, setSelectorProvider, setSelectorRunnersCount, setServerSocketSoTimeout, shutdown, shutdown, shutdownNow, start, startSelectorRunners, stopSelectorRunners
-
Methods inherited from class org.glassfish.grizzly.AbstractTransport
configureBlocking, getAttributeBuilder, getConnectionMonitoringConfig, getIOStrategy, getKernelThreadPool, getKernelThreadPoolConfig, getMemoryManager, getMonitoringConfig, getName, getProcessor, getProcessorSelector, getReadBufferSize, getReadTimeout, getState, getThreadPoolMonitoringConfig, getWorkerThreadPool, getWorkerThreadPoolConfig, getWriteBufferSize, getWriteTimeout, isBlocking, isPaused, isStandalone, isStopped, notifyProbesBeforePause, notifyProbesBeforeResume, notifyProbesBeforeStart, notifyProbesBeforeStop, notifyProbesConfigChanged, notifyProbesPause, notifyProbesStop, obtainProcessor, setAttributeBuilder, setIOStrategy, setKernelPool0, setKernelThreadPool, setKernelThreadPoolConfig, setMemoryManager, setName, setProcessor, setProcessorSelector, setReadBufferSize, setReadTimeout, setWorkerThreadPool, setWorkerThreadPool0, setWorkerThreadPoolConfig, setWriteBufferSize, setWriteTimeout, stop
-
-
-
-
Field Detail
-
DEFAULT_CHANNEL_CONFIGURATOR
public static final ChannelConfigurator DEFAULT_CHANNEL_CONFIGURATOR
DefaultChannelConfigurator
used to configure client and server side channels.
-
serverConnections
protected final Collection<UDPNIOServerConnection> serverConnections
The Server connections.
-
asyncQueueIO
protected final AsyncQueueIO<SocketAddress> asyncQueueIO
Transport AsyncQueueIO
-
registerChannelCompletionHandler
protected final UDPNIOTransport.RegisterChannelCompletionHandler registerChannelCompletionHandler
-
-
Constructor Detail
-
UDPNIOTransport
public UDPNIOTransport()
-
UDPNIOTransport
public UDPNIOTransport(String name)
-
-
Method Detail
-
createTemporarySelectorIO
protected TemporarySelectorIO createTemporarySelectorIO()
- Specified by:
createTemporarySelectorIO
in classNIOTransport
-
listen
protected void listen()
- Specified by:
listen
in classNIOTransport
-
addShutdownListener
public boolean addShutdownListener(GracefulShutdownListener shutdownListener)
Description copied from interface:Transport
Adds aGracefulShutdownListener
which will be called whenTransport.shutdown()
is called to enable graceful shutdown of transports. This allows the owner of the listener to signal that all shutdown tasks are complete and that it's safe to finalize the termination of the transport- Specified by:
addShutdownListener
in interfaceTransport
- Overrides:
addShutdownListener
in classNIOTransport
- Parameters:
shutdownListener
- theGracefulShutdownListener
- Returns:
true
if the listener was successfully registered, otherwisefalse
. When this method returnsfalse
it means one of two things: the transport is stopping or is stopped, or the listener has already been registered.
-
bind
public UDPNIOServerConnection bind(int port) throws IOException
Binds Transport to the specific port on localhost.- Specified by:
bind
in interfaceSocketBinder
- Parameters:
port
- the port to bind to- Returns:
- bound
Connection
- Throws:
IOException
- if unable to bind i.e. if port already bound
-
bind
public UDPNIOServerConnection bind(String host, int port) throws IOException
Binds Transport to the specific host and port.- Specified by:
bind
in interfaceSocketBinder
- Parameters:
host
- the local host the server will bind toport
- specific port to bind to- Returns:
- bound
Connection
- Throws:
IOException
- if unable to bind i.e. if port already bound
-
bind
public UDPNIOServerConnection bind(String host, int port, int backlog) throws IOException
Binds Transport to the specific host and port.- Specified by:
bind
in interfaceSocketBinder
- Parameters:
host
- the local host the server will bind toport
- the port to bind tobacklog
- the maximum length of the queue- Returns:
- bound
Connection
- Throws:
IOException
- if unable to bind i.e. if port already bound
-
bind
public UDPNIOServerConnection bind(SocketAddress socketAddress) throws IOException
Binds Transport to the specific SocketAddress.- Specified by:
bind
in interfaceSocketBinder
- Parameters:
socketAddress
- the local address the server will bind to- Returns:
- bound
Connection
- Throws:
IOException
- if unable to bind i.e. if port already bound
-
bind
public UDPNIOServerConnection bind(SocketAddress socketAddress, int backlog) throws IOException
Binds Transport to the specific SocketAddress.- Specified by:
bind
in interfaceSocketBinder
- Parameters:
socketAddress
- the local address the server will bind tobacklog
- the maximum length of the queue- Returns:
- bound
Connection
- Throws:
IOException
- if unable to bind i.e. if port already bound
-
bindToInherited
public Connection<?> bindToInherited() throws IOException
Description copied from interface:SocketBinder
Binds the Transport to the channel inherited from the entity that created this Java virtual machine.- Specified by:
bindToInherited
in interfaceSocketBinder
- Returns:
- bound
Connection
- Throws:
IOException
- if unable to bind i.e. if port already bound
-
bind
public UDPNIOServerConnection bind(String host, PortRange portRange, int backlog) throws IOException
Binds Transport to the specific host, and port within aPortRange
.- Specified by:
bind
in interfaceSocketBinder
- Parameters:
host
- the local host the server will bind toportRange
-PortRange
.backlog
- the maximum length of the queue- Returns:
- bound
Connection
- Throws:
IOException
- if unable to bind i.e. if port already bound
-
bind
public UDPNIOServerConnection bind(String host, PortRange portRange, boolean randomStartPort, int backlog) throws IOException
Binds Transport to the specific host, and port within aPortRange
.- Specified by:
bind
in interfaceSocketBinder
- Parameters:
host
- the local host the server will bind toportRange
-PortRange
.randomStartPort
- if true, a random port in the range will be used as the initial port.backlog
- the maximum length of the queue- Returns:
- bound
Connection
- Throws:
IOException
- if unable to bind i.e. if port already bound
-
unbind
public void unbind(Connection connection)
Unbinds boundTransport
connection.- Specified by:
unbind
in interfaceSocketBinder
- Parameters:
connection
-Connection
-
unbindAll
public void unbindAll()
Description copied from interface:SocketBinder
Unbinds all boundTransport
connections.- Specified by:
unbindAll
in interfaceSocketBinder
- Specified by:
unbindAll
in classNIOTransport
-
connect
public GrizzlyFuture<Connection> connect() throws IOException
Creates non-connected UDPConnection
.- Returns:
- non-connected UDP
Connection
. - Throws:
IOException
-
connect
public GrizzlyFuture<Connection> connect(String host, int port) throws IOException
Creates, initializes and connects socket to the specific remote host and port and returnsConnection
, representing socket.- Specified by:
connect
in interfaceSocketConnectorHandler
- Parameters:
host
- remote host to connect to.port
- remote port to connect to.- Returns:
GrizzlyFuture
of connect operation, which could be used to get resultingConnection
.- Throws:
IOException
-
connect
public GrizzlyFuture<Connection> connect(SocketAddress remoteAddress)
Creates, initializes and connects socket to the specificSocketAddress
and returnsConnection
, representing socket.- Specified by:
connect
in interfaceConnectorHandler<SocketAddress>
- Parameters:
remoteAddress
- remote address to connect to.- Returns:
GrizzlyFuture
of connect operation, which could be used to get resultingConnection
.- Throws:
IOException
-
connect
public void connect(SocketAddress remoteAddress, CompletionHandler<Connection> completionHandler)
Creates, initializes and connects socket to the specificSocketAddress
and returnsConnection
, representing socket.- Specified by:
connect
in interfaceConnectorHandler<SocketAddress>
- Parameters:
remoteAddress
- remote address to connect to.completionHandler
-CompletionHandler
.
-
connect
public GrizzlyFuture<Connection> connect(SocketAddress remoteAddress, SocketAddress localAddress)
Creates, initializes socket, binds it to the specific local and remoteSocketAddress
and returnsConnection
, representing socket.- Specified by:
connect
in interfaceConnectorHandler<SocketAddress>
- Parameters:
remoteAddress
- remote address to connect to.localAddress
- local address to bind socket to.- Returns:
GrizzlyFuture
of connect operation, which could be used to get resultingConnection
.
-
connect
public void connect(SocketAddress remoteAddress, SocketAddress localAddress, CompletionHandler<Connection> completionHandler)
Creates, initializes socket, binds it to the specific local and remoteSocketAddress
and returnsConnection
, representing socket.- Specified by:
connect
in interfaceConnectorHandler<SocketAddress>
- Parameters:
remoteAddress
- remote address to connect to.localAddress
- local address to bind socket to.completionHandler
-CompletionHandler
.
-
closeConnection
protected void closeConnection(Connection connection) throws IOException
Description copied from class:AbstractTransport
Close the connection, managed by Transport- Specified by:
closeConnection
in classNIOTransport
- Parameters:
connection
-NIOConnection
to close- Throws:
IOException
- not used
-
configureStandalone
public void configureStandalone(boolean isStandalone)
- Specified by:
configureStandalone
in interfaceTransport
-
getTransportFilter
public Filter getTransportFilter()
Description copied from interface:FilterChainEnabledTransport
Get transportFilter
, which is aware ofTransport
specifics; knows how to read/write from/toTransport
specificConnection
streams. EachTransport
should provide transportFilter
implementation.- Specified by:
getTransportFilter
in interfaceFilterChainEnabledTransport
- Returns:
- transport
Filter
, which is aware ofTransport
specifics; knows how to read/write from/toTransport
specificConnection
s.
-
getAsyncQueueIO
public AsyncQueueIO getAsyncQueueIO()
Description copied from interface:AsyncQueueEnabledTransport
Get asynchronous queue implementation.- Specified by:
getAsyncQueueIO
in interfaceAsyncQueueEnabledTransport
- Returns:
- asynchronous queue implementation.
-
getTemporarySelectorIO
public TemporarySelectorIO getTemporarySelectorIO()
- Specified by:
getTemporarySelectorIO
in interfaceTemporarySelectorsEnabledTransport
- Overrides:
getTemporarySelectorIO
in classNIOTransport
-
fireIOEvent
public void fireIOEvent(IOEvent ioEvent, Connection connection, IOEventLifeCycleListener listener)
Description copied from interface:Transport
Fires specificIOEvent
on theConnection
- Specified by:
fireIOEvent
in interfaceTransport
- Parameters:
ioEvent
- I/O eventconnection
-Connection
, on which we fire the event.listener
- I/O event life-cycle listener.
-
getReader
public Reader getReader(Connection connection)
Get theReader
to read data from theConnection
. The Transport may decide to return blocking or non-blockingReader
depending on theConnection
settings.- Specified by:
getReader
in interfaceTransport
- Parameters:
connection
-Connection
.- Returns:
Reader
.
-
getReader
public Reader getReader(boolean isBlocking)
Get theReader
implementation, depending on the requested mode.
-
getWriter
public Writer getWriter(Connection connection)
Get theWriter
to write data to theConnection
. The Transport may decide to return blocking or non-blockingWriter
depending on theConnection
settings.- Specified by:
getWriter
in interfaceTransport
- Parameters:
connection
-Connection
.- Returns:
Writer
.
-
getWriter
public Writer getWriter(boolean isBlocking)
Get theWriter
implementation, depending on the requested mode.
-
read
public int read(UDPNIOConnection connection, Buffer buffer) throws IOException
- Throws:
IOException
-
read
public int read(UDPNIOConnection connection, Buffer buffer, ReadResult<Buffer,SocketAddress> currentResult) throws IOException
- Throws:
IOException
-
write
public long write(UDPNIOConnection connection, SocketAddress dstAddress, WritableMessage message) throws IOException
- Throws:
IOException
-
write
public long write(UDPNIOConnection connection, SocketAddress dstAddress, WritableMessage message, WriteResult<WritableMessage,SocketAddress> currentResult) throws IOException
- Throws:
IOException
-
getChannelConfigurator
public ChannelConfigurator getChannelConfigurator()
- Overrides:
getChannelConfigurator
in classNIOTransport
- Returns:
- the configurator responsible for initial
SelectableChannel
configuration
-
createJmxManagementObject
protected Object createJmxManagementObject()
Create the Transport JMX management object.- Specified by:
createJmxManagementObject
in classAbstractTransport
- Returns:
- the Transport JMX management object.
-
-