com.sun.grizzly.nio.transport
Class TCPNIOConnection

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

public class TCPNIOConnection
extends AbstractNIOConnection

Connection implementation for the TCPNIOTransport

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
TCPNIOConnection(TCPNIOTransport transport, SelectableChannel 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.
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.
protected  void resetAddresses()
           
protected  void setSelectionKey(SelectionKey selectionKey)
           
protected  void setSelectorRunner(SelectorRunner selectorRunner)
           
 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, setReadBufferSize, setWriteBufferSize, write, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TCPNIOConnection

public TCPNIOConnection(TCPNIOTransport transport,
                        SelectableChannel channel)
Method Detail

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.

resetAddresses

protected void resetAddresses()

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.