org.glassfish.grizzly.nio.transport
Class TCPNIOTransport

java.lang.Object
  extended by org.glassfish.grizzly.AbstractTransport
      extended by org.glassfish.grizzly.nio.AbstractNIOTransport
          extended by org.glassfish.grizzly.nio.transport.TCPNIOTransport
All Implemented Interfaces:
AsyncQueueEnabledTransport, FilterChainEnabledTransport, NIOTransport, TemporarySelectorsEnabledTransport, SocketBinder, SocketConnectorHandler, Transport, ExceptionHandler

public class TCPNIOTransport
extends AbstractNIOTransport
implements SocketBinder, SocketConnectorHandler, AsyncQueueEnabledTransport, FilterChainEnabledTransport, TemporarySelectorsEnabledTransport

TCP Transport NIO implementation

Author:
Alexey Stashok, Jean-Francois Arcand

Nested Class Summary
 class TCPNIOTransport.EnableInterestPostProcessor
           
protected  class TCPNIOTransport.RegisterChannelCompletionHandler
           
 
Nested classes/interfaces inherited from interface org.glassfish.grizzly.Transport
Transport.State
 
Nested classes/interfaces inherited from interface org.glassfish.grizzly.util.ExceptionHandler
ExceptionHandler.Severity
 
Field Summary
protected  AsyncQueueIO asyncQueueIO
          Transport AsyncQueueIO
protected  int clientSocketSoTimeout
          The socket time out
protected  int connectionTimeout
          Default channel connection timeout
protected  FilterChainFactory filterChainFactory
          FilterChainFactory implementation
protected  int linger
          The socket linger.
protected  TCPNIOTransport.RegisterChannelCompletionHandler registerChannelCompletionHandler
           
protected  boolean reuseAddress
          The socket reuseAddress
protected  Collection<TCPNIOServerConnection> serverConnections
          The Server connections.
protected  int serverSocketSoTimeout
          The server socket time out
protected  boolean tcpNoDelay
          The socket tcpDelay.
protected  TemporarySelectorIO temporarySelectorIO
          Server socket backlog.
 
Fields inherited from class org.glassfish.grizzly.nio.AbstractNIOTransport
nioChannelDistributor, selectionKeyHandler, selectorHandler, selectorRunners, selectorRunnersCount
 
Fields inherited from class org.glassfish.grizzly.AbstractTransport
attributeBuilder, exceptionHandlers, internalThreadPool, isBlocking, memoryManager, name, processor, processorSelector, readBufferSize, state, strategy, workerThreadPool, writeBufferSize
 
Constructor Summary
  TCPNIOTransport()
           
protected TCPNIOTransport(String name)
           
 
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.
protected  void closeConnection(Connection connection)
          Close the connection, managed by Transport
protected  void configureChannel(SocketChannel channel)
          Configuring SocketChannel according the transport settings
 Future<Connection> connect(SocketAddress remoteAddress)
          Creates, initializes and connects socket to the specific SocketAddress and returns Connection, representing socket.
 Future<Connection> connect(SocketAddress remoteAddress, SocketAddress localAddress)
          Creates, initializes socket, binds it to the specific local and remote SocketAddress and returns Connection, representing socket.
 Future<Connection> connect(String host, int port)
          Creates, initializes and connects socket to the specific remote host and port and returns Connection, representing socket.
protected  void executeProcessor(IOEvent ioEvent, Connection connection, Processor processor, ProcessorExecutor executor, PostProcessor postProcessor, Object strategyContext)
           
 void fireIOEvent(IOEvent ioEvent, Connection connection, Object strategyContext)
          Fires specific IOEvent on the Connection
 AsyncQueueIO getAsyncQueueIO()
          Get asynchronous queue implementation.
 int getClientSocketSoTimeout()
           
 int getConnectionTimeout()
           
 FilterChain getFilterChain()
          Get FilterChain instance.
 FilterChainFactory getFilterChainFactory()
          Get FilterChainFactory, responsible to construct FilterChain instance.
 int getLinger()
           
 Filter getMessageTransportFilter()
          Get transport Filter, which is aware of Transport specifics; knows how to read/write from/to Transport.
 int getServerSocketSoTimeout()
           
 Filter getStreamTransportFilter()
          Get transport Filter, which is aware of Transport specifics; knows how to read/write from/to Transport specific Connection streams.
 TemporarySelectorIO getTemporarySelectorIO()
           
 boolean isReuseAddress()
           
 boolean isTcpNoDelay()
           
