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
FieldsModifier and TypeFieldDescriptionprotected ChannelConfiguratorstatic final intstatic final intstatic final booleanstatic final booleanstatic final intstatic final intprotected NIOChannelDistributorprotected SelectionKeyHandlerprotected SelectorHandlerprotected SelectorProviderprotected SelectorRunner[]protected FutureImpl<Transport>Future to control graceful shutdown statusprotected Set<GracefulShutdownListener>protected ExecutorServiceExecutorService hosting shutdown listener threads.protected final 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.protected abstract voidcloseConnection(Connection connection) Close the connection, managed by Transportprotected voidconfigureNIOConnection(NIOConnection connection) protected ExecutorServiceprotected abstract TemporarySelectorIOprotected voidintintprotected intGet theSelectorProviderto be used by this transport.protected SelectorRunner[]intintbooleanReturns true, if NIOTransport is configured to useAsyncQueueWriter, optimized to be used in connection multiplexing mode, or false otherwise.booleanprotected abstract voidlisten()protected static voidnotifyProbesError(NIOTransport transport, Throwable error) Notify registeredTransportProbes about the error.protected static voidnotifyProbesPause(NIOTransport transport) Notify registeredTransportProbes about the pause event.protected static voidnotifyProbesResume(NIOTransport transport) Notify registeredTransportProbes about the resume event.protected static voidnotifyProbesStart(NIOTransport transport) Notify registeredTransportProbes about the start event.protected static voidnotifyProbesStop(NIOTransport transport) Notify registeredTransportProbes about the stop event.voidnotifyTransportError(Throwable error) Method gets invoked, when error occur during the Transport lifecycle.voidpause()Pause UDPNIOTransport, so I/O events coming on itsUDPNIOConnections will not be processed.voidresume()Resume UDPNIOTransport, which has been paused before usingpause().voidsetChannelConfigurator(ChannelConfigurator channelConfigurator) Sets the configurator responsible for initialSelectableChannelconfiguration.voidsetClientSocketSoTimeout(int socketTimeout) voidsetConnectionTimeout(int connectionTimeout) voidsetNIOChannelDistributor(NIOChannelDistributor nioChannelDistributor) voidsetOptimizedForMultiplexing(boolean optimizedForMultiplexing) Configures NIOTransport to be optimized for specific for the connection multiplexing usecase, when different threads will try to write data simultaneously.voidsetReuseAddress(boolean reuseAddress) voidsetSelectionKeyHandler(SelectionKeyHandler selectionKeyHandler) voidsetSelectorHandler(SelectorHandler selectorHandler) voidsetSelectorProvider(SelectorProvider selectorProvider) Set theSelectorProviderto be used by this transport.voidsetSelectorRunnersCount(int selectorRunnersCount) Sets the number ofSelectorRunners used for handling NIO events.voidsetServerSocketSoTimeout(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.voidForcibly stops the transport and closes all connections.voidstart()Start TCPNIOTransport.protected voidprotected voidabstract voidUnbinds all boundTransportconnections.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, stopMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.glassfish.grizzly.asyncqueue.AsyncQueueEnabledTransport
getAsyncQueueIOMethods inherited from interface org.glassfish.grizzly.ConnectorHandler
connect, connect, connect, connectMethods inherited from interface org.glassfish.grizzly.SocketBinder
bind, bind, bind, bind, bind, bind, bind, bindToInherited, unbindMethods inherited from interface org.glassfish.grizzly.SocketConnectorHandler
connectMethods 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:SocketBinderUnbinds all boundTransportconnections.- Specified by:
unbindAllin interfaceSocketBinder
-
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- 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.
-
getTemporarySelectorIO
- Specified by:
getTemporarySelectorIOin interfaceTemporarySelectorsEnabledTransport
-
getSelectionKeyHandler
-
setSelectionKeyHandler
-
getSelectorHandler
-
setSelectorHandler
-
getChannelConfigurator
- Returns:
- the configurator responsible for initial
SelectableChannelconfiguration
-
setChannelConfigurator
Sets the configurator responsible for initialSelectableChannelconfiguration.- Parameters:
channelConfigurator-ChannelConfigurator
-
getSelectorRunnersCount
public int getSelectorRunnersCount()- Returns:
- the number of
SelectorRunners used for handling NIO events
-
setSelectorRunnersCount
public void setSelectorRunnersCount(int selectorRunnersCount) Sets the number ofSelectorRunners used for handling NIO events.- Parameters:
selectorRunnersCount-
-
getSelectorProvider
Get theSelectorProviderto be used by this transport.- Returns:
- the
SelectorProviderto be used by this transport.
-
setSelectorProvider
Set theSelectorProviderto 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:
notifyTransportErrorin interfaceTransport- Parameters:
error-Throwable.
-
getSelectorRunners
-
notifyProbesError
Notify registeredTransportProbes about the error.- Parameters:
transport- the Transport event occurred on.
-
notifyProbesStart
Notify registeredTransportProbes about the start event.- Parameters:
transport- the Transport event occurred on.
-
notifyProbesStop
Notify registeredTransportProbes about the stop event.- Parameters:
transport- the Transport event occurred on.
-
notifyProbesPause
Notify registeredTransportProbes about the pause event.- Parameters:
transport- the Transport event occurred on.
-
notifyProbesResume
Notify registeredTransportProbes 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:
startin interfaceTransport- Throws:
IOException- if an attempt was made to actually start which failed
-
shutdown
Description copied from interface:TransportGracefully 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:
shutdownin interfaceTransport- Returns:
- a
GrizzlyFuturewhich 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:
shutdownin 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- theTimeUnitof the specified grace period.- Returns:
- a
GrizzlyFuturewhich will return the stopped transport.
-
shutdownNow
Forcibly stops the transport and closes all connections.- Specified by:
shutdownNowin interfaceTransport- Throws:
IOException- if there was an error shutting down- See Also:
-
closeConnection
Description copied from class:AbstractTransportClose the connection, managed by Transport- Specified by:
closeConnectionin classAbstractTransport- Parameters:
connection-NIOConnectionto 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 itsUDPNIOConnections 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
-