java.lang.Object
org.glassfish.grizzly.AbstractTransport
org.glassfish.grizzly.nio.NIOTransport
org.glassfish.grizzly.nio.transport.TCPNIOTransport
- All Implemented Interfaces:
AsyncQueueEnabledTransport,ConnectorHandler<SocketAddress>,FilterChainEnabledTransport,MonitoringAware<TransportProbe>,TemporarySelectorsEnabledTransport,SocketBinder,SocketConnectorHandler,Transport
public final class TCPNIOTransport
extends NIOTransport
implements AsyncQueueEnabledTransport, FilterChainEnabledTransport, TemporarySelectorsEnabledTransport
TCP Transport NIO implementation
- Author:
- Alexey Stashok, Jean-Francois Arcand
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.glassfish.grizzly.Transport
Transport.State -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ChannelConfiguratorDefaultChannelConfiguratorused to configure client and server side channels.static final booleanstatic final intstatic final intstatic final booleanstatic final intstatic final intFields 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 TypeMethodDescriptionbind(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.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) 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.protected intintgetReader(boolean isBlocking) Get theReaderimplementation, depending on the requested mode.getReader(Connection connection) Get theReaderto read data from theConnection.intGet the default server connection backlog size.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.booleanbooleanprotected voidlisten()read(Connection connection, Buffer buffer) voidsetKeepAlive(boolean isKeepAlive) voidsetLinger(int linger) voidsetServerConnectionBackLog(int serverConnectionBackLog) Set the default server connection backlog size.voidsetTcpNoDelay(boolean tcpNoDelay) voidunbind(Connection connection) Unbinds boundTransportconnection.voidUnbinds all boundTransportconnections.intwrite(TCPNIOConnection connection, WritableMessage message) intwrite(TCPNIOConnection connection, WritableMessage message, WriteResult currentResult) Methods inherited from class org.glassfish.grizzly.nio.NIOTransport
addShutdownListener, configureNIOConnection, createShutdownExecutorService, finalizeShutdown, getClientSocketSoTimeout, getConnectionTimeout, 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. -
MAX_RECEIVE_BUFFER_SIZE
public static final int MAX_RECEIVE_BUFFER_SIZE -
MAX_SEND_BUFFER_SIZE
public static final int MAX_SEND_BUFFER_SIZE -
DEFAULT_TCP_NO_DELAY
public static final boolean DEFAULT_TCP_NO_DELAY- See Also:
-
DEFAULT_KEEP_ALIVE
public static final boolean DEFAULT_KEEP_ALIVE- See Also:
-
DEFAULT_LINGER
public static final int DEFAULT_LINGER- See Also:
-
DEFAULT_SERVER_CONNECTION_BACKLOG
public static final int DEFAULT_SERVER_CONNECTION_BACKLOG- See Also:
-
-
Constructor Details
-
TCPNIOTransport
public TCPNIOTransport()
-
-
Method Details
-
createTemporarySelectorIO
- Specified by:
createTemporarySelectorIOin classNIOTransport
-
listen
protected void listen()- Specified by:
listenin classNIOTransport
-
getDefaultSelectorRunnersCount
protected int getDefaultSelectorRunnersCount()- Overrides:
getDefaultSelectorRunnersCountin classNIOTransport
-
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
Binds 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 TCPNIOServerConnection 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 TCPNIOServerConnection 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, 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.
-
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.
-
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
-
getChannelConfigurator
- Overrides:
getChannelConfiguratorin classNIOTransport- Returns:
- the configurator responsible for initial
SelectableChannelconfiguration
-
getAsyncQueueIO
Description copied from interface:AsyncQueueEnabledTransportGet asynchronous queue implementation.- Specified by:
getAsyncQueueIOin interfaceAsyncQueueEnabledTransport- Returns:
- asynchronous queue implementation.
-
configureStandalone
public void configureStandalone(boolean isStandalone) - Specified by:
configureStandalonein interfaceTransport
-
getLinger
public int getLinger() -
setLinger
public void setLinger(int linger) -
isKeepAlive
public boolean isKeepAlive() -
setKeepAlive
public void setKeepAlive(boolean isKeepAlive) -
isTcpNoDelay
public boolean isTcpNoDelay() -
setTcpNoDelay
public void setTcpNoDelay(boolean tcpNoDelay) -
getServerConnectionBackLog
public int getServerConnectionBackLog()Get the default server connection backlog size.- Returns:
- the default server connection backlog size.
-
setServerConnectionBackLog
public void setServerConnectionBackLog(int serverConnectionBackLog) Set the default server connection backlog size.- Parameters:
serverConnectionBackLog- the default server connection backlog size.
-
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.
-
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
-
write
- Throws:
IOException
-
write
public int write(TCPNIOConnection connection, WritableMessage message, WriteResult currentResult) throws IOException - Throws:
IOException
-
createJmxManagementObject
Create the Transport JMX management object.- Specified by:
createJmxManagementObjectin classAbstractTransport- Returns:
- the Transport JMX management object.
-