com.sun.grizzly.nio.transport
Class UDPNIOConnection

java.lang.Object
  extended by com.sun.grizzly.nio.AbstractNIOConnection
      extended by com.sun.grizzly.nio.transport.UDPNIOConnection
All Implemented Interfaces:
AttributeStorage, Connection<SocketAddress>, NIOConnection, Readable<SocketAddress>, Writable<SocketAddress>, Closeable
Direct Known Subclasses:
UDPNIOServerConnection

public class UDPNIOConnection
extends AbstractNIOConnection

Connection implementation for the UDPNIOTransport

Author:
Alexey Stashok

Field Summary
 
Fields inherited from class com.sun.grizzly.nio.AbstractNIOConnection
asyncReadQueue, asyncWriteQueue, attributes, channel, isBlocking, isClosed, processor, processorSelector, readBufferSize, selectionKey, selectorRunner, transport, writeBufferSize
 
Constructor Summary
UDPNIOConnection(UDPNIOTransport transport, DatagramChannel channel)
           
 
Method Summary
 SocketAddress getLocalAddress()
          Returns the local address of this Connection, or null if it is unconnected.
 SocketAddress getPeerAddress()
          Returns the address of the endpoint this Connection is connected to, or null if it is unconnected.
 StreamReader getStreamReader()
          Get the Connection StreamReader, to read data from the Connection.
 StreamWriter getStreamWriter()
          Get the Connection StreamWriter, to write data to the Connection.
 boolean isConnected()
           
protected  void preClose()
           
 Future<ReadResult<Buffer,SocketAddress>> read(Buffer buffer, CompletionHandler<ReadResult<Buffer,SocketAddress>> completionHandler, Condition<ReadResult<Buffer,SocketAddress>> condition)
          Method reads data to the buffer.
 Future register()
           
 void setReadBufferSize(int readBufferSize)
          Set the default size of Buffers, which will be allocated for reading data from Connection.
protected  void setSelectionKey(SelectionKey selectionKey)
           
protected  void setSelectorRunner(SelectorRunner selectorRunner)
           
 void setWriteBufferSize(int writeBufferSize)
          Set the default size of Buffers, which will be allocated for writing data to Connection.
 Future<WriteResult<Buffer,SocketAddress>> write(SocketAddress dstAddress, Buffer buffer, CompletionHandler<WriteResult<Buffer,SocketAddress>> completionHandler)
          Method writes the buffer to the specific address.
 
Methods inherited from class com.sun.grizzly.nio.AbstractNIOConnection
close, configureBlocking, disableIOEvent, enableIOEvent, getAsyncReadQueue, getAsyncWriteQueue, getAttributes, getChannel, getProcessor, getProcessorSelector, getReadBufferSize, getSelectionKey, getSelectorRunner, getTransport, getWriteBufferSize, isBlocking, isOpen, obtainAttributes, read, read, read, setChannel, setProcessor, setProcessorSelector, write, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UDPNIOConnection

public UDPNIOConnection(UDPNIOTransport transport,
                        DatagramChannel channel)
Method Detail

isConnected

public boolean isConnected()

register

public Future register()
                throws IOException
Throws:
IOException

setSelectionKey

protected void setSelectionKey(SelectionKey selectionKey)
Overrides:
setSelectionKey in class AbstractNIOConnection

setSelectorRunner

protected void setSelectorRunner(SelectorRunner selectorRunner)
Overrides:
setSelectorRunner in class AbstractNIOConnection

getStreamReader

public StreamReader getStreamReader()
Description copied from interface: Connection
Get the Connection StreamReader, to read data from the Connection.

Returns:
the Connection StreamReader, to read data from the Connection.

getStreamWriter

public StreamWriter getStreamWriter()
Description copied from interface: Connection
Get the Connection StreamWriter, to write data to the Connection.

Returns:
the Connection StreamWriter, to write data to the Connection.

preClose

protected void preClose()
Specified by:
preClose in class AbstractNIOConnection

getPeerAddress

public SocketAddress getPeerAddress()
Returns the address of the endpoint this Connection is connected to, or null if it is unconnected.

Returns:
the address of the endpoint this Connection is connected to, or null if it is unconnected.

getLocalAddress

public SocketAddress getLocalAddress()
Returns the local address of this Connection, or null if it is unconnected.

Returns:
the local address of this Connection, or null if it is unconnected.

setReadBufferSize

public void setReadBufferSize(int readBufferSize)
Description copied from interface: Connection
Set the default size of Buffers, which will be allocated for reading data from Connection.

Specified by:
setReadBufferSize in interface Connection<SocketAddress>
Overrides:
setReadBufferSize in class AbstractNIOConnection
Parameters:
readBufferSize - the default size of Buffers, which will be allocated for reading data from Connection.

setWriteBufferSize

public void setWriteBufferSize(int writeBufferSize)
Description copied from interface: Connection
Set the default size of Buffers, which will be allocated for writing data to Connection.

Specified by:
setWriteBufferSize in interface Connection<SocketAddress>
Overrides:
setWriteBufferSize in class AbstractNIOConnection
Parameters:
writeBufferSize - the default size of Buffers, which will be allocated for writing data to Connection.

read

public Future<ReadResult<Buffer,SocketAddress>> read(Buffer buffer,
                                                     CompletionHandler<ReadResult<Buffer,SocketAddress>> completionHandler,
                                                     Condition<ReadResult<Buffer,SocketAddress>> condition)
                                              throws IOException
Description copied from interface: Readable
Method reads data to the buffer.

Parameters:
buffer - the buffer, where data will be read
completionHandler - CompletionHandler, which will get notified, when read will be completed
condition - Condition, which will be checked each time new portion of a data was read to a buffer. The condition can decide, whether asynchronous read is completed or not.
Returns:
Future, using which it's possible to check the result
Throws:
IOException

write

public Future<WriteResult<Buffer,SocketAddress>> write(SocketAddress dstAddress,
                                                       Buffer buffer,
                                                       CompletionHandler<WriteResult<Buffer,SocketAddress>> completionHandler)
                                                throws IOException
Description copied from interface: Writable
Method writes the buffer to the specific address.

Parameters:
dstAddress - the destination address the buffer will be sent to
buffer - the buffer, from which the data will be written
completionHandler - CompletionHandler, which will get notified, when write will be completed
Returns:
Future, using which it's possible to check the result
Throws:
IOException


Copyright © 2009 SUN Microsystems. All Rights Reserved.