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 classUDPNIOTransport.RegisterChannelCompletionHandlerprotected classUDPNIOTransport.TransportConnectorHandlerTransport defaultUDPNIOConnectorHandler.-
Nested classes/interfaces inherited from interface org.glassfish.grizzly.Transport
Transport.State
-
-
Field Summary
Fields Modifier and Type Field Description protected AsyncQueueIO<SocketAddress>asyncQueueIOTransport AsyncQueueIOstatic ChannelConfiguratorDEFAULT_CHANNEL_CONFIGURATORDefaultChannelConfiguratorused to configure client and server side channels.protected UDPNIOTransport.RegisterChannelCompletionHandlerregisterChannelCompletionHandlerprotected Collection<UDPNIOServerConnection>serverConnectionsThe 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 booleanaddShutdownListener(GracefulShutdownListener shutdownListener)Adds aGracefulShutdownListenerwhich will be called whenTransport.shutdown()is called to enable graceful shutdown of transports.UDPNIOServerConnectionbind(int port)Binds Transport to the specific port on localhost.UDPNIOServerConnectionbind(String host, int port)Binds Transport to the specific host and port.UDPNIOServerConnectionbind(String host, int port, int backlog)Binds Transport to the specific host and port.UDPNIOServerConnectionbind(String host, PortRange portRange, boolean randomStartPort, int backlog)Binds Transport to the specific host, and port within aPortRange.UDPNIOServerConnectionbind(String host, PortRange portRange, int backlog)Binds Transport to the specific host, and port within aPortRange.UDPNIOServerConnectionbind(SocketAddress socketAddress)Binds Transport to the specific SocketAddress.UDPNIOServerConnectionbind(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 voidcloseConnection(Connection connection)Close the connection, managed by TransportvoidconfigureStandalone(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 specificSocketAddressand returnsConnection, representing socket.GrizzlyFuture<Connection>connect(SocketAddress remoteAddress, SocketAddress localAddress)Creates, initializes socket, binds it to the specific local and remoteSocketAddressand returnsConnection, representing socket.voidconnect(SocketAddress remoteAddress, SocketAddress localAddress, CompletionHandler<Connection> completionHandler)Creates, initializes socket, binds it to the specific local and remoteSocketAddressand returnsConnection, representing socket.voidconnect(SocketAddress remoteAddress, CompletionHandler<Connection> completionHandler)Creates, initializes and connects socket to the specificSocketAddressand returnsConnection, representing socket.protected ObjectcreateJmxManagementObject()Create the Transport JMX management object.protected TemporarySelectorIOcreateTemporarySelectorIO()voidfireIOEvent(IOEvent ioEvent, Connection connection, IOEventLifeCycleListener listener)Fires specificIOEventon theConnectionAsyncQueueIOgetAsyncQueueIO()Get asynchronous queue implementation.ChannelConfiguratorgetChannelConfigurator()ReadergetReader(boolean isBlocking)Get theReaderimplementation, depending on the requested mode.ReadergetReader(Connection connection)Get theReaderto read data from theConnection.TemporarySelectorIOgetTemporarySelectorIO()FiltergetTransportFilter()Get transportFilter, which is aware ofTransportspecifics; knows how to read/write from/toTransportspecificConnectionstreams.WritergetWriter(boolean isBlocking)Get theWriterimplementation, depending on the requested mode.WritergetWriter(Connection connection)Get theWriterto write data to theConnection.protected voidlisten()intread(UDPNIOConnection connection, Buffer buffer)intread(UDPNIOConnection connection, Buffer buffer, ReadResult<Buffer,SocketAddress> currentResult)voidunbind(Connection connection)Unbinds boundTransportconnection.voidunbindAll()Unbinds all boundTransportconnections.longwrite(UDPNIOConnection connection, SocketAddress dstAddress, WritableMessage message)longwrite(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
DefaultChannelConfiguratorused 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:
createTemporarySelectorIOin classNIOTransport
-
listen
protected void listen()
- Specified by:
listenin classNIOTransport
-
addShutdownListener
public boolean addShutdownListener(GracefulShutdownListener shutdownListener)
Description copied from interface:TransportAdds aGracefulShutdownListenerwhich 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:
addShutdownListenerin interfaceTransport- Overrides:
addShutdownListenerin classNIOTransport- Parameters:
shutdownListener- theGracefulShutdownListener- Returns:
trueif the listener was successfully registered, otherwisefalse. When this method returnsfalseit 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:
bindin 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:
bindin 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:
bindin 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:
bindin 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:
bindin 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:SocketBinderBinds the Transport to the channel inherited from the entity that created this Java virtual machine.- Specified by:
bindToInheritedin 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:
bindin 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:
bindin 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 boundTransportconnection.- Specified by:
unbindin interfaceSocketBinder- Parameters:
connection-Connection
-
unbindAll
public void unbindAll()
Description copied from interface:SocketBinderUnbinds all boundTransportconnections.- Specified by:
unbindAllin interfaceSocketBinder- Specified by:
unbindAllin 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:
connectin interfaceSocketConnectorHandler- Parameters:
host- remote host to connect to.port- remote port to connect to.- Returns:
GrizzlyFutureof 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 specificSocketAddressand returnsConnection, representing socket.- Specified by:
connectin interfaceConnectorHandler<SocketAddress>- Parameters:
remoteAddress- remote address to connect to.- Returns:
GrizzlyFutureof 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 specificSocketAddressand returnsConnection, representing socket.- Specified by:
connectin 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 remoteSocketAddressand returnsConnection, representing socket.- Specified by:
connectin interfaceConnectorHandler<SocketAddress>- Parameters:
remoteAddress- remote address to connect to.localAddress- local address to bind socket to.- Returns:
GrizzlyFutureof 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 remoteSocketAddressand returnsConnection, representing socket.- Specified by:
connectin 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:AbstractTransportClose the connection, managed by Transport- Specified by:
closeConnectionin classNIOTransport- Parameters:
connection-NIOConnectionto close- Throws:
IOException- not used
-
configureStandalone
public void configureStandalone(boolean isStandalone)
- Specified by:
configureStandalonein interfaceTransport
-
getTransportFilter
public Filter getTransportFilter()
Description copied from interface:FilterChainEnabledTransportGet transportFilter, which is aware ofTransportspecifics; knows how to read/write from/toTransportspecificConnectionstreams. EachTransportshould provide transportFilterimplementation.- Specified by:
getTransportFilterin interfaceFilterChainEnabledTransport- Returns:
- transport
Filter, which is aware ofTransportspecifics; knows how to read/write from/toTransportspecificConnections.
-
getAsyncQueueIO
public AsyncQueueIO getAsyncQueueIO()
Description copied from interface:AsyncQueueEnabledTransportGet asynchronous queue implementation.- Specified by:
getAsyncQueueIOin interfaceAsyncQueueEnabledTransport- Returns:
- asynchronous queue implementation.
-
getTemporarySelectorIO
public TemporarySelectorIO getTemporarySelectorIO()
- Specified by:
getTemporarySelectorIOin interfaceTemporarySelectorsEnabledTransport- Overrides:
getTemporarySelectorIOin classNIOTransport
-
fireIOEvent
public void fireIOEvent(IOEvent ioEvent, Connection connection, IOEventLifeCycleListener listener)
Description copied from interface:TransportFires specificIOEventon theConnection- Specified by:
fireIOEventin 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 theReaderto read data from theConnection. The Transport may decide to return blocking or non-blockingReaderdepending on theConnectionsettings.- Specified by:
getReaderin interfaceTransport- Parameters:
connection-Connection.- Returns:
Reader.
-
getReader
public Reader getReader(boolean isBlocking)
Get theReaderimplementation, depending on the requested mode.
-
getWriter
public Writer getWriter(Connection connection)
Get theWriterto write data to theConnection. The Transport may decide to return blocking or non-blockingWriterdepending on theConnectionsettings.- Specified by:
getWriterin interfaceTransport- Parameters:
connection-Connection.- Returns:
Writer.
-
getWriter
public Writer getWriter(boolean isBlocking)
Get theWriterimplementation, 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:
getChannelConfiguratorin classNIOTransport- Returns:
- the configurator responsible for initial
SelectableChannelconfiguration
-
createJmxManagementObject
protected Object createJmxManagementObject()
Create the Transport JMX management object.- Specified by:
createJmxManagementObjectin classAbstractTransport- Returns:
- the Transport JMX management object.
-
-