org.glassfish.grizzly.nio.transport
Class TCPNIOTransport

java.lang.Object
  extended by org.glassfish.grizzly.AbstractTransport
      extended by org.glassfish.grizzly.nio.NIOTransport
          extended by org.glassfish.grizzly.nio.transport.TCPNIOTransport
All Implemented Interfaces:
AsyncQueueEnabledTransport, ConnectorHandler<SocketAddress>, FilterChainEnabledTransport, JmxMonitoringAware<TransportProbe>, MonitoringAware<TransportProbe>, TemporarySelectorsEnabledTransport, SocketBinder<TCPNIOServerConnection>, SocketConnectorHandler, Transport

public final class TCPNIOTransport
extends NIOTransport
implements SocketBinder<TCPNIOServerConnection>, SocketConnectorHandler, 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 inherited from class org.glassfish.grizzly.nio.NIOTransport
nioChannelDistributor, RANDOM, selectionKeyHandler, selectorHandler, selectorProvider, selectorRunners, selectorRunnersCount
 
Fields inherited from class org.glassfish.grizzly.AbstractTransport
attributeBuilder, connectionMonitoringConfig, isBlocking, isStandalone, kernelPool, kernelPoolConfig, managedWorkerPool, memoryManager, name, processor, processorSelector, readBufferSize, state, strategy, threadPoolMonitoringConfig, transportMonitoringConfig, workerPoolConfig, workerThreadPool, writeBufferSize
 
Constructor Summary
TCPNIOTransport()
           
 
Method Summary
 TCPNIOServerConnection bind(int port)
          Binds Transport to the specific port on localhost.
 TCPNIOServerConnection bind(SocketAddress socketAddress)
          Binds Transport to the specific SocketAddress.
 TCPNIOServerConnection bind(SocketAddress socketAddress, int backlog)
          Binds Transport to the specific SocketAddress.
 TCPNIOServerConnection bind(String host, int port)
          Binds Transport to the specific host and port.
 TCPNIOServerConnection bind(String host, int port, int backlog)
          Binds Transport to the specific host and port.
 TCPNIOServerConnection bind(String host, PortRange portRange, int backlog)
          Binds Transport to the specific host, and port within a PortRange.
 TCPNIOServerConnection bindToInherited()
          Binds the Transport to the channel inherited from the entity that created this Java virtual machine.
protected  void closeConnection(Connection connection)
          Close the connection, managed by Transport
 void configureStandalone(boolean isStandalone)
           
 GrizzlyFuture<Connection> connect(SocketAddress remoteAddress)
          Creates, initializes and connects socket to the specific SocketAddress and returns Connection, representing socket.
 void connect(SocketAddress remoteAddress, CompletionHandler<Connection> completionHandler)
          Creates, initializes and connects socket to the specific SocketAddress and returns Connection, representing socket.
 GrizzlyFuture<Connection> connect(SocketAddress remoteAddress, SocketAddress localAddress)
          Creates, initializes socket, binds it to the specific local and remote SocketAddress and returns Connection, representing socket.
 void connect(SocketAddress remoteAddress, SocketAddress localAddress, CompletionHandler<Connection> completionHandler)
          Creates, initializes socket, binds it to the specific local and remote SocketAddress and returns Connection, representing socket.
 GrizzlyFuture<Connection> connect(String host, int port)
          Creates, initializes and connects socket to the specific remote host and port and returns Connection, representing socket.
