Top Fields Constructors Methods
org.glassfish.grizzly.nio

public abstract Class NIOTransport

extends AbstractTransport
implements SocketBinder, SocketConnectorHandler, TemporarySelectorsEnabledTransport, AsyncQueueEnabledTransport
Class Inheritance
All Implemented Interfaces
org.glassfish.grizzly.asyncqueue.AsyncQueueEnabledTransport, org.glassfish.grizzly.nio.tmpselectors.TemporarySelectorsEnabledTransport, org.glassfish.grizzly.SocketConnectorHandler, org.glassfish.grizzly.ConnectorHandler, org.glassfish.grizzly.SocketBinder
Known Direct Subclasses
org.glassfish.grizzly.nio.transport.TCPNIOTransport, org.glassfish.grizzly.nio.transport.UDPNIOTransport
Imports
java.io.IOException, java.net.Socket, .StandardSocketOptions, java.nio.channels.SelectableChannel, java.nio.channels.spi.SelectorProvider, java.util.HashSet, .Set, java.util.concurrent.ExecutorService, .Executors, .ThreadFactory, .TimeUnit, java.util.concurrent.locks.Lock, java.util.function.Supplier, java.util.logging.Level, .Logger, org.glassfish.grizzly.AbstractTransport, .Connection, .GracefulShutdownListener, .Grizzly, .GrizzlyFuture, .SocketBinder, .SocketConnectorHandler, .StandaloneProcessor, .Transport, .TransportProbe, org.glassfish.grizzly.asyncqueue.AsyncQueueEnabledTransport, org.glassfish.grizzly.impl.FutureImpl, org.glassfish.grizzly.localization.LogMessages, org.glassfish.grizzly.nio.tmpselectors.TemporarySelectorIO, .TemporarySelectorPool, .TemporarySelectorsEnabledTransport, org.glassfish.grizzly.strategies.SameThreadIOStrategy, .WorkerThreadIOStrategy, org.glassfish.grizzly.threadpool.AbstractThreadPool, .GrizzlyExecutorService, .ThreadPoolConfig, org.glassfish.grizzly.utils.Futures, .Holder

Author
oleksiys

Field Summary

Modifier and TypeField and Description
protected ChannelConfigurator
pack-priv int
clientSocketSoTimeout

The socket time out

pack-priv int
connectionTimeout

Default channel connection timeout

public static final int
public static final int
public static final boolean
public static final boolean
public static final boolean
public static final int
public static final int
private static final Logger
protected NIOChannelDistributor
private boolean
pack-priv boolean
reuseAddress

The socket reuseAddress

pack-priv boolean
reusePort

The socket reusePort

private static final Holder<Boolean>
protected SelectionKeyHandler
protected SelectorHandler
protected SelectorProvider
protected SelectorRunner[]
private int
pack-priv int
serverSocketSoTimeout

The server socket time out

protected FutureImpl<Transport>
shutdownFuture

Future to control graceful shutdown status

protected Set<GracefulShutdownListener>
protected ExecutorService
shutdownService

ExecutorService hosting shutdown listener threads.

protected final TemporarySelectorIO
Inherited from org.glassfish.grizzly.AbstractTransport:
attributeBuilderconnectionMonitoringConfigisBlockingisStandalonekernelPoolkernelPoolConfigmanagedWorkerPoolmemoryManagernameprocessorprocessorSelectorreadBufferSizereadTimeoutstatestrategythreadPoolMonitoringConfigtransportMonitoringConfigworkerPoolConfigworkerThreadPoolwriteBufferSizewriteTimeout

Constructor Summary

AccessConstructor and Description
public
NIOTransport(final String name)

Method Summary

Modifier and TypeMethod and Description
public boolean
addShutdownListener(final GracefulShutdownListener shutdownListener)

Implements org.glassfish.grizzly.Transport.addShutdownListener.

Adds a GracefulShutdownListener which will be called when shutdown() is called to enable graceful shutdown of transports.

protected abstract void
closeConnection(Connection<L> connection)

Implements abstract org.glassfish.grizzly.AbstractTransport.closeConnection.

Close the connection, managed by Transport

protected void
protected ExecutorService
protected abstract TemporarySelectorIO
protected void
public ChannelConfigurator
getChannelConfigurator()

Returns: the configurator responsible for initial SelectableChannel configuration

