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
UDP NIO transport implementation
- Author:
- Alexey Stashok
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classprotected classTransport defaultUDPNIOConnectorHandler.Nested classes/interfaces inherited from interface org.glassfish.grizzly.Transport
Transport.State -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final AsyncQueueIO<SocketAddress>Transport AsyncQueueIOstatic final ChannelConfiguratorDefaultChannelConfiguratorused to configure client and server side channels.protected final UDPNIOTransport.RegisterChannelCompletionHandlerprotected final Collection<UDPNIOServerConnection>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, temporarySelectorIOFields 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, writeTimeoutFields inherited from interface org.glassfish.grizzly.Transport
DEFAULT_READ_BUFFER_SIZE, DEFAULT_READ_TIMEOUT, DEFAULT_WRITE_BUFFER_SIZE, DEFAULT_WRITE_TIMEOUT -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddShutdownListener(GracefulShutdownListener shutdownListener) Adds aGracefulShutdownListenerwhich will be called whenTransport.shutdown()is called to enable graceful shutdown of transports.bind(int port) Binds Transport to the specific port on localhost.Binds Transport to the specific host and port.Binds Transport to the specific host and port.Binds Transport to the specific host, and port within aPortRange.Binds Transport to the specific host, and port within aPortRange.bind(SocketAddress socketAddress) Binds Transport to the specific SocketAddress.bind(SocketAddress socketAddress, int backlog) Binds Transport to the specific SocketAddress.Connection<?>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) connect()Creates non-connected UDPConnection.Creates, initializes and connects socket to the specific remote host and port and returnsConnection, representing socket.connect(SocketAddress remoteAddress) Creates, initializes and connects socket to the specificSocketAddressand returnsConnection, representing socket.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 ObjectCreate the Transport JMX management object.protected TemporarySelectorIOvoidfireIOEvent(IOEvent ioEvent, Connection connection, IOEventLifeCycleListener listener) Fires specificIOEventon theConnectionGet asynchronous queue implementation.getReader(boolean isBlocking) Get theReaderimplementation, depending on the requested mode.getReader(Connection connection) Get theReaderto read data from theConnection.Get transportFilter, which is aware ofTransportspecifics; knows how to read/write from/toTransportspecificConnectionstreams.getWriter(boolean isBlocking) Get theWriterimplementation, depending on the requested mode.getWriter(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.voidUnbinds 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, stopSelectorRunnersMethods 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 Details
-
DEFAULT_CHANNEL_CONFIGURATOR
DefaultChannelConfiguratorused to configure client and server side channels. -
serverConnections
The Server connections. -
asyncQueueIO
Transport AsyncQueueIO -
registerChannelCompletionHandler
-
-
Constructor Details
-
UDPNIOTransport
public UDPNIOTransport() -
UDPNIOTransport
-
-
Method Details
-
createTemporarySelectorIO
- Specified by:
createTemporarySelectorIOin classNIOTransport
-
listen
protected void listen()- Specified by:
listenin classNIOTransport
-
addShutdownListener
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
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
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
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
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
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
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
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
Creates non-connected UDPConnection.- Returns:
- non-connected UDP
Connection. - Throws:
IOException
-
connect
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
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
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
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
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
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
Description copied from interface:AsyncQueueEnabledTransportGet asynchronous queue implementation.- Specified by:
getAsyncQueueIOin interfaceAsyncQueueEnabledTransport- Returns:
- asynchronous queue implementation.
-
getTemporarySelectorIO
- Specified by:
getTemporarySelectorIOin interfaceTemporarySelectorsEnabledTransport- Overrides:
getTemporarySelectorIOin classNIOTransport
-
fireIOEvent
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
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
Get theReaderimplementation, depending on the requested mode. -
getWriter
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
Get theWriterimplementation, depending on the requested mode. -
read
- 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
- Overrides:
getChannelConfiguratorin classNIOTransport- Returns:
- the configurator responsible for initial
SelectableChannelconfiguration
-
createJmxManagementObject
Create the Transport JMX management object.- Specified by:
createJmxManagementObjectin classAbstractTransport- Returns:
- the Transport JMX management object.
-