protected  JmxObject createJmxManagementObject()
          Create the Transport JMX managment object.
 void fireIOEvent(IOEvent ioEvent, Connection connection, IOEventProcessingHandler processingHandler)
          Fires specific IOEvent on the Connection
 AsyncQueueIO<SocketAddress> getAsyncQueueIO()
          Get asynchronous queue implementation.
 int getClientSocketSoTimeout()
           
 int getConnectionTimeout()
           
 int getLinger()
           
 Reader<SocketAddress> getReader(boolean isBlocking)
          Get the Reader implementation, depending on the requested mode.
 Reader<SocketAddress> getReader(Connection connection)
          Get the Reader to read data from the Connection.
 int getServerConnectionBackLog()
          Get the default server connection backlog size.
 int getServerSocketSoTimeout()
           
 TemporarySelectorIO getTemporarySelectorIO()
           
 Filter getTransportFilter()
          Get transport Filter, which is aware of Transport specifics; knows how to read/write from/to Transport specific Connection streams.
 Writer<SocketAddress> getWriter(boolean isBlocking)
          Get the Writer implementation, depending on the requested mode.
 Writer<SocketAddress> getWriter(Connection connection)
          Get the Writer to write data to the Connection.
 boolean isKeepAlive()
           
 boolean isOptimizedForMultiplexing()
          Returns true, if TCPNIOTransport is configured to use AsyncQueueWriter, optimized to be used in connection multiplexing mode, or false otherwise.
 boolean isReuseAddress()
           
 boolean isTcpNoDelay()
           
 void pause()
          Pauses the transport
 Buffer read(Connection connection, Buffer buffer)
           
 void resume()
          Resumes the transport after a pause
 void setClientSocketSoTimeout(int socketTimeout)
           
 void setConnectionTimeout(int connectionTimeout)
           
 void setKeepAlive(boolean isKeepAlive)
           
 void setLinger(int linger)
           
 void setOptimizedForMultiplexing(boolean isOptimizedForMultiplexing)
          Configures TCPNIOTransport to be optimized for specific for the connection multiplexing usecase, when different threads will try to write data simultaneously.
 void setReuseAddress(boolean reuseAddress)
           
 void setServerConnectionBackLog(int serverConnectionBackLog)
          Set the default server connection backlog size.
 void setServerSocketSoTimeout(int serverSocketSoTimeout)
           
 void setTcpNoDelay(boolean tcpNoDelay)
           
 void start()
          Starts the transport
 void stop()
          Stops the transport and closes all the connections
 void unbind(TCPNIOServerConnection connection)
          Unbinds bound Transport connection.
 void unbindAll()
          Unbinds all bound Transport connections.
 int write(Connection connection, WritableMessage message)
           
 int write(Connection connection, WritableMessage message, WriteResult currentResult)
           
 
Methods inherited from class org.glassfish.grizzly.nio.NIOTransport
getNIOChannelDistributor, getSelectionKeyHandler, getSelectorHandler, getSelectorProvider, getSelectorRunners, getSelectorRunnersCount, notifyProbesError, notifyProbesPause, notifyProbesResume, notifyProbesStart, notifyProbesStop, notifyTransportError, setNIOChannelDistributor, setSelectionKeyHandler, setSelectorHandler, setSelectorProvider, setSelectorRunnersCount, startSelectorRunners, stopSelectorRunners
 
Methods inherited from class org.glassfish.grizzly.AbstractTransport
configureBlocking, getAttributeBuilder, getConnectionMonitoringConfig, getIOStrategy, getKernelThreadPool, getKernelThreadPoolConfig, getMemoryManager, getMonitoringConfig, getName, getProcessor, getProcessorSelector, getReadBufferSize, getState, getThreadPoolMonitoringConfig, getWorkerThreadPool, getWorkerThreadPoolConfig, getWriteBufferSize, isBlocking, isPaused, isStandalone, isStopped, notifyProbesConfigChanged, obtainProcessor, setAttributeBuilder, setIOStrategy, setKernelPool0, setKernelThreadPool, setKernelThreadPoolConfig, setMemoryManager, setName, setProcessor, setProcessorSelector, setReadBufferSize, setWorkerThreadPool, setWorkerThreadPool0, setWorkerThreadPoolConfig, setWriteBufferSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TCPNIOTransport

public TCPNIOTransport()
Method Detail

start

public void start()
           throws IOException
Description copied from class: AbstractTransport
Starts the transport

Specified by:
start in interface Transport
Overrides:
start in class NIOTransport
Throws:
IOException

stop

public void stop()
          throws IOException
Description copied from class: AbstractTransport
Stops the transport and closes all the connections

Specified by:
stop in interface Transport
Specified by:
stop in class AbstractTransport
Throws:
IOException

pause

public void pause()
           throws IOException
Description copied from class: AbstractTransport
Pauses the transport

Specified by:
pause in interface Transport
Specified by:
pause in class AbstractTransport
Throws:
IOException

resume

public void resume()
            throws IOException
Description copied from class: AbstractTransport
Resumes the transport after a pause

Specified by:
resume in interface Transport
Specified by:
resume in class AbstractTransport
Throws:
IOException

bind

public TCPNIOServerConnection bind(int port)
                            throws IOException
Binds Transport to the specific port on localhost.