public int
public int
protected int
public NIOChannelDistributor
public SelectionKeyHandler
public SelectorHandler
public SelectorProvider

Returns:

the SelectorProvider to be used by this transport.
getSelectorProvider
()

Get the SelectorProvider to be used by this transport.

protected SelectorRunner[]
public int
getSelectorRunnersCount()

Returns: the number of SelectorRunners used for handling NIO events

public int
public TemporarySelectorIO
public boolean

Returns:

true, if NIOTransport is configured to use org.glassfish.grizzly.asyncqueue.AsyncQueueWriter, optimized to be used in connection multiplexing mode, or false otherwise.
isOptimizedForMultiplexing
()

Returns true, if NIOTransport is configured to use org.glassfish.grizzly.asyncqueue.AsyncQueueWriter, optimized to be used in connection multiplexing mode, or false otherwise.

public boolean
public boolean
public boolean
isReusePortAvailable()

Tells whether SO_REUSEPORT is supported.

protected abstract void
protected static void
notifyProbesError(final NIOTransport
the Transport event occurred on.
transport
,
final Throwable error)

Notify registered TransportProbes about the error.

protected static void
notifyProbesPause(final NIOTransport
the Transport event occurred on.
transport
)

Notify registered TransportProbes about the pause event.

protected static void
notifyProbesResume(final NIOTransport
the Transport event occurred on.
transport
)

Notify registered TransportProbes about the resume event.

protected static void
notifyProbesStart(final NIOTransport
the Transport event occurred on.
transport
)

Notify registered TransportProbes about the start event.

protected static void
notifyProbesStop(final NIOTransport
the Transport event occurred on.
transport
)

Notify registered TransportProbes about the stop event.

public void
notifyTransportError(final Throwable error)

Implements org.glassfish.grizzly.Transport.notifyTransportError.

Method gets invoked, when error occur during the Transport lifecycle.

public void
pause()

Implements org.glassfish.grizzly.Transport.pause.

Pause UDPNIOTransport, so I/O events coming on its org.glassfish.grizzly.nio.transport.UDPNIOConnections will not be processed.

public void
resume()

Implements org.glassfish.grizzly.Transport.resume.

Resume UDPNIOTransport, which has been paused before using pause().

public void
setChannelConfigurator(final ChannelConfigurator channelConfigurator)

Sets the configurator responsible for initial SelectableChannel configuration.

public void
setClientSocketSoTimeout(final int socketTimeout)

public void
setConnectionTimeout(final int connectionTimeout)

public void
setNIOChannelDistributor(final NIOChannelDistributor nioChannelDistributor)

public void
setOptimizedForMultiplexing(final boolean optimizedForMultiplexing)

Configures NIOTransport to be optimized for specific for the connection multiplexing usecase, when different threads will try to write data simultaneously.

public void
setReuseAddress(final boolean reuseAddress)

public void
setReusePort(final boolean reusePort)

public void
setSelectionKeyHandler(final SelectionKeyHandler selectionKeyHandler)

public void
setSelectorHandler(final SelectorHandler selectorHandler)

public void
setSelectorProvider(final SelectorProvider selectorProvider)

Set the SelectorProvider to be used by this transport.

public void
setSelectorRunnersCount(final int selectorRunnersCount)

Sets the number of SelectorRunners used for handling NIO events.

public void
setServerSocketSoTimeout(final int serverSocketSoTimeout)

public GrizzlyFuture<Transport>
shutdown()

Implements org.glassfish.grizzly.Transport.shutdown.

Gracefully stops the transport accepting new connections and allows existing work to complete before finalizing the shutdown.

public GrizzlyFuture<Transport>
shutdown(final long gracePeriod, final TimeUnit timeUnit)

Implements org.glassfish.grizzly.Transport.shutdown.

Gracefully stops the transport accepting new connections and allows existing work to complete before finalizing the shutdown.

public void
shutdownNow()

Implements org.glassfish.grizzly.Transport.shutdownNow.

Forcibly stops the transport and closes all connections.

public void
start()

Implements org.glassfish.grizzly.Transport.start.

Start TCPNIOTransport.

protected synchronized void
protected synchronized void
public abstract void
unbindAll()

Redeclares org.glassfish.grizzly.SocketBinder.unbindAll.

Unbinds all bound Transport connections.

