org.glassfish.grizzly.nio.transport
Class UDPNIOTransport

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

public final class UDPNIOTransport
extends NIOTransport
implements SocketBinder, SocketConnectorHandler, AsyncQueueEnabledTransport, FilterChainEnabledTransport, TemporarySelectorsEnabledTransport

UDP NIO transport implementation

Author:
Alexey Stashok

Nested Class Summary
protected  class UDPNIOTransport.RegisterChannelCompletionHandler
           
protected  class UDPNIOTransport.TransportConnectorHandler
          Transport default UDPNIOConnectorHandler.
 
Nested classes/interfaces inherited from interface org.glassfish.grizzly.Transport
Transport.IOEventReg, Transport.State
 
Field Summary
protected  AsyncQueueIO<java.net.SocketAddress> asyncQueueIO
          Transport AsyncQueueIO
protected  int connectionTimeout
          Default channel connection timeout
protected  UDPNIOTransport.RegisterChannelCompletionHandler registerChannelCompletionHandler
           
protected  boolean reuseAddress
          The socket reuseAddress
protected  java.util.Collection<UDPNIOServerConnection> serverConnections
          The Server connections.
protected  int serverSocketSoTimeout
          The server socket time out
protected  TemporarySelectorIO temporarySelectorIO
          Server socket backlog.
 
Fields inherited from class org.glassfish.grizzly.nio.NIOTransport
nioChannelDistributor, RANDOM, selectionKeyHandler, selectorHandler, 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
UDPNIOTransport()
           
UDPNIOTransport(java.lang.String name)
           
 
Method Summary
 UDPNIOServerConnection bind(int port)
          Binds Transport to the specific port on localhost.
 UDPNIOServerConnection bind(java.net.SocketAddress socketAddress)
          Binds Transport to the specific SocketAddress.
 UDPNIOServerConnection bind(java.net.SocketAddress socketAddress, int backlog)
          Binds Transport to the specific SocketAddress.
 UDPNIOServerConnection bind(java.lang.String host, int port)
          Binds Transport to the specific host and port.
 UDPNIOServerConnection bind(java.lang.String host, int port, int backlog)
          Binds Transport to the specific host and port.
 UDPNIOServerConnection bind(java.lang.String host, PortRange portRange, int backlog)
          Binds Transport to the specific host, and port within a PortRange.
protected  void closeConnection(Connection connection)
          Close the connection, managed by Transport
