Class TCPNIOTransport
- 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
Fields Modifier and Type Field Description static ChannelConfiguratorDEFAULT_CHANNEL_CONFIGURATORDefaultChannelConfiguratorused to configure client and server side channels.static booleanDEFAULT_KEEP_ALIVEstatic intDEFAULT_LINGERstatic intDEFAULT_SERVER_CONNECTION_BACKLOGstatic booleanDEFAULT_TCP_NO_DELAYstatic intMAX_RECEIVE_BUFFER_SIZEstatic intMAX_SEND_BUFFER_SIZE-
Fields 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, 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
Constructors Constructor Description TCPNIOTransport()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TCPNIOServerConnectionbind(int port)Binds Transport to the specific port on localhost.TCPNIOServerConnectionbind(String host, int port)Binds Transport to the specific host and port.TCPNIOServerConnectionbind(String host, int port, int backlog)Binds Transport to the specific host and port.TCPNIOServerConnectionbind(String host, PortRange portRange, boolean randomStartPort, int backlog)Binds Transport to the specific host, and port within aPortRange.TCPNIOServerConnectionbind(String host, PortRange portRange, int backlog)Binds Transport to the specific host, and port within aPortRange.TCPNIOServerConnectionbind(SocketAddress socketAddress)Binds Transport to the specific SocketAddress.TCPNIOServerConnectionbind(SocketAddress socketAddress, int backlog)Binds Transport to the specific SocketAddress.TCPNIOServerConnectionbindToInherited()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)GrizzlyFuture<Connection>connect(String host, int port)Creates, initializes and connects socket to the specific remote host and port and returnsConnection, representing socket.GrizzlyFuture<Connection>connect(SocketAddress remoteAddress)Creates, initializes and connects socket to the specificSocketAddressand returnsConnection, representing socket.GrizzlyFuture<Connection>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 ObjectcreateJmxManagementObject()Create the Transport JMX management object.protected TemporarySelectorIOcreateTemporarySelectorIO()voidfireIOEvent(IOEvent ioEvent, Connection connection, IOEventLifeCycleListener listener)Fires specificIOEventon theConnectionAsyncQueueIO<SocketAddress>getAsyncQueueIO()Get asynchronous queue implementation.ChannelConfiguratorgetChannelConfigurator()protected intgetDefaultSelectorRunnersCount()intgetLinger()Reader<SocketAddress>getReader(boolean isBlocking)Get theReaderimplementation, depending on the requested mode.Reader<SocketAddress>getReader(Connection connection)Get theReaderto read data from theConnection.intgetServerConnectionBackLog()Get the default server connection backlog size.TemporarySelectorIOgetTemporarySelectorIO()FiltergetTransportFilter()Get transportFilter, which is aware ofTransportspecifics; knows how to read/write from/toTransportspecificConnectionstreams.Writer<SocketAddress>getWriter(boolean isBlocking)Get theWriterimplementation, depending on the requested mode.Writer<SocketAddress>getWriter(Connection connection)Get theWriterto write data to theConnection.booleanisKeepAlive()booleanisTcpNoDelay()protected voidlisten()Bufferread(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.voidunbindAll()Unbinds 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, stopSelectorRunners
-
Methods 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 Detail
-
DEFAULT_CHANNEL_CONFIGURATOR
public static final ChannelConfigurator 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:
- Constant Field Values
-
DEFAULT_KEEP_ALIVE
public static final boolean DEFAULT_KEEP_ALIVE
- See Also:
- Constant Field Values
-
DEFAULT_LINGER
public static final int DEFAULT_LINGER
- See Also:
- Constant Field Values
-
DEFAULT_SERVER_CONNECTION_BACKLOG
public static final int DEFAULT_SERVER_CONNECTION_BACKLOG
- See Also:
- Constant Field Values
-
-
Method Detail
-
createTemporarySelectorIO
protected TemporarySelectorIO createTemporarySelectorIO()
- Specified by:
createTemporarySelectorIOin classNIOTransport
-
listen
protected void listen()
- Specified by:
listenin classNIOTransport
-
getDefaultSelectorRunnersCount
protected int getDefaultSelectorRunnersCount()
- Overrides:
getDefaultSelectorRunnersCountin classNIOTransport
-
bind
public TCPNIOServerConnection bind(int port) throws IOException
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
public TCPNIOServerConnection bind(String host, int port) throws IOException
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
public TCPNIOServerConnection bind(String host, int port, int backlog) throws IOException
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
public TCPNIOServerConnection bind(SocketAddress socketAddress) throws IOException
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
public TCPNIOServerConnection bind(SocketAddress socketAddress, int backlog) throws IOException
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
public TCPNIOServerConnection bindToInherited() throws IOException
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
public void unbind(Connection connection)
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
public GrizzlyFuture<Connection> connect(String host, int port)
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
public GrizzlyFuture<Connection> connect(SocketAddress remoteAddress)
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
public void connect(SocketAddress remoteAddress, CompletionHandler<Connection> completionHandler)
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
public GrizzlyFuture<Connection> connect(SocketAddress remoteAddress, SocketAddress localAddress)
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
protected void closeConnection(Connection connection) throws IOException
Description copied from class:AbstractTransportClose the connection, managed by Transport- Specified by:
closeConnectionin classNIOTransport- Parameters:
connection-NIOConnectionto close- Throws:
IOException- not used
-
getChannelConfigurator
public ChannelConfigurator getChannelConfigurator()
- Overrides:
getChannelConfiguratorin classNIOTransport- Returns:
- the configurator responsible for initial
SelectableChannelconfiguration
-
getAsyncQueueIO
public AsyncQueueIO<SocketAddress> 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
public Filter 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
public TemporarySelectorIO getTemporarySelectorIO()
- Specified by:
getTemporarySelectorIOin interfaceTemporarySelectorsEnabledTransport- Overrides:
getTemporarySelectorIOin classNIOTransport
-
fireIOEvent
public void fireIOEvent(IOEvent ioEvent, Connection connection, IOEventLifeCycleListener listener)
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
public Reader<SocketAddress> getReader(Connection connection)
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
public Reader<SocketAddress> getReader(boolean isBlocking)
Get theReaderimplementation, depending on the requested mode.
-
getWriter
public Writer<SocketAddress> getWriter(Connection connection)
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
public Writer<SocketAddress> getWriter(boolean isBlocking)
Get theWriterimplementation, depending on the requested mode.
-
read
public Buffer read(Connection connection, Buffer buffer) throws IOException
- Throws:
IOException
-
write
public int write(TCPNIOConnection connection, WritableMessage message) throws IOException
- Throws:
IOException
-
write
public int write(TCPNIOConnection connection, WritableMessage message, WriteResult currentResult) throws IOException
- Throws:
IOException
-
createJmxManagementObject
protected Object createJmxManagementObject()
Create the Transport JMX management object.- Specified by:
createJmxManagementObjectin classAbstractTransport- Returns:
- the Transport JMX management object.
-
-