protected  NIOConnection obtainNIOConnection(SocketChannel channel)
           
 void pause()
          Pauses the transport
 int read(Connection connection, Buffer buffer)
           
 int read(Connection connection, Buffer buffer, ReadResult currentResult)
           
 void resume()
          Resumes the transport after a pause
 void setClientSocketSoTimeout(int socketTimeout)
           
 void setConnectionTimeout(int connectionTimeout)
           
 void setFilterChainFactory(FilterChainFactory factory)
          Set FilterChainFactory, responsible to construct FilterChain instance.
 void setLinger(int linger)
           
 void setReuseAddress(boolean reuseAddress)
           
 void setServerSocketSoTimeout(int serverSocketSoTimeout)
           
 void setTcpNoDelay(boolean tcpNoDelay)
           
 void setTemporarySelectorIO(TemporarySelectorIO temporarySelectorIO)
           
 void start()
          Starts the transport
 void stop()
          Stops the transport and closes all the connections
 void unbind(Connection connection)
          Unbinds bound Transport connection.
 void unbindAll()
          Unbinds all bound Transport connections.
 int write(Connection connection, Buffer buffer)
           
 int write(Connection connection, Buffer buffer, WriteResult currentResult)
           
 
Methods inherited from class org.glassfish.grizzly.nio.AbstractNIOTransport
getNioChannelDistributor, getSelectionKeyHandler, getSelectorHandler, getSelectorRunners, getSelectorRunnersCount, setNioChannelDistributor, setSelectionKeyHandler, setSelectorHandler, setSelectorRunnersCount, startSelectorRunners, stopSelectorRunners
 
Methods inherited from class org.glassfish.grizzly.AbstractTransport
addExceptionHandler, configureBlocking, fireIOEvent, getAttributeBuilder, getInternalThreadPool, getMemoryManager, getName, getProcessor, getProcessorSelector, getReadBufferSize, getState, getStrategy, getWorkerThreadPool, getWriteBufferSize, isBlocking, isStopped, notifyException, removeExceptionHandler, setAttributeBuilder, setInternalThreadPool, setMemoryManager, setName, setProcessor, setProcessorSelector, setReadBufferSize, setStrategy, setWorkerThreadPool, setWriteBufferSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.glassfish.grizzly.SocketConnectorHandler
getProcessor, getProcessorSelector, setProcessor, setProcessorSelector
 
Methods inherited from interface org.glassfish.grizzly.nio.NIOTransport
getStrategy, setStrategy
 
Methods inherited from interface org.glassfish.grizzly.Transport
addExceptionHandler, configureBlocking, fireIOEvent, getAttributeBuilder, getInternalThreadPool, getMemoryManager, getName, getProcessor, getProcessorSelector, getReadBufferSize, getState, getWorkerThreadPool, getWriteBufferSize, isBlocking, isStopped, notifyException, removeExceptionHandler, setAttributeBuilder, setInternalThreadPool, setMemoryManager, setName, setProcessor, setProcessorSelector, setReadBufferSize, setWorkerThreadPool, setWriteBufferSize
 

Field Detail

serverConnections

protected final Collection<TCPNIOServerConnection> serverConnections
The Server connections.


filterChainFactory

protected FilterChainFactory filterChainFactory
FilterChainFactory implementation


asyncQueueIO

protected AsyncQueueIO asyncQueueIO
Transport AsyncQueueIO


temporarySelectorIO

protected TemporarySelectorIO temporarySelectorIO
Server socket backlog.


serverSocketSoTimeout

protected int serverSocketSoTimeout
The server socket time out


tcpNoDelay

protected boolean tcpNoDelay
The socket tcpDelay. Default value for tcpNoDelay is disabled (set to true).


reuseAddress

protected boolean reuseAddress
The socket reuseAddress


linger

protected int linger
The socket linger.


clientSocketSoTimeout

protected int clientSocketSoTimeout
The socket time out


connectionTimeout

protected int connectionTimeout
Default channel connection timeout


registerChannelCompletionHandler

protected final TCPNIOTransport.RegisterChannelCompletionHandler registerChannelCompletionHandler
Constructor Detail

TCPNIOTransport

public TCPNIOTransport()

TCPNIOTransport

protected TCPNIOTransport(String name)
Method Detail

start

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

Specified by:
start in interface Transport
Specified by:
start in class AbstractTransport
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
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
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
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
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
Parameters:
socketAddress - the local address the server will bind to
backlog - the maximum length of the queue
Returns:
bound Connection
Throws:
IOException

