public abstract class NIOTransport extends AbstractTransport implements SocketBinder, SocketConnectorHandler, TemporarySelectorsEnabledTransport, AsyncQueueEnabledTransport
Transport.State
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_CLIENT_SOCKET_SO_TIMEOUT |
static int |
DEFAULT_CONNECTION_TIMEOUT |
static boolean |
DEFAULT_OPTIMIZED_FOR_MULTIPLEXING |
static boolean |
DEFAULT_REUSE_ADDRESS |
static int |
DEFAULT_SELECTOR_RUNNER_COUNT |
static int |
DEFAULT_SERVER_SOCKET_SO_TIMEOUT |
protected NIOChannelDistributor |
nioChannelDistributor |
protected SelectionKeyHandler |
selectionKeyHandler |
protected SelectorHandler |
selectorHandler |
protected SelectorProvider |
selectorProvider |
protected SelectorRunner[] |
selectorRunners |
protected FutureImpl<Transport> |
shutdownFuture
Future to control graceful shutdown status
|
protected Set<GracefulShutdownListener> |
shutdownListeners |
protected ExecutorService |
shutdownService
ExecutorService hosting shutdown listener threads.
|
protected TemporarySelectorIO |
temporarySelectorIO |
attributeBuilder, connectionMonitoringConfig, isBlocking, isStandalone, kernelPool, kernelPoolConfig, managedWorkerPool, memoryManager, name, processor, processorSelector, readBufferSize, readTimeout, state, strategy, threadPoolMonitoringConfig, transportMonitoringConfig, workerPoolConfig, workerThreadPool, writeBufferSize, writeTimeout
DEFAULT_READ_BUFFER_SIZE, DEFAULT_READ_TIMEOUT, DEFAULT_WRITE_BUFFER_SIZE, DEFAULT_WRITE_TIMEOUT
Constructor and Description |
---|
NIOTransport(String name) |
Modifier and Type | Method and Description |
---|---|
boolean |
addShutdownListener(GracefulShutdownListener shutdownListener)
Adds a
GracefulShutdownListener which will be called when Transport.shutdown()
is called to enable graceful shutdown of transports. |
protected abstract void |
closeConnection(Connection connection)
Close the connection, managed by Transport
|
protected void |
configureNIOConnection(NIOConnection connection) |
protected ExecutorService |
createShutdownExecutorService() |
protected abstract TemporarySelectorIO |
createTemporarySelectorIO() |
protected void |
finalizeShutdown() |
int |
getClientSocketSoTimeout() |
int |
getConnectionTimeout() |
protected int |
getDefaultSelectorRunnersCount() |
NIOChannelDistributor |
getNIOChannelDistributor() |
SelectionKeyHandler |
getSelectionKeyHandler() |
SelectorHandler |
getSelectorHandler() |
SelectorProvider |
getSelectorProvider()
Get the
SelectorProvider to be used by this transport. |
protected SelectorRunner[] |
getSelectorRunners() |
int |
getSelectorRunnersCount() |
int |
getServerSocketSoTimeout() |
TemporarySelectorIO |
getTemporarySelectorIO() |
boolean |
isOptimizedForMultiplexing()
Returns true, if NIOTransport is configured to use
AsyncQueueWriter , optimized to be used in connection multiplexing
mode, or false otherwise. |
boolean |
isReuseAddress() |
protected abstract void |
listen() |
protected static void |
notifyProbesError(NIOTransport transport,
Throwable error)
Notify registered
TransportProbe s about the error. |
protected static void |
notifyProbesPause(NIOTransport transport)
Notify registered
TransportProbe s about the pause event. |
protected static void |
notifyProbesResume(NIOTransport transport)
Notify registered
TransportProbe s about the resume event. |
protected static void |
notifyProbesStart(NIOTransport transport)
Notify registered
TransportProbe s about the start event. |
protected static void |
notifyProbesStop(NIOTransport transport)
Notify registered
TransportProbe 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 its
UDPNIOConnection s
will not be processed. |
void |
resume()
Resume UDPNIOTransport, which has been paused before using
pause() . |
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 the
SelectorProvider to be used by this transport. |
void |
setSelectorRunnersCount(int selectorRunnersCount) |
void |
setServerSocketSoTimeout(int serverSocketSoTimeout) |
GrizzlyFuture<Transport> |
shutdown()
Gracefully stops the transport accepting new connections and allows
existing work to complete before finalizing the shutdown.
|
GrizzlyFuture<Transport> |
shutdown(long gracePeriod,
TimeUnit timeUnit)
Gracefully stops the transport accepting new connections and allows
existing work to complete before finalizing the shutdown.
|
void |
shutdownNow()
Forcibly stops the transport and closes all connections.
|
void |
start()
Start TCPNIOTransport.
|
protected void |
startSelectorRunners() |
protected void |
stopSelectorRunners() |
abstract void |
unbindAll()
Unbinds all bound
Transport connections. |
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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
bind, bind, bind, bind, bind, bind, bindToInherited, unbind
connect
connect, connect, connect, connect
getAsyncQueueIO
configureStandalone, fireIOEvent, getReader, getReader, getWriter, getWriter
public static final int DEFAULT_SERVER_SOCKET_SO_TIMEOUT
public static final boolean DEFAULT_REUSE_ADDRESS
public static final int DEFAULT_CLIENT_SOCKET_SO_TIMEOUT
public static final int DEFAULT_CONNECTION_TIMEOUT
public static final int DEFAULT_SELECTOR_RUNNER_COUNT
public static final boolean DEFAULT_OPTIMIZED_FOR_MULTIPLEXING
protected SelectorHandler selectorHandler
protected SelectionKeyHandler selectionKeyHandler
protected SelectorRunner[] selectorRunners
protected NIOChannelDistributor nioChannelDistributor
protected SelectorProvider selectorProvider
protected final TemporarySelectorIO temporarySelectorIO
protected Set<GracefulShutdownListener> shutdownListeners
protected FutureImpl<Transport> shutdownFuture
protected ExecutorService shutdownService
public NIOTransport(String name)
public abstract void unbindAll()
SocketBinder
Transport
connections.unbindAll
in interface SocketBinder
public boolean addShutdownListener(GracefulShutdownListener shutdownListener)
Transport
GracefulShutdownListener
which will be called when Transport.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 transportaddShutdownListener
in interface Transport
shutdownListener
- the GracefulShutdownListener
true
if the listener was successfully registered,
otherwise false
. When this method returns false
it means one of two things: the transport is stopping or is stopped, or
the listener has already been registered.public TemporarySelectorIO getTemporarySelectorIO()
getTemporarySelectorIO
in interface TemporarySelectorsEnabledTransport
public SelectionKeyHandler getSelectionKeyHandler()
public void setSelectionKeyHandler(SelectionKeyHandler selectionKeyHandler)
public SelectorHandler getSelectorHandler()
public void setSelectorHandler(SelectorHandler selectorHandler)
public int getSelectorRunnersCount()
public void setSelectorRunnersCount(int selectorRunnersCount)
public SelectorProvider getSelectorProvider()
SelectorProvider
to be used by this transport.SelectorProvider
to be used by this transport.public void setSelectorProvider(SelectorProvider selectorProvider)
SelectorProvider
to be used by this transport.selectorProvider
- the SelectorProvider
.public boolean isOptimizedForMultiplexing()
AsyncQueueWriter
, optimized to be used in connection multiplexing
mode, or false otherwise.AsyncQueueWriter
, optimized to be used in connection multiplexing
mode, or false otherwise.public void setOptimizedForMultiplexing(boolean optimizedForMultiplexing)
protected void startSelectorRunners() throws IOException
IOException
protected void stopSelectorRunners()
public NIOChannelDistributor getNIOChannelDistributor()
public void setNIOChannelDistributor(NIOChannelDistributor nioChannelDistributor)
public void notifyTransportError(Throwable error)
notifyTransportError
in interface Transport
error
- Throwable
.protected SelectorRunner[] getSelectorRunners()
protected static void notifyProbesError(NIOTransport transport, Throwable error)
TransportProbe
s about the error.transport
- the Transport event occurred on.protected static void notifyProbesStart(NIOTransport transport)
TransportProbe
s about the start event.transport
- the Transport event occurred on.protected static void notifyProbesStop(NIOTransport transport)
TransportProbe
s about the stop event.transport
- the Transport event occurred on.protected static void notifyProbesPause(NIOTransport transport)
TransportProbe
s about the pause event.transport
- the Transport event occurred on.protected static void notifyProbesResume(NIOTransport transport)
TransportProbe
s about the resume event.transport
- the Transport event occurred on.public void start() throws IOException
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.start
in interface Transport
IOException
public GrizzlyFuture<Transport> shutdown()
Transport
Transport.shutdownNow()
to terminate
the transport if the graceful shutdown is taking too long.shutdown
in interface Transport
GrizzlyFuture
which will return the stopped transport.GracefulShutdownListener
public GrizzlyFuture<Transport> shutdown(long gracePeriod, TimeUnit timeUnit)
shutdown
in interface Transport
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
- the TimeUnit
of the specified grace period.GrizzlyFuture
which will return the stopped transport.public void shutdownNow() throws IOException
shutdownNow
in interface Transport
IOException
protected abstract void closeConnection(Connection connection) throws IOException
AbstractTransport
closeConnection
in class AbstractTransport
IOException
protected abstract TemporarySelectorIO createTemporarySelectorIO()
protected abstract void listen()
protected int getDefaultSelectorRunnersCount()
protected void finalizeShutdown()
public void pause()
UDPNIOConnection
s
will not be processed. Use resume()
in order to resume UDPNIOTransport processing.
The transport will be paused only if its current state is 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.public void resume()
pause()
.
The transport will be resumed only if its current state is 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.protected void configureNIOConnection(NIOConnection connection)
public boolean isReuseAddress()
public void setReuseAddress(boolean reuseAddress)
public int getClientSocketSoTimeout()
public void setClientSocketSoTimeout(int socketTimeout)
public int getConnectionTimeout()
public void setConnectionTimeout(int connectionTimeout)
public int getServerSocketSoTimeout()
public void setServerSocketSoTimeout(int serverSocketSoTimeout)
protected ExecutorService createShutdownExecutorService()
Copyright © 2014 Oracle Corporation. All rights reserved.