com.sun.grizzly.nio.transport
Class UDPNIOTransport

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

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

UDP NIO transport implementation

Author:
Alexey Stashok

Nested Class Summary
 class UDPNIOTransport.EnableInterestPostProcessor
           
protected  class UDPNIOTransport.RegisterChannelCompletionHandler
           
 
Nested classes/interfaces inherited from interface com.sun.grizzly.Transport
Transport.State
 
Nested classes/interfaces inherited from interface com.sun.grizzly.utils.ExceptionHandler
ExceptionHandler.Severity
 
Field Summary
protected  AsyncQueueIO asyncQueueIO
          Transport AsyncQueueIO
protected  int connectionTimeout
          Default channel connection timeout
protected  FilterChainFactory filterChainFactory
          FilterChainFactory implementation
protected  UDPNIOTransport.RegisterChannelCompletionHandler registerChannelCompletionHandler
           
protected  boolean reuseAddress
          The socket reuseAddress
protected  Collection<UDPNIOServerConnection> serverConnections
          The Server connections.
protected  int serverSocketSoTimeout
          The server socket time out
protected  TemporarySelectorIO temporarySelectorIO
          Server socket backlog.
 
Fields inherited from class com.sun.grizzly.nio.AbstractNIOTransport
nioChannelDistributor, selectionKeyHandler, selectorHandler, selectorRunners, selectorRunnersCount
 
Fields inherited from class com.sun.grizzly.AbstractTransport
attributeBuilder, exceptionHandlers, internalThreadPool, isBlocking, memoryManager, name, processor, processorSelector, readBufferSize, state, strategy, workerThreadPool, writeBufferSize
 
Constructor Summary
UDPNIOTransport()
           
UDPNIOTransport(String name)
           
 
Method Summary
 UDPNIOServerConnection bind(int port)
          Binds Transport to the specific port on localhost.
 UDPNIOServerConnection bind(SocketAddress socketAddress)
          Binds Transport to the specific SocketAddress.
 UDPNIOServerConnection bind(SocketAddress socketAddress, int backlog)
          Binds Transport to the specific SocketAddress.
 UDPNIOServerConnection bind(String host, int port)
          Binds Transport to the specific host and port.
 UDPNIOServerConnection 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
 Future<Connection> connect()
          Creates non-connected UDP Connection.
 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 getConnectionTimeout()
           
 FilterChain getFilterChain()
          Get FilterChain instance.
 FilterChainFactory getFilterChainFactory()
          Get FilterChainFactory, responsible to construct FilterChain instance.
 Filter getMessageTransportFilter()
          Get transport Filter, which is aware of Transport specifics; knows how to read/write from/to Transport.
 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()
           
protected  NIOConnection obtainNIOConnection(DatagramChannel 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 setConnectionTimeout(int connectionTimeout)
           
 void setFilterChainFactory(FilterChainFactory factory)
          Set FilterChainFactory, responsible to construct FilterChain instance.
 void setReuseAddress(boolean reuseAddress)
           
 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, SocketAddress dstAddress, Buffer buffer)
           
 int write(Connection connection, SocketAddress dstAddress, Buffer buffer, WriteResult currentResult)
           
 
Methods inherited from class com.sun.grizzly.nio.AbstractNIOTransport
getNioChannelDistributor, getSelectionKeyHandler, getSelectorHandler, getSelectorRunners, getSelectorRunnersCount, setNioChannelDistributor, setSelectionKeyHandler, setSelectorHandler, setSelectorRunnersCount, startSelectorRunners, stopSelectorRunners
 
Methods inherited from class com.sun.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 com.sun.grizzly.SocketConnectorHandler
getProcessor, getProcessorSelector, setProcessor, setProcessorSelector
 
Methods inherited from interface com.sun.grizzly.nio.NIOTransport
getStrategy, setStrategy
 
Methods inherited from interface com.sun.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

serverSocketSoTimeout

protected int serverSocketSoTimeout
The server socket time out


reuseAddress

protected boolean reuseAddress
The socket reuseAddress


connectionTimeout

protected int connectionTimeout
Default channel connection timeout


serverConnections

protected final Collection<UDPNIOServerConnection> serverConnections
The Server connections.


filterChainFactory

protected FilterChainFactory filterChainFactory
FilterChainFactory implementation


asyncQueueIO

protected AsyncQueueIO asyncQueueIO
Transport AsyncQueueIO


temporarySelectorIO

protected TemporarySelectorIO temporarySelectorIO
Server socket backlog.


registerChannelCompletionHandler

protected final UDPNIOTransport.RegisterChannelCompletionHandler registerChannelCompletionHandler
Constructor Detail

UDPNIOTransport

public UDPNIOTransport()

UDPNIOTransport

public UDPNIOTransport(String name)
Method Detail

bind

public UDPNIOServerConnection 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 UDPNIOServerConnection 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 UDPNIOServerConnection 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 UDPNIOServerConnection 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 UDPNIOServerConnection 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()
                           throws IOException
Creates non-connected UDP Connection.

Returns:
non-connected UDP Connection.
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

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

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.

obtainNIOConnection

protected NIOConnection obtainNIOConnection(DatagramChannel channel)

getAsyncQueueIO

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

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

getTemporarySelectorIO

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

setTemporarySelectorIO

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

getConnectionTimeout

public int getConnectionTimeout()

setConnectionTimeout

public void setConnectionTimeout(int connectionTimeout)

isReuseAddress

public boolean isReuseAddress()

setReuseAddress

public void setReuseAddress(boolean reuseAddress)

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,
                 SocketAddress dstAddress,
                 Buffer buffer)
          throws IOException
Throws:
IOException

write

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


Copyright © 2009 SUN Microsystems. All Rights Reserved.