Inherited from org.glassfish.grizzly.AbstractTransport:
configureBlockingcreateJmxManagementObjectgetAttributeBuildergetConnectionMonitoringConfiggetIOStrategygetKernelThreadPoolgetKernelThreadPoolConfiggetMemoryManagergetMonitoringConfiggetNamegetProcessorgetProcessorSelectorgetReadBufferSizegetReadTimeoutgetStategetThreadPoolMonitoringConfiggetWorkerThreadPoolgetWorkerThreadPoolConfiggetWriteBufferSizegetWriteTimeoutisBlockingisPausedisStandaloneisStoppednotifyProbesBeforePausenotifyProbesBeforeResumenotifyProbesBeforeStartnotifyProbesBeforeStopnotifyProbesConfigChangednotifyProbesPausenotifyProbesStopobtainProcessorsetAttributeBuildersetIOStrategysetKernelPool0setKernelThreadPoolsetKernelThreadPoolConfigsetMemoryManagersetNamesetProcessorsetProcessorSelectorsetReadBufferSizesetReadTimeoutsetWorkerThreadPoolsetWorkerThreadPool0setWorkerThreadPoolConfigsetWriteBufferSizesetWriteTimeoutstop

Field Detail

channelConfiguratorback to summary
protected ChannelConfigurator channelConfigurator
clientSocketSoTimeoutback to summary
pack-priv int clientSocketSoTimeout

The socket time out

connectionTimeoutback to summary
pack-priv int connectionTimeout

Default channel connection timeout

DEFAULT_CLIENT_SOCKET_SO_TIMEOUTback to summary
public static final int DEFAULT_CLIENT_SOCKET_SO_TIMEOUT
DEFAULT_CONNECTION_TIMEOUTback to summary
public static final int DEFAULT_CONNECTION_TIMEOUT

Hides org.glassfish.grizzly.SocketConnectorHandler.DEFAULT_CONNECTION_TIMEOUT.

DEFAULT_OPTIMIZED_FOR_MULTIPLEXINGback to summary
public static final boolean DEFAULT_OPTIMIZED_FOR_MULTIPLEXING
DEFAULT_REUSE_ADDRESSback to summary
public static final boolean DEFAULT_REUSE_ADDRESS
DEFAULT_REUSE_PORTback to summary
public static final boolean DEFAULT_REUSE_PORT
DEFAULT_SELECTOR_RUNNER_COUNTback to summary
public static final int DEFAULT_SELECTOR_RUNNER_COUNT
DEFAULT_SERVER_SOCKET_SO_TIMEOUTback to summary
public static final int DEFAULT_SERVER_SOCKET_SO_TIMEOUT
LOGGERback to summary
private static final Logger LOGGER
nioChannelDistributorback to summary
protected NIOChannelDistributor nioChannelDistributor
optimizedForMultiplexingback to summary
private boolean optimizedForMultiplexing
reuseAddressback to summary
pack-priv boolean reuseAddress

The socket reuseAddress

reusePortback to summary
pack-priv boolean reusePort

The socket reusePort

REUSEPORT_AVAILABLE_HOLDERback to summary
private static final Holder<Boolean> REUSEPORT_AVAILABLE_HOLDER
selectionKeyHandlerback to summary
protected SelectionKeyHandler selectionKeyHandler
selectorHandlerback to summary
protected SelectorHandler selectorHandler
selectorProviderback to summary
protected SelectorProvider selectorProvider
selectorRunnersback to summary
protected SelectorRunner[] selectorRunners
selectorRunnersCountback to summary
private int selectorRunnersCount
serverSocketSoTimeoutback to summary
pack-priv int serverSocketSoTimeout

The server socket time out

shutdownFutureback to summary
protected FutureImpl<Transport> shutdownFuture

Future to control graceful shutdown status

shutdownListenersback to summary
protected Set<GracefulShutdownListener> shutdownListeners
shutdownServiceback to summary
protected ExecutorService shutdownService

ExecutorService hosting shutdown listener threads.

temporarySelectorIOback to summary
protected final TemporarySelectorIO temporarySelectorIO

Constructor Detail

NIOTransportback to summary
public NIOTransport(final String name)

Method Detail

addShutdownListenerback to summary
public boolean addShutdownListener(final GracefulShutdownListener shutdownListener)

Implements org.glassfish.grizzly.Transport.addShutdownListener.