unbind

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

Specified by:
unbind in interface SocketBinder
Throws:
IOException

unbindAll

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

Specified by:
unbindAll in interface SocketBinder
Throws:
IOException

connect

public Future<Connection> connect(String host,
                                  int port)
                           throws IOException
Description copied from interface: SocketConnectorHandler
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:
Future of connect operation, which could be used to get resulting Connection.
Throws:
IOException

connect

public Future<Connection> connect(SocketAddress remoteAddress)
                           throws IOException
Description copied from interface: SocketConnectorHandler
Creates, initializes and connects socket to the specific SocketAddress and returns Connection, representing socket.

Specified by:
connect in interface SocketConnectorHandler
Parameters:
remoteAddress - remote address to connect to.
Returns:
Future of connect operation, which could be used to get resulting Connection.
Throws:
IOException

connect

public Future<Connection> connect(SocketAddress remoteAddress,
                                  SocketAddress localAddress)
                           throws IOException
Description copied from interface: SocketConnectorHandler
Creates, initializes socket, binds it to the specific local and remote SocketAddress and returns Connection, representing socket.

Specified by:
connect in interface SocketConnectorHandler
Parameters:
remoteAddress - remote address to connect to.
localAddress - local address to bind socket to.
Returns:
Future of connect operation, which could be used to get resulting Connection.
Throws:
IOException

closeConnection

protected void closeConnection(Connection connection)
                        throws IOException
Description copied from class: AbstractTransport
Close the connection, managed by Transport

Specified by:
closeConnection in class AbstractNIOTransport
Throws:
IOException

obtainNIOConnection

protected NIOConnection obtainNIOConnection(SocketChannel channel)

configureChannel

protected void configureChannel(SocketChannel channel)
                         throws IOException
Configuring SocketChannel according the transport settings

Parameters:
channel - SocketChannel to configure
Throws:
IOException

getAsyncQueueIO

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

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

getLinger

public int getLinger()

setLinger

public void setLinger(int linger)

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)

getFilterChainFactory

public FilterChainFactory getFilterChainFactory()
Description copied from interface: FilterChainEnabledTransport
Get FilterChainFactory, responsible to construct FilterChain instance.

Specified by:
getFilterChainFactory in interface FilterChainEnabledTransport
Returns:
FilterChainFactory, responsible to construct FilterChain instance.

setFilterChainFactory

public void setFilterChainFactory(FilterChainFactory factory)
Description copied from interface: FilterChainEnabledTransport
Set FilterChainFactory, responsible to construct FilterChain instance.

Specified by:
setFilterChainFactory in interface FilterChainEnabledTransport
Parameters:
factory - FilterChainFactory, responsible to construct FilterChain instance.

getFilterChain

public FilterChain getFilterChain()
Description copied from interface: FilterChainEnabledTransport
Get FilterChain instance.

Specified by:
getFilterChain in interface FilterChainEnabledTransport
Returns:
FilterChain instance.

getStreamTransportFilter

public Filter getStreamTransportFilter()
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. This Filter is used, if FilterChain supposed to work in stream mode. Each Transport should provide stream transport Filter implementation.

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

getMessageTransportFilter

public Filter getMessageTransportFilter()
Description copied from interface: FilterChainEnabledTransport
Get transport Filter, which is aware of Transport specifics; knows how to read/write from/to Transport. This Filter is used, if FilterChain supposed to work in message mode. Each Transport should provide stream transport Filter implementation.

Specified by:
getMessageTransportFilter 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

setTemporarySelectorIO

public void setTemporarySelectorIO(TemporarySelectorIO temporarySelectorIO)
Specified by:
setTemporarySelectorIO in interface TemporarySelectorsEnabledTransport

fireIOEvent

public void fireIOEvent(IOEvent ioEvent,
                        Connection connection,
                        Object strategyContext)
                 throws IOException
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.
strategyContext - Strategy state
Throws:
IOException

executeProcessor

protected void executeProcessor(IOEvent ioEvent,
                                Connection connection,
                                Processor processor,
                                ProcessorExecutor executor,
                                PostProcessor postProcessor,
                                Object strategyContext)
                         throws IOException
Throws:
IOException

read

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

read

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

write

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

write

public int write(Connection connection,
                 Buffer buffer,
                 WriteResult currentResult)
          throws IOException
Throws:
IOException


Copyright © 2009 SUN Microsystems. All Rights Reserved.