java.lang.Object
org.glassfish.grizzly.AbstractTransport
org.glassfish.grizzly.nio.NIOTransport
- All Implemented Interfaces:
AsyncQueueEnabledTransport
,ConnectorHandler<SocketAddress>
,MonitoringAware<TransportProbe>
,TemporarySelectorsEnabledTransport
,SocketBinder
,SocketConnectorHandler
,Transport
- Direct Known Subclasses:
TCPNIOTransport
,UDPNIOTransport
public abstract class NIOTransport
extends AbstractTransport
implements SocketBinder, SocketConnectorHandler, TemporarySelectorsEnabledTransport, AsyncQueueEnabledTransport
- Author:
- oleksiys
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.glassfish.grizzly.Transport
Transport.State
-
Field Summary
Modifier and TypeFieldDescriptionprotected ChannelConfigurator
static final int
static final int
static final boolean
static final boolean
static final int
static final int
protected NIOChannelDistributor
protected SelectionKeyHandler
protected SelectorHandler
protected SelectorProvider
protected SelectorRunner[]
protected FutureImpl<Transport>
Future to control graceful shutdown statusprotected Set<GracefulShutdownListener>
protected ExecutorService
ExecutorService hosting shutdown listener threads.protected final 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
-
Method Summary
Modifier and TypeMethodDescriptionboolean
addShutdownListener
(GracefulShutdownListener shutdownListener) Adds aGracefulShutdownListener
which will be called whenTransport.shutdown()
is called to enable graceful shutdown of transports.protected abstract void
closeConnection
(Connection connection) Close the connection, managed by Transportprotected void
configureNIOConnection
(NIOConnection connection) protected ExecutorService
protected abstract TemporarySelectorIO
protected void
int
int
protected int
Get theSelectorProvider
to be used by this transport.protected SelectorRunner[]
int
int
boolean
Returns true, if NIOTransport is configured to useAsyncQueueWriter
, optimized to be used in connection multiplexing mode, or false otherwise.boolean
protected abstract void
listen()
protected static void
notifyProbesError
(NIOTransport transport, Throwable error) Notify registeredTransportProbe
s about the error.protected static void
notifyProbesPause
(NIOTransport transport) Notify registeredTransportProbe
s about the pause event.protected static void
notifyProbesResume
(NIOTransport transport) Notify registeredTransportProbe
s about the resume event.protected static void
notifyProbesStart
(NIOTransport transport) Notify registeredTransportProbe
s about the start event.protected static void
notifyProbesStop
(NIOTransport transport) Notify registeredTransportProbe
s about the stop event.void
notifyTransportError
(Throwable error) Method gets invoked, when error occur during the Transport lifecycle.void
pause()
Pause UDPNIOTransport, so I/O events coming on itsUDPNIOConnection
s will not be processed.void
resume()
Resume UDPNIOTransport, which has been paused before usingpause()
.void
setChannelConfigurator
(ChannelConfigurator channelConfigurator) Sets the configurator responsible for initialSelectableChannel
configuration.void
setClientSocketSoTimeout
(int socketTimeout) void
setConnectionTimeout
(int connectionTimeout) void
setNIOChannelDistributor
(NIOChannelDistributor nioChannelDistributor) void
setOptimizedForMultiplexing
(boolean optimizedForMultiplexing) Configures NIOTransport to be optimized for specific for the connection multiplexing usecase, when different threads will try to write data simultaneously.void
setReuseAddress
(boolean reuseAddress) void
setSelectionKeyHandler
(SelectionKeyHandler selectionKeyHandler) void
setSelectorHandler
(SelectorHandler selectorHandler) void
setSelectorProvider
(SelectorProvider selectorProvider) Set theSelectorProvider
to be used by this transport.void
setSelectorRunnersCount
(int selectorRunnersCount) Sets the number ofSelectorRunner
s used for handling NIO events.void
setServerSocketSoTimeout
(int serverSocketSoTimeout) shutdown()
Gracefully stops the transport accepting new connections and allows existing work to complete before finalizing the shutdown.Gracefully stops the transport accepting new connections and allows existing work to complete before finalizing the shutdown.void
Forcibly stops the transport and closes all connections.void
start()
Start TCPNIOTransport.protected void
protected void
abstract void
Unbinds all boundTransport
connections.Methods inherited from class org.glassfish.grizzly.AbstractTransport
configureBlocking, createJmxManagementObject, 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
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.glassfish.grizzly.asyncqueue.AsyncQueueEnabledTransport
getAsyncQueueIO
Methods inherited from interface org.glassfish.grizzly.ConnectorHandler
connect, connect, connect, connect
Methods inherited from interface org.glassfish.grizzly.SocketBinder
bind, bind, bind, bind, bind, bind, bind, bindToInherited, unbind
Methods inherited from interface org.glassfish.grizzly.SocketConnectorHandler
connect
Methods inherited from interface org.glassfish.grizzly.Transport
configureStandalone, fireIOEvent, getReader, getReader, getWriter, getWriter
-
Field Details
-
DEFAULT_SERVER_SOCKET_SO_TIMEOUT
public static final int DEFAULT_SERVER_SOCKET_SO_TIMEOUT- See Also:
-
DEFAULT_REUSE_ADDRESS
public static final boolean DEFAULT_REUSE_ADDRESS- See Also:
-
DEFAULT_CLIENT_SOCKET_SO_TIMEOUT
public static final int DEFAULT_CLIENT_SOCKET_SO_TIMEOUT- See Also:
-
DEFAULT_CONNECTION_TIMEOUT
public static final int DEFAULT_CONNECTION_TIMEOUT- See Also:
-
DEFAULT_SELECTOR_RUNNER_COUNT
public static final int DEFAULT_SELECTOR_RUNNER_COUNT- See Also:
-
DEFAULT_OPTIMIZED_FOR_MULTIPLEXING
public static final boolean DEFAULT_OPTIMIZED_FOR_MULTIPLEXING- See Also:
-
selectorHandler
-
selectionKeyHandler
-
channelConfigurator
-
selectorRunners
-
nioChannelDistributor
-
selectorProvider
-
temporarySelectorIO
-
shutdownListeners
-
shutdownFuture
Future to control graceful shutdown status -
shutdownService
ExecutorService hosting shutdown listener threads.
-
-
Constructor Details
-
NIOTransport
-
-
Method Details
-
unbindAll
public abstract void unbindAll()Description copied from interface:SocketBinder
Unbinds all boundTransport
connections.- Specified by:
unbindAll
in interfaceSocketBinder
-
addShutdownListener
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
- 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.
-
getTemporarySelectorIO
- Specified by:
getTemporarySelectorIO
in interfaceTemporarySelectorsEnabledTransport
-
getSelectionKeyHandler
-
setSelectionKeyHandler
-
getSelectorHandler
-
setSelectorHandler
-
getChannelConfigurator
- Returns:
- the configurator responsible for initial
SelectableChannel
configuration
-
setChannelConfigurator
Sets the configurator responsible for initialSelectableChannel
configuration.- Parameters:
channelConfigurator
-ChannelConfigurator
-
getSelectorRunnersCount
public int getSelectorRunnersCount()- Returns:
- the number of
SelectorRunner
s used for handling NIO events
-
setSelectorRunnersCount
public void setSelectorRunnersCount(int selectorRunnersCount) Sets the number ofSelectorRunner
s used for handling NIO events.- Parameters:
selectorRunnersCount
-
-
getSelectorProvider
Get theSelectorProvider
to be used by this transport.- Returns:
- the
SelectorProvider
to be used by this transport.
-
setSelectorProvider
Set theSelectorProvider
to be used by this transport.- Parameters:
selectorProvider
- theSelectorProvider
.
-
isOptimizedForMultiplexing
public boolean isOptimizedForMultiplexing()Returns true, if NIOTransport is configured to useAsyncQueueWriter
, optimized to be used in connection multiplexing mode, or false otherwise.- Returns:
- true, if NIOTransport is configured to use
AsyncQueueWriter
, optimized to be used in connection multiplexing mode, or false otherwise.
-
setOptimizedForMultiplexing
public void setOptimizedForMultiplexing(boolean optimizedForMultiplexing) Configures NIOTransport to be optimized for specific for the connection multiplexing usecase, when different threads will try to write data simultaneously. -
startSelectorRunners
- Throws:
IOException
-
stopSelectorRunners
protected void stopSelectorRunners() -
getNIOChannelDistributor
-
setNIOChannelDistributor
-
notifyTransportError
Method gets invoked, when error occur during the Transport lifecycle.- Specified by:
notifyTransportError
in interfaceTransport
- Parameters:
error
-Throwable
.
-
getSelectorRunners
-
notifyProbesError
Notify registeredTransportProbe
s about the error.- Parameters:
transport
- the Transport event occurred on.
-
notifyProbesStart
Notify registeredTransportProbe
s about the start event.- Parameters:
transport
- the Transport event occurred on.
-
notifyProbesStop
Notify registeredTransportProbe
s about the stop event.- Parameters:
transport
- the Transport event occurred on.
-
notifyProbesPause
Notify registeredTransportProbe
s about the pause event.- Parameters:
transport
- the Transport event occurred on.
-
notifyProbesResume
Notify registeredTransportProbe
s about the resume event.- Parameters:
transport
- the Transport event occurred on.
-
start
Start TCPNIOTransport. The transport will be started only if its current state isTransport.State.STOPPED
, otherwise the call will be ignored without exception thrown and the transport state will remain the same as it was before the method call.- Specified by:
start
in interfaceTransport
- Throws:
IOException
- if an attempt was made to actually start which failed
-
shutdown
Description copied from interface:Transport
Gracefully stops the transport accepting new connections and allows existing work to complete before finalizing the shutdown. This method will wait indefinitely for all interested parties to signal it is safe to terminate the transport. InvokeTransport.shutdownNow()
to terminate the transport if the graceful shutdown is taking too long.- Specified by:
shutdown
in interfaceTransport
- Returns:
- a
GrizzlyFuture
which will return the stopped transport. - See Also:
-
shutdown
Gracefully stops the transport accepting new connections and allows existing work to complete before finalizing the shutdown. This method will wait for the specified time for all interested parties to signal it is safe to terminate the transport. If the timeout is exceeded, the transport will be terminated forcefully.- Specified by:
shutdown
in interfaceTransport
- Parameters:
gracePeriod
- the grace period for a graceful shutdown before the transport is forcibly terminated. If gracePeriod is zero or less, then there is no time limit for the shutdown.timeUnit
- theTimeUnit
of the specified grace period.- Returns:
- a
GrizzlyFuture
which will return the stopped transport.
-
shutdownNow
Forcibly stops the transport and closes all connections.- Specified by:
shutdownNow
in interfaceTransport
- Throws:
IOException
- if there was an error shutting down- See Also:
-
closeConnection
Description copied from class:AbstractTransport
Close the connection, managed by Transport- Specified by:
closeConnection
in classAbstractTransport
- Parameters:
connection
-NIOConnection
to close- Throws:
IOException
- not used
-
createTemporarySelectorIO
-
listen
protected abstract void listen() -
getDefaultSelectorRunnersCount
protected int getDefaultSelectorRunnersCount() -
finalizeShutdown
protected void finalizeShutdown() -
pause
public void pause()Pause UDPNIOTransport, so I/O events coming on itsUDPNIOConnection
s will not be processed. Useresume()
in order to resume UDPNIOTransport processing. The transport will be paused only if its current state isTransport.State.STARTED
, otherwise the call will be ignored without exception thrown and the transport state will remain the same as it was before the method call. -
resume
public void resume()Resume UDPNIOTransport, which has been paused before usingpause()
. The transport will be resumed only if its current state isTransport.State.PAUSED
, otherwise the call will be ignored without exception thrown and the transport state will remain the same as it was before the method call. -
configureNIOConnection
-
isReuseAddress
public boolean isReuseAddress() -
setReuseAddress
public void setReuseAddress(boolean reuseAddress) -
getClientSocketSoTimeout
public int getClientSocketSoTimeout() -
setClientSocketSoTimeout
public void setClientSocketSoTimeout(int socketTimeout) -
getConnectionTimeout
public int getConnectionTimeout() -
setConnectionTimeout
public void setConnectionTimeout(int connectionTimeout) -
getServerSocketSoTimeout
public int getServerSocketSoTimeout() -
setServerSocketSoTimeout
public void setServerSocketSoTimeout(int serverSocketSoTimeout) -
createShutdownExecutorService
-