Doc from org.glassfish.grizzly.Transport.addShutdownListener.

Adds a GracefulShutdownListener which will be called when 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

Annotations
@Override
closeConnectionback to summary
protected abstract void closeConnection(Connection<L> connection) throws IOException

Implements abstract org.glassfish.grizzly.AbstractTransport.closeConnection.

Doc from org.glassfish.grizzly.AbstractTransport.closeConnection.

Close the connection, managed by Transport

Annotations
@Override
Exceptions
IOException:
not used
configureNIOConnectionback to summary
protected void configureNIOConnection(NIOConnection connection)
createShutdownExecutorServiceback to summary
protected ExecutorService createShutdownExecutorService()
createTemporarySelectorIOback to summary
protected abstract TemporarySelectorIO createTemporarySelectorIO()
finalizeShutdownback to summary
protected void finalizeShutdown()
getChannelConfiguratorback to summary
public ChannelConfigurator getChannelConfigurator()
Returns:ChannelConfigurator

the configurator responsible for initial SelectableChannel configuration

getClientSocketSoTimeoutback to summary
public int getClientSocketSoTimeout()
getConnectionTimeoutback to summary
public int getConnectionTimeout()
getDefaultSelectorRunnersCountback to summary
protected int getDefaultSelectorRunnersCount()
getNIOChannelDistributorback to summary
public NIOChannelDistributor getNIOChannelDistributor()
getSelectionKeyHandlerback to summary
public SelectionKeyHandler getSelectionKeyHandler()
getSelectorHandlerback to summary
public SelectorHandler getSelectorHandler()
getSelectorProviderback to summary
public SelectorProvider getSelectorProvider()

Get the SelectorProvider to be used by this transport.

Returns:SelectorProvider

the SelectorProvider to be used by this transport.

getSelectorRunnersback to summary
protected SelectorRunner[] getSelectorRunners()
getSelectorRunnersCountback to summary
public int getSelectorRunnersCount()
Returns:int

the number of SelectorRunners used for handling NIO events

getServerSocketSoTimeoutback to summary
public int getServerSocketSoTimeout()
getTemporarySelectorIOback to summary
public TemporarySelectorIO getTemporarySelectorIO()

Implements org.glassfish.grizzly.nio.tmpselectors.TemporarySelectorsEnabledTransport.getTemporarySelectorIO.

Annotations
@Override
isOptimizedForMultiplexingback to summary
public boolean isOptimizedForMultiplexing()

Returns true, if NIOTransport is configured to use org.glassfish.grizzly.asyncqueue.AsyncQueueWriter, optimized to be used in connection multiplexing mode, or false otherwise.

Returns:boolean

true, if NIOTransport is configured to use org.glassfish.grizzly.asyncqueue.AsyncQueueWriter, optimized to be used in connection multiplexing mode, or false otherwise.

Annotations
@SuppressWarnings:UnusedDeclaration
isReuseAddressback to summary
public boolean isReuseAddress()
isReusePortback to summary
public boolean isReusePort()
isReusePortAvailableback to summary
public boolean isReusePortAvailable()

Tells whether SO_REUSEPORT is supported.

listenback to summary
protected abstract void listen()
notifyProbesErrorback to summary
protected static void notifyProbesError(final NIOTransport transport, final Throwable error)

Notify registered TransportProbes about the error.

Parameters
transport:NIOTransport

the Transport event occurred on.

notifyProbesPauseback to summary
protected static void notifyProbesPause(final NIOTransport transport)

Notify registered TransportProbes about the pause event.

Parameters
transport:NIOTransport

the Transport event occurred on.

notifyProbesResumeback to summary
protected static void notifyProbesResume(final NIOTransport transport)

Notify registered TransportProbes about the resume event.

Parameters
transport:NIOTransport

the Transport event occurred on.

notifyProbesStartback to summary
protected static void notifyProbesStart(final NIOTransport transport)

Notify registered TransportProbes about the start event.

Parameters
transport:NIOTransport

the Transport event occurred on.

notifyProbesStopback to summary
protected static void notifyProbesStop(final NIOTransport transport)

Notify registered TransportProbes about the stop event.

Parameters
transport:NIOTransport

the Transport event occurred on.

notifyTransportErrorback to summary
public void notifyTransportError(final Throwable error)

Implements org.glassfish.grizzly.Transport.notifyTransportError.