protected  void configureNIOConnection(UDPNIOConnection connection)
           
 void configureStandalone(boolean isStandalone)
           
 GrizzlyFuture<Connection> connect()
          Creates non-connected UDP Connection.
 GrizzlyFuture<Connection> connect(java.net.SocketAddress remoteAddress)
          Creates, initializes and connects socket to the specific SocketAddress and returns Connection, representing socket.
 GrizzlyFuture<Connection> connect(java.net.SocketAddress remoteAddress, CompletionHandler<Connection> completionHandler)
          Creates, initializes and connects socket to the specific SocketAddress and returns Connection, representing socket.
 GrizzlyFuture<Connection> connect(java.net.SocketAddress remoteAddress, java.net.SocketAddress localAddress)
          Creates, initializes socket, binds it to the specific local and remote SocketAddress and returns Connection, representing socket.
 GrizzlyFuture<Connection> connect(java.net.SocketAddress remoteAddress, java.net.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(java.lang.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.
 Transport.IOEventReg fireIOEvent(IOEvent ioEvent, Connection connection, IOEventProcessingHandler processingHandler)
          Fires specific IOEvent on the Connection
 AsyncQueueIO getAsyncQueueIO()
          Get asynchronous queue implementation.
 int getConnectionTimeout()
           
 Reader getReader(boolean isBlocking)
          Get the Reader implementation, depending on the requested mode.
 Reader getReader(Connection connection)
          Get the Reader to read data from the Connection.
 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 getWriter(boolean isBlocking)
          Get the Writer implementation, depending on the requested mode.
 Writer getWriter(Connection connection)
          Get the Writer to write data to the Connection.
 boolean isReuseAddress()
           
 void pause()
          Pauses the transport
 int read(UDPNIOConnection connection, Buffer buffer)
           
 int read(UDPNIOConnection connection, Buffer buffer, ReadResult<Buffer,java.net.SocketAddress> currentResult)
           
 void resume()
          Resumes the transport after a pause
 void setConnectionTimeout(int connectionTimeout)
           
 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(UDPNIOConnection connection, java.net.SocketAddress dstAddress, Buffer buffer)
           
 int write(UDPNIOConnection connection, java.net.SocketAddress dstAddress, Buffer buffer, WriteResult<Buffer,java.net.SocketAddress> currentResult)
           
 
Methods inherited from class org.glassfish.grizzly.nio.NIOTransport
getNIOChannelDistributor, getSelectionKeyHandler, getSelectorHandler, getSelectorRunners, getSelectorRunnersCount, notifyProbesError, notifyProbesPause, notifyProbesResume, notifyProbesStart, notifyProbesStop, notifyTransportError, setNIOChannelDistributor, setSelectionKeyHandler, setSelectorHandler, 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
 

Field Detail

serverSocketSoTimeout

protected final int serverSocketSoTimeout
The server socket time out

See Also:
Constant Field Values

reuseAddress

protected boolean reuseAddress
The socket reuseAddress


connectionTimeout

protected int connectionTimeout
Default channel connection timeout


serverConnections

protected final java.util.Collection<UDPNIOServerConnection> serverConnections
The Server connections.


asyncQueueIO

protected final AsyncQueueIO<java.net.SocketAddress> asyncQueueIO
Transport AsyncQueueIO


temporarySelectorIO

protected TemporarySelectorIO temporarySelectorIO
Server socket backlog.


registerChannelCompletionHandler

protected final UDPNIOTransport.RegisterChannelCompletionHandler registerChannelCompletionHandler
Constructor Detail

UDPNIOTransport

public UDPNIOTransport()

UDPNIOTransport

public UDPNIOTransport(java.lang.String name)
Method Detail

bind

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

Specified by:
bind in interface SocketBinder
Returns:
bound Connection
Throws:
java.io.IOException

bind

public UDPNIOServerConnection bind(java.lang.String host,
                                   int port)
                            throws java.io.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:
java.io.IOException

bind

public UDPNIOServerConnection bind(java.lang.String host,
                                   int port,
                                   int backlog)
                            throws java.io.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:
java.io.IOException

bind

public UDPNIOServerConnection bind(java.net.SocketAddress socketAddress)
                            throws java.io.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:
java.io.IOException

bind

public UDPNIOServerConnection bind(java.net.SocketAddress socketAddress,
                                   int backlog)
                            throws java.io.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:
java.io.IOException

bind

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

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

unbind

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

Specified by:
unbind in interface SocketBinder
Parameters:
connection - Connection
Throws:
java.io.IOException

unbindAll

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

Specified by:
unbindAll in interface SocketBinder
Throws:
java.io.IOException

connect

public GrizzlyFuture<Connection> connect()
                                  throws java.io.IOException
Creates non-connected UDP Connection.

Returns:
non-connected UDP Connection.
Throws:
java.io.IOException

connect

public GrizzlyFuture<Connection> connect(java.lang.String host,
                                         int port)
                                  throws java.io.IOException
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.
Throws:
java.io.IOException

connect

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

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

connect

public GrizzlyFuture<Connection> connect(java.net.SocketAddress remoteAddress,
                                         CompletionHandler<Connection> completionHandler)
                                  throws java.io.IOException
Creates, initializes and connects socket to the specific SocketAddress and returns Connection, representing socket.

Specified by:
connect in interface ConnectorHandler<java.net.SocketAddress>
Parameters:
remoteAddress - remote address to connect to.
completionHandler - UDPNIOTransport.RegisterChannelCompletionHandler.
Returns:
GrizzlyFuture of connect operation, which could be used to get resulting Connection.
Throws:
java.io.IOException

connect

public GrizzlyFuture<Connection> connect(java.net.SocketAddress remoteAddress,
                                         java.net.SocketAddress localAddress)
                                  throws java.io.IOException
Creates, initializes socket, binds it to the specific local and remote SocketAddress and returns Connection, representing socket.

Specified by:
connect in interface ConnectorHandler<java.net.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.
Throws:
java.io.IOException

connect

public GrizzlyFuture<Connection> connect(java.net.SocketAddress remoteAddress,
                                         java.net.SocketAddress localAddress,
                                         CompletionHandler<Connection> completionHandler)
                                  throws java.io.IOException
Creates, initializes socket, binds it to the specific local and remote SocketAddress and returns Connection, representing socket.

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

closeConnection

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

Specified by:
closeConnection in class NIOTransport
Throws:
java.io.IOException

start

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

Specified by:
start in interface Transport
Specified by:
start in class AbstractTransport
Throws:
java.io.IOException

stop

public void stop()
          throws java.io.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:
java.io.IOException

pause

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

Specified by:
pause in interface Transport
Specified by:
pause in class AbstractTransport
Throws:
java.io.IOException

resume

public void resume()
            throws java.io.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:
java.io.IOException

configureStandalone

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

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.

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 Transport.IOEventReg fireIOEvent(IOEvent ioEvent,
                                        Connection connection,
                                        IOEventProcessingHandler processingHandler)
                                 throws java.io.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.
processingHandler - I/O event processing handler.
Throws:
java.io.IOException

getReader

public Reader 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 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 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 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 int read(UDPNIOConnection connection,
                Buffer buffer)
         throws java.io.IOException
Throws:
java.io.IOException

read

public int read(UDPNIOConnection connection,
                Buffer buffer,
                ReadResult<Buffer,java.net.SocketAddress> currentResult)
         throws java.io.IOException
Throws:
java.io.IOException

write

public int write(UDPNIOConnection connection,
                 java.net.SocketAddress dstAddress,
                 Buffer buffer)
          throws java.io.IOException
Throws:
java.io.IOException

write

public int write(UDPNIOConnection connection,
                 java.net.SocketAddress dstAddress,
                 Buffer buffer,
                 WriteResult<Buffer,java.net.SocketAddress> currentResult)
          throws java.io.IOException
Throws:
java.io.IOException

configureNIOConnection

protected void configureNIOConnection(UDPNIOConnection connection)

createJmxManagementObject

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

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


Copyright © 2011 Oracle Corpration. All Rights Reserved.