Specified by:
bind in interface SocketBinder<TCPNIOServerConnection>
Returns:
bound Connection
Throws:
IOException

bind

public TCPNIOServerConnection bind(String host,
                                   int port)
                            throws IOException
Binds Transport to the specific host and port.

Specified by:
bind in interface SocketBinder<TCPNIOServerConnection>
Parameters:
host - the local host the server will bind to
Returns:
bound Connection
Throws:
IOException

bind

public TCPNIOServerConnection bind(String host,
                                   int port,
                                   int backlog)
                            throws IOException
Binds Transport to the specific host and port.

Specified by:
bind in interface SocketBinder<TCPNIOServerConnection>
Parameters:
host - the local host the server will bind to
backlog - the maximum length of the queue
Returns:
bound Connection
Throws:
IOException

bind

public TCPNIOServerConnection bind(SocketAddress socketAddress)
                            throws IOException
Binds Transport to the specific SocketAddress.

Specified by:
bind in interface SocketBinder<TCPNIOServerConnection>
Parameters:
socketAddress - the local address the server will bind to
Returns:
bound Connection
Throws:
IOException

bind

public TCPNIOServerConnection bind(SocketAddress socketAddress,
                                   int backlog)
                            throws IOException
Binds Transport to the specific SocketAddress.

Specified by:
bind in interface SocketBinder<TCPNIOServerConnection>
Parameters:
socketAddress - the local address the server will bind to
backlog - the maximum length of the queue
Returns:
bound Connection
Throws:
IOException

bindToInherited

public TCPNIOServerConnection bindToInherited()
                                       throws IOException
Binds the Transport to the channel inherited from the entity that created this Java virtual machine.

Specified by:
bindToInherited in interface SocketBinder<TCPNIOServerConnection>
Returns:
bound Connection
Throws:
IOException

bind

public TCPNIOServerConnection bind(String host,
                                   PortRange portRange,
                                   int backlog)
                            throws IOException
Binds Transport to the specific host, and port within a PortRange.

Specified by:
bind in interface SocketBinder<TCPNIOServerConnection>
Parameters:
host - the local host the server will bind to
portRange - PortRange.
backlog - the maximum length of the queue
Returns:
bound Connection
Throws:
IOException

unbind

public void unbind(TCPNIOServerConnection connection)
            throws IOException
Unbinds bound Transport connection.

Specified by:
unbind in interface SocketBinder<TCPNIOServerConnection>
Parameters:
connection - Connection
Throws:
IOException

unbindAll

public void unbindAll()
               throws IOException
Description copied from interface: SocketBinder
Unbinds all bound Transport connections.

Specified by:
unbindAll in interface SocketBinder<TCPNIOServerConnection>
Throws:
IOException

connect

public GrizzlyFuture<Connection> connect(String host,
                                         int port)
Creates, initializes and connects socket to the specific remote host and port and returns Connection, representing socket.

Specified by:
connect in interface SocketConnectorHandler
Parameters:
host - remote host to connect to.
port - remote port to connect to.
Returns:
GrizzlyFuture of connect operation, which could be used to get resulting Connection.

connect

public GrizzlyFuture<Connection> connect(SocketAddress remoteAddress)
Creates, initializes and connects socket to the specific SocketAddress and returns Connection, representing socket.

Specified by:
connect in interface ConnectorHandler<SocketAddress>
Parameters:
remoteAddress - remote address to connect to.
Returns:
GrizzlyFuture of connect operation, which could be used to get resulting Connection.

connect

public void connect(SocketAddress remoteAddress,
                    CompletionHandler<Connection> completionHandler)
Creates, initializes and connects socket to the specific SocketAddress and returns Connection, representing socket.

Specified by:
connect in interface ConnectorHandler<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 remote SocketAddress and returns Connection, representing socket.

Specified by:
connect in interface ConnectorHandler<SocketAddress>
Parameters:
remoteAddress - remote address to connect to.
localAddress - local address to bind socket to.
Returns:
GrizzlyFuture of connect operation, which could be used to get resulting Connection.

connect

public void connect(SocketAddress remoteAddress,
                    SocketAddress localAddress,
                    CompletionHandler<Connection> completionHandler)
Creates, initializes socket, binds it to the specific local and remote SocketAddress and returns Connection, representing socket.

Specified by:
connect in interface ConnectorHandler<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: AbstractTransport
Close the connection, managed by Transport