Doc from org.glassfish.grizzly.Transport.notifyTransportError.

Method gets invoked, when error occur during the Transport lifecycle.

Annotations
@Override
pauseback to summary
public void pause()

Implements org.glassfish.grizzly.Transport.pause.

Pause UDPNIOTransport, so I/O events coming on its org.glassfish.grizzly.nio.transport.UDPNIOConnections will not be processed. Use resume() in order to resume UDPNIOTransport processing. The transport will be paused only if its current state is org.glassfish.grizzly.Transport.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.

Annotations
@Override
resumeback to summary
public void resume()

Implements org.glassfish.grizzly.Transport.resume.

Resume UDPNIOTransport, which has been paused before using pause(). The transport will be resumed only if its current state is org.glassfish.grizzly.Transport.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.

Annotations
@Override
setChannelConfiguratorback to summary
public void setChannelConfigurator(final ChannelConfigurator channelConfigurator)

Sets the configurator responsible for initial SelectableChannel configuration.

Parameters
channelConfigurator:ChannelConfigurator

ChannelConfigurator

setClientSocketSoTimeoutback to summary
public void setClientSocketSoTimeout(final int socketTimeout)
Annotations
@SuppressWarnings:UnusedDeclaration
setConnectionTimeoutback to summary
public void setConnectionTimeout(final int connectionTimeout)
Annotations
@SuppressWarnings:UnusedDeclaration
setNIOChannelDistributorback to summary
public void setNIOChannelDistributor(final NIOChannelDistributor nioChannelDistributor)
setOptimizedForMultiplexingback to summary
public void setOptimizedForMultiplexing(final boolean optimizedForMultiplexing)

Configures NIOTransport to be optimized for specific for the connection multiplexing usecase, when different threads will try to write data simultaneously.

setReuseAddressback to summary
public void setReuseAddress(final boolean reuseAddress)
setReusePortback to summary
public void setReusePort(final boolean reusePort)
setSelectionKeyHandlerback to summary
public void setSelectionKeyHandler(final SelectionKeyHandler selectionKeyHandler)
setSelectorHandlerback to summary
public void setSelectorHandler(final SelectorHandler selectorHandler)
setSelectorProviderback to summary
public void setSelectorProvider(final SelectorProvider selectorProvider)

Set the SelectorProvider to be used by this transport.

Parameters
selectorProvider:SelectorProvider

the SelectorProvider.

setSelectorRunnersCountback to summary
public void setSelectorRunnersCount(final int selectorRunnersCount)

Sets the number of SelectorRunners used for handling NIO events.

setServerSocketSoTimeoutback to summary
public void setServerSocketSoTimeout(final int serverSocketSoTimeout)
Annotations
@SuppressWarnings:UnusedDeclaration
shutdownback to summary
public GrizzlyFuture<Transport> shutdown()

Implements org.glassfish.grizzly.Transport.shutdown.

Doc from org.glassfish.grizzly.Transport.shutdown.

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. Invoke shutdownNow() to terminate the transport if the graceful shutdown is taking too long.

Annotations
@Override
shutdownback to summary
public GrizzlyFuture<Transport> shutdown(final long gracePeriod, final TimeUnit timeUnit)

Implements org.glassfish.grizzly.Transport.shutdown.

Doc from org.glassfish.grizzly.Transport.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.

Annotations
@Override
shutdownNowback to summary
public void shutdownNow() throws IOException

Implements org.glassfish.grizzly.Transport.shutdownNow.

Doc from org.glassfish.grizzly.Transport.shutdownNow.

Forcibly stops the transport and closes all connections.

Annotations
@Override
Exceptions
IOException:
if there was an error shutting down
startback to summary
public void start() throws IOException

Implements org.glassfish.grizzly.Transport.start.

Start TCPNIOTransport.

The transport will be started only if its current state is 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.

Annotations
@Override
Exceptions
IOException:
if an attempt was made to actually start which failed
startSelectorRunnersback to summary
protected synchronized void startSelectorRunners() throws IOException
stopSelectorRunnersback to summary
protected synchronized void stopSelectorRunners()
unbindAllback to summary
public abstract void unbindAll()

Redeclares org.glassfish.grizzly.SocketBinder.unbindAll.

Doc from org.glassfish.grizzly.SocketBinder.unbindAll.

Unbinds all bound Transport connections.

Annotations
@Override