Specified by:
closeConnection in class NIOTransport
Throws:
IOException

getAsyncQueueIO

public AsyncQueueIO<SocketAddress> getAsyncQueueIO()
Description copied from interface: AsyncQueueEnabledTransport
Get asynchronous queue implementation.

Specified by:
getAsyncQueueIO in interface AsyncQueueEnabledTransport
Returns:
asynchronous queue implementation.

configureStandalone

public void configureStandalone(boolean isStandalone)
Specified by:
configureStandalone in interface Transport

getLinger

public int getLinger()

setLinger

public void setLinger(int linger)

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.

isKeepAlive

public boolean isKeepAlive()

setKeepAlive

public void setKeepAlive(boolean isKeepAlive)

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)

isTcpNoDelay

public boolean isTcpNoDelay()

setTcpNoDelay

public void setTcpNoDelay(boolean tcpNoDelay)

getServerSocketSoTimeout

public int getServerSocketSoTimeout()

setServerSocketSoTimeout

public void setServerSocketSoTimeout(int serverSocketSoTimeout)

isOptimizedForMultiplexing

public boolean isOptimizedForMultiplexing()
Returns true, if TCPNIOTransport is configured to use AsyncQueueWriter, optimized to be used in connection multiplexing mode, or false otherwise.

Returns:
true, if TCPNIOTransport is configured to use AsyncQueueWriter, optimized to be used in connection multiplexing mode, or false otherwise.

setOptimizedForMultiplexing

public void setOptimizedForMultiplexing(boolean isOptimizedForMultiplexing)
Configures TCPNIOTransport to be optimized for specific for the connection multiplexing usecase, when different threads will try to write data simultaneously.


getTransportFilter

public Filter getTransportFilter()
Description copied from interface: FilterChainEnabledTransport
Get transport Filter, which is aware of Transport specifics; knows how to read/write from/to Transport specific Connection streams. Each Transport should provide transport Filter implementation.

Specified by:
getTransportFilter in interface FilterChainEnabledTransport
Returns:
transport Filter, which is aware of Transport specifics; knows how to read/write from/to Transport specific Connections.

getTemporarySelectorIO

public TemporarySelectorIO getTemporarySelectorIO()
Specified by:
getTemporarySelectorIO in interface TemporarySelectorsEnabledTransport

fireIOEvent

public void fireIOEvent(IOEvent ioEvent,
                        Connection connection,
                        IOEventProcessingHandler processingHandler)
Description copied from interface: Transport
Fires specific IOEvent on the Connection

Specified by:
fireIOEvent in interface Transport
Parameters:
ioEvent - I/O event
connection - Connection, on which we fire the event.
processingHandler - I/O event processing handler.

getReader

public Reader<SocketAddress> getReader(Connection connection)
Get the Reader to read data from the Connection. The Transport may decide to return blocking or non-blocking Reader depending on the Connection settings.

Specified by:
getReader in interface Transport
Parameters:
connection - Connection.
Returns:
Reader.

getReader

public Reader<SocketAddress> getReader(boolean isBlocking)
Get the Reader implementation, depending on the requested mode.

Specified by:
getReader in interface Transport
Parameters:
isBlocking - blocking mode.
Returns:
Reader.

getWriter

public Writer<SocketAddress> getWriter(Connection connection)
Get the Writer to write data to the Connection. The Transport may decide to return blocking or non-blocking Writer depending on the Connection settings.

Specified by:
getWriter in interface Transport
Parameters:
connection - Connection.
Returns:
Writer.

getWriter

public Writer<SocketAddress> getWriter(boolean isBlocking)
Get the Writer implementation, depending on the requested mode.

Specified by:
getWriter in interface Transport
Parameters:
isBlocking - blocking mode.
Returns:
Writer.

read

public Buffer read(Connection connection,
                   Buffer buffer)
            throws IOException
Throws:
IOException

write

public int write(Connection connection,
                 WritableMessage message)
          throws IOException
Throws:
IOException

write

public int write(Connection connection,
                 WritableMessage message,
                 WriteResult currentResult)
          throws IOException
Throws:
IOException

createJmxManagementObject

protected JmxObject createJmxManagementObject()
Create the Transport JMX managment object.

Specified by:
createJmxManagementObject in class AbstractTransport
Returns:
the Transport JMX managment object.


Copyright © 2013 Oracle Corporation. All Rights Reserved.