com.sun.grizzly.connectioncache.client
Class CacheableConnectorHandler

java.lang.Object
  extended by com.sun.grizzly.AbstractConnectorHandler<SelectorHandler,CallbackHandler>
      extended by com.sun.grizzly.connectioncache.client.CacheableConnectorHandler
All Implemented Interfaces:
AsyncQueueReadable, AsyncQueueWritable, ConnectorHandler<SelectorHandler,CallbackHandler>, Handler, Closeable

public class CacheableConnectorHandler
extends AbstractConnectorHandler<SelectorHandler,CallbackHandler>

Extended implementation of the DefaultSelectionKeyHandler with ConnectionManagement integrated in it

Author:
Alexey Stashok

Field Summary
 
Fields inherited from class com.sun.grizzly.AbstractConnectorHandler
callbackHandler, controller, inputStream, isConnected, protocol, selectorHandler, underlyingChannel
 
Constructor Summary
CacheableConnectorHandler(CacheableConnectorHandlerPool parentPool)
           
 
Method Summary
 void close()
          Close the underlying connection.
 void connect(SocketAddress remoteAddress)
          Connect to hostname:port.
 void connect(SocketAddress remoteAddress, CallbackHandler callbackHandler)
          Connect to hostname:port.
 void connect(SocketAddress remoteAddress, CallbackHandler callbackHandler, SelectorHandler selectorHandler)
          Connect to hostname:port.
 void connect(SocketAddress remoteAddress, SocketAddress localAddress)
          Connect to hostname:port.
 void connect(SocketAddress remoteAddress, SocketAddress localAddress, CallbackHandler callbackHandler)
          Connect to hostname:port.
 void connect(SocketAddress remoteAddress, SocketAddress localAddress, CallbackHandler callbackHandler, SelectorHandler selectorHandler)
          Connect to hostname:port.
 void finishConnect(SelectionKey key)
          Decide how the OP_CONNECT final steps are handled.
 void forceClose()
           
 SelectorHandler getSelectorHandler()
          Return the associated SelectorHandler.
 SelectableChannel getUnderlyingChannel()
          Return the current SelectableChannel used.
 ConnectorHandler getUnderlyingConnectorHandler()
           
 boolean isConnected()
          Is the underlying channel connected.
 boolean isReusing()
          Return true if underlying connection was take from cache and going to be reused by this CacheableConnectorHandler, otherwise return false, if underlying connection was just created and connected.
 long read(ByteBuffer byteBuffer, boolean blocking)
          Read bytes.
 Future<AsyncQueueReadUnit> readFromAsyncQueue(ByteBuffer buffer, AsyncReadCallbackHandler callbackHandler)
          Method reads data to the ByteBuffer using async read queue.
 Future<AsyncQueueReadUnit> readFromAsyncQueue(ByteBuffer buffer, AsyncReadCallbackHandler callbackHandler, AsyncReadCondition condition)
          Method reads data to the ByteBuffer using async read queue.
 Future<AsyncQueueReadUnit> readFromAsyncQueue(ByteBuffer buffer, AsyncReadCallbackHandler callbackHandler, AsyncReadCondition condition, AsyncQueueDataProcessor readPostProcessor)
          Method reads data to the ByteBuffer using async read queue.
 void release(int expectedResponseCount)
          Releases underlying connection, which means it could be reused for writing by other CacheableConnectorHandler, however this CacheableConnectorHandler will be still interested in getting expectedResponseCount responses on it.
 void responseReceived()
          Notifies connection cache, that response was received.
 long write(ByteBuffer byteBuffer, boolean blocking)
          Writes bytes.
 Future<AsyncQueueWriteUnit> writeToAsyncQueue(ByteBuffer buffer)
          Method writes ByteBuffer using async write queue.
 Future<AsyncQueueWriteUnit> writeToAsyncQueue(ByteBuffer buffer, AsyncWriteCallbackHandler callbackHandler)
          Method writes ByteBuffer using async write queue.
 Future<AsyncQueueWriteUnit> writeToAsyncQueue(ByteBuffer buffer, AsyncWriteCallbackHandler callbackHandler, AsyncQueueDataProcessor writePreProcessor)
          Method writes ByteBuffer using async write queue.
 Future<AsyncQueueWriteUnit> writeToAsyncQueue(ByteBuffer buffer, AsyncWriteCallbackHandler callbackHandler, AsyncQueueDataProcessor writePreProcessor, ByteBufferCloner cloner)
          Method writes ByteBuffer using async write queue.
 Future<AsyncQueueWriteUnit> writeToAsyncQueue(SocketAddress dstAddress, ByteBuffer buffer)
          Method sends ByteBuffer using async write queue.
 Future<AsyncQueueWriteUnit> writeToAsyncQueue(SocketAddress dstAddress, ByteBuffer buffer, AsyncWriteCallbackHandler callbackHandler)
          Method sends ByteBuffer using async write queue.
 Future<AsyncQueueWriteUnit> writeToAsyncQueue(SocketAddress dstAddress, ByteBuffer buffer, AsyncWriteCallbackHandler callbackHandler, AsyncQueueDataProcessor writePreProcessor)
          Method sends ByteBuffer using async write queue.
 Future<AsyncQueueWriteUnit> writeToAsyncQueue(SocketAddress dstAddress, ByteBuffer buffer, AsyncWriteCallbackHandler callbackHandler, AsyncQueueDataProcessor writePreProcessor, ByteBufferCloner cloner)
          Method sends ByteBuffer using async write queue.
 
Methods inherited from class com.sun.grizzly.AbstractConnectorHandler
getCallbackHandler, getController, protocol, protocol, setCallbackHandler, setController, setSelectorHandler, setUnderlyingChannel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CacheableConnectorHandler

public CacheableConnectorHandler(CacheableConnectorHandlerPool parentPool)
Method Detail

connect

public void connect(SocketAddress remoteAddress,
                    CallbackHandler callbackHandler,
                    SelectorHandler selectorHandler)
             throws IOException
Description copied from class: AbstractConnectorHandler
Connect to hostname:port. When an aysnchronous event happens (e.g OP_READ or OP_WRITE), the Controller will invoke the CallBackHandler.

Specified by:
connect in interface ConnectorHandler<SelectorHandler,CallbackHandler>
Overrides:
connect in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
Parameters:
remoteAddress - remote address to connect
callbackHandler - the handler invoked by its associated SelectorHandler when a non blocking operation is ready to be handled. When null, all read and write operation will be delegated to the default ProtocolChain and its list of ProtocolFilter . When null, this ConnectorHandler will create an instance of DefaultCallbackHandler.
selectorHandler - an instance of SelectorHandler.
Throws:
IOException

connect

public void connect(SocketAddress remoteAddress,
                    CallbackHandler callbackHandler)
             throws IOException
Description copied from class: AbstractConnectorHandler
Connect to hostname:port. When an aysnchronous event happens (e.g OP_READ or OP_WRITE), the Controller will invoke the CallBackHandler.

Specified by:
connect in interface ConnectorHandler<SelectorHandler,CallbackHandler>
Overrides:
connect in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
Parameters:
remoteAddress - remote address to connect
callbackHandler - the handler invoked by its associated SelectorHandler when a non blocking operation is ready to be handled. When null, all read and write operation will be delegated to the default ProtocolChain and its list of ProtocolFilter . When null, this ConnectorHandler will create an instance of DefaultCallbackHandler.
Throws:
IOException

connect

public void connect(SocketAddress remoteAddress)
             throws IOException
Description copied from class: AbstractConnectorHandler
Connect to hostname:port. Internally an instance of Controller and its default SelectorHandler will be created everytime this method is called. This method should be used only and only if no external Controller has been initialized.

Specified by:
connect in interface ConnectorHandler<SelectorHandler,CallbackHandler>
Overrides:
connect in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
Parameters:
remoteAddress - remote address to connect
Throws:
IOException

connect

public void connect(SocketAddress remoteAddress,
                    SocketAddress localAddress,
                    CallbackHandler callbackHandler,
                    SelectorHandler selectorHandler)
             throws IOException
Description copied from interface: ConnectorHandler
Connect to hostname:port. When an aysnchronous event happens (e.g OP_READ or OP_WRITE), the Controller will invoke the CallBackHandler.

Parameters:
remoteAddress - remote address to connect
localAddress - local address to bind
callbackHandler - the handler invoked by the Controller when an non blocking operation is ready to be handled.
selectorHandler - SelectorHandler
Throws:
IOException

connect

public void connect(SocketAddress remoteAddress,
                    SocketAddress localAddress,
                    CallbackHandler callbackHandler)
             throws IOException
Description copied from class: AbstractConnectorHandler
Connect to hostname:port. When an aysnchronous event happens (e.g OP_READ or OP_WRITE), the Controller will invoke the CallBackHandler.

Specified by:
connect in interface ConnectorHandler<SelectorHandler,CallbackHandler>
Overrides:
connect in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
Parameters:
remoteAddress - remote address to connect
localAddress - local address to bind
callbackHandler - the handler invoked by its associated SelectorHandler when a non blocking operation is ready to be handled. When null, all read and write operation will be delegated to the default ProtocolChain and its list of ProtocolFilter . When null, this ConnectorHandler will create an instance of DefaultCallbackHandler.
Throws:
IOException

connect

public void connect(SocketAddress remoteAddress,
                    SocketAddress localAddress)
             throws IOException
Description copied from interface: ConnectorHandler
Connect to hostname:port. Internally an instance of Controller and its default SelectorHandler will be created everytime this method is called. This method should be used only and only if no external Controller has been initialized.

Parameters:
remoteAddress - remote address to connect
localAddress - local address to bind
Throws:
IOException

release

public void release(int expectedResponseCount)
Releases underlying connection, which means it could be reused for writing by other CacheableConnectorHandler, however this CacheableConnectorHandler will be still interested in getting expectedResponseCount responses on it.

Parameters:
expectedResponseCount - number of reponses expected on the connection

responseReceived

public void responseReceived()
Notifies connection cache, that response was received. And connection cache could decrease expected response counter by 1


getSelectorHandler

public SelectorHandler getSelectorHandler()
Description copied from class: AbstractConnectorHandler
Return the associated SelectorHandler.

Specified by:
getSelectorHandler in interface ConnectorHandler<SelectorHandler,CallbackHandler>
Overrides:
getSelectorHandler in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
Returns:
the associated SelectorHandler.

getUnderlyingChannel

public SelectableChannel getUnderlyingChannel()
Description copied from class: AbstractConnectorHandler
Return the current SelectableChannel used.

Specified by:
getUnderlyingChannel in interface ConnectorHandler<SelectorHandler,CallbackHandler>
Overrides:
getUnderlyingChannel in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
Returns:
the current SelectableChannel used.

forceClose

public void forceClose()
                throws IOException
Throws:
IOException

close

public void close()
           throws IOException
Description copied from interface: ConnectorHandler
Close the underlying connection.

Throws:
IOException

read

public long read(ByteBuffer byteBuffer,
                 boolean blocking)
          throws IOException
Description copied from class: AbstractConnectorHandler
Read bytes. If blocking is set to true, a pool of temporary Selector will be used to read bytes.

Specified by:
read in interface ConnectorHandler<SelectorHandler,CallbackHandler>
Overrides:
read in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
Parameters:
byteBuffer - The byteBuffer to store bytes.
blocking - true if a a pool of temporary Selector is required to handle a blocking read.
Returns:
number of bytes read
Throws:
IOException

write

public long write(ByteBuffer byteBuffer,
                  boolean blocking)
           throws IOException
Description copied from class: AbstractConnectorHandler
Writes bytes. If blocking is set to true, a pool of temporary Selector will be used to writes bytes.

Specified by:
write in interface ConnectorHandler<SelectorHandler,CallbackHandler>
Overrides:
write in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
Parameters:
byteBuffer - The byteBuffer to write.
blocking - true if a a pool of temporary Selector is required to handle a blocking write.
Returns:
number of bytes written
Throws:
IOException

finishConnect

public void finishConnect(SelectionKey key)
                   throws IOException
Description copied from interface: ConnectorHandler
Decide how the OP_CONNECT final steps are handled.

Parameters:
key - SelectionKey
Throws:
IOException

isConnected

public boolean isConnected()
Description copied from class: AbstractConnectorHandler
Is the underlying channel connected.

Specified by:
isConnected in interface ConnectorHandler<SelectorHandler,CallbackHandler>
Overrides:
isConnected in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
Returns:
true if connected, otherwise false

isReusing

public boolean isReusing()
Return true if underlying connection was take from cache and going to be reused by this CacheableConnectorHandler, otherwise return false, if underlying connection was just created and connected.

Returns:
true if underlying connection was take from cache and going to be reused by this CacheableConnectorHandler, otherwise return false, if underlying connection was just created and connected.

getUnderlyingConnectorHandler

public ConnectorHandler getUnderlyingConnectorHandler()

writeToAsyncQueue

public Future<AsyncQueueWriteUnit> writeToAsyncQueue(ByteBuffer buffer)
                                              throws IOException
Description copied from class: AbstractConnectorHandler
Method writes ByteBuffer using async write queue. First, if write queue is empty - it tries to write ByteBuffer directly (without putting to the queue). If associated write queue is not empty or after direct writing ByteBuffer still has ready data to be written - ByteBuffer will be added to AsyncQueue. If an exception occurs, during direct writing - it will be propagated to the caller directly, otherwise it will be just logged by Grizzly framework.

Specified by:
writeToAsyncQueue in interface AsyncQueueWritable
Overrides:
writeToAsyncQueue in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
Parameters:
buffer - ByteBuffer
Throws:
IOException

writeToAsyncQueue

public Future<AsyncQueueWriteUnit> writeToAsyncQueue(ByteBuffer buffer,
                                                     AsyncWriteCallbackHandler callbackHandler)
                                              throws IOException
Description copied from class: AbstractConnectorHandler
Method writes ByteBuffer using async write queue. First, if write queue is empty - it tries to write ByteBuffer directly (without putting to the queue). If associated write queue is not empty or after direct writing ByteBuffer still has ready data to be written - ByteBuffer will be added to AsyncQueue. If an exception occurs, during direct writing - it will be propagated to the caller directly, otherwise, if the ByteBuffer is added to a writing queue - exception notification will come via AsyncWriteCallbackHandler.onIOException()

Specified by:
writeToAsyncQueue in interface AsyncQueueWritable
Overrides:
writeToAsyncQueue in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
Parameters:
buffer - ByteBuffer
callbackHandler - AsyncWriteCallbackHandler, which will get notified, when ByteBuffer will be completely written
Throws:
IOException

writeToAsyncQueue

public Future<AsyncQueueWriteUnit> writeToAsyncQueue(ByteBuffer buffer,
                                                     AsyncWriteCallbackHandler callbackHandler,
                                                     AsyncQueueDataProcessor writePreProcessor)
                                              throws IOException
Description copied from class: AbstractConnectorHandler
Method writes ByteBuffer using async write queue. First, if write queue is empty - it tries to write ByteBuffer directly (without putting to the queue). If associated write queue is not empty or after direct writing ByteBuffer still has ready data to be written - ByteBuffer will be added to AsyncQueue. If an exception occurs, during direct writing - it will be propagated to the caller directly, otherwise, if the ByteBuffer is added to a writing queue - exception notification will come via AsyncWriteCallbackHandler.onIOException() Before data will be written on SelectableChannel, first it will be passed for preprocessing to AsyncQueueDataProcessor, and then preprocessor result data (AsyncQueueDataProcessor.getResultByteBuffer()) will be written on the SelectableChannel.

Specified by:
writeToAsyncQueue in interface AsyncQueueWritable
Overrides:
writeToAsyncQueue in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
Parameters:
buffer - ByteBuffer
callbackHandler - AsyncWriteCallbackHandler, which will get notified, when ByteBuffer will be completely written
writePreProcessor - AsyncQueueDataProcessor, which will perform data processing, before it will be written on SelectableChannel
Throws:
IOException

writeToAsyncQueue

public Future<AsyncQueueWriteUnit> writeToAsyncQueue(ByteBuffer buffer,
                                                     AsyncWriteCallbackHandler callbackHandler,
                                                     AsyncQueueDataProcessor writePreProcessor,
                                                     ByteBufferCloner cloner)
                                              throws IOException
Description copied from class: AbstractConnectorHandler
Method writes ByteBuffer using async write queue. First, if write queue is empty - it tries to write ByteBuffer directly (without putting to the queue). If associated write queue is not empty or after direct writing ByteBuffer still has ready data to be written - ByteBuffer will be added to AsyncQueue. If an exception occurs, during direct writing - it will be propagated to the caller directly, otherwise, if the ByteBuffer is added to a writing queue - exception notification will come via AsyncWriteCallbackHandler.onIOException() Before data will be written on SelectableChannel, first it will be passed for preprocessing to AsyncQueueDataProcessor, and then preprocessor result data (AsyncQueueDataProcessor.getResultByteBuffer()) will be written on the SelectableChannel.

Specified by:
writeToAsyncQueue in interface AsyncQueueWritable
Overrides:
writeToAsyncQueue in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
Parameters:
buffer - ByteBuffer
callbackHandler - AsyncWriteCallbackHandler, which will get notified, when ByteBuffer will be completely written
writePreProcessor - AsyncQueueDataProcessor, which will perform data processing, before it will be written on SelectableChannel
Throws:
IOException

writeToAsyncQueue

public Future<AsyncQueueWriteUnit> writeToAsyncQueue(SocketAddress dstAddress,
                                                     ByteBuffer buffer)
                                              throws IOException
Description copied from class: AbstractConnectorHandler
Method sends ByteBuffer using async write queue. First, if write queue is empty - it tries to send ByteBuffer to the given SocketAddress directly (without putting to the queue). If associated write queue is not empty or after direct sending ByteBuffer still has ready data to be written - ByteBuffer will be added to AsyncQueue. If an exception occurs, during direct writing - it will be propagated to the caller directly, otherwise it will be just logged by Grizzly framework.

Specified by:
writeToAsyncQueue in interface AsyncQueueWritable
Overrides:
writeToAsyncQueue in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
Parameters:
dstAddress - destination SocketAddress data will be sent to
buffer - ByteBuffer
Throws:
IOException

writeToAsyncQueue

public Future<AsyncQueueWriteUnit> writeToAsyncQueue(SocketAddress dstAddress,
                                                     ByteBuffer buffer,
                                                     AsyncWriteCallbackHandler callbackHandler)
                                              throws IOException
Description copied from class: AbstractConnectorHandler
Method sends ByteBuffer using async write queue. First, if write queue is empty - it tries to send ByteBuffer to the given SocketAddress directly (without putting to the queue). If associated write queue is not empty or after direct sending ByteBuffer still has ready data to be written - ByteBuffer will be added to AsyncQueue. If an exception occurs, during direct writing - it will be propagated to the caller directly, otherwise, if the ByteBuffer is added to a writing queue - exception notification will come via AsyncWriteCallbackHandler.onIOException()

Specified by:
writeToAsyncQueue in interface AsyncQueueWritable
Overrides:
writeToAsyncQueue in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
Parameters:
dstAddress - destination SocketAddress data will be sent to
buffer - ByteBuffer
callbackHandler - AsyncWriteCallbackHandler, which will get notified, when ByteBuffer will be completely written
Throws:
IOException

writeToAsyncQueue

public Future<AsyncQueueWriteUnit> writeToAsyncQueue(SocketAddress dstAddress,
                                                     ByteBuffer buffer,
                                                     AsyncWriteCallbackHandler callbackHandler,
                                                     AsyncQueueDataProcessor writePreProcessor)
                                              throws IOException
Description copied from class: AbstractConnectorHandler
Method sends ByteBuffer using async write queue. First, if write queue is empty - it tries to send ByteBuffer to the given SocketAddress directly (without putting to the queue). If associated write queue is not empty or after direct sending ByteBuffer still has ready data to be written - ByteBuffer will be added to AsyncQueue. If an exception occurs, during direct writing - it will be propagated to the caller directly, otherwise, if the ByteBuffer is added to a writing queue - exception notification will come via AsyncWriteCallbackHandler.onIOException() Before data will be written on SelectableChannel, first it will be passed for preprocessing to AsyncQueueDataProcessor, and then preprocessor result data (AsyncQueueDataProcessor.getResultByteBuffer()) will be written on the SelectableChannel.

Specified by:
writeToAsyncQueue in interface AsyncQueueWritable
Overrides:
writeToAsyncQueue in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
Parameters:
dstAddress - destination SocketAddress data will be sent to
buffer - ByteBuffer
callbackHandler - AsyncWriteCallbackHandler, which will get notified, when ByteBuffer will be completely written
writePreProcessor - AsyncQueueDataProcessor, which will perform data processing, before it will be written on SelectableChannel
Throws:
IOException

writeToAsyncQueue

public Future<AsyncQueueWriteUnit> writeToAsyncQueue(SocketAddress dstAddress,
                                                     ByteBuffer buffer,
                                                     AsyncWriteCallbackHandler callbackHandler,
                                                     AsyncQueueDataProcessor writePreProcessor,
                                                     ByteBufferCloner cloner)
                                              throws IOException
Description copied from class: AbstractConnectorHandler
Method sends ByteBuffer using async write queue. First, if write queue is empty - it tries to send ByteBuffer to the given SocketAddress directly (without putting to the queue). If associated write queue is not empty or after direct sending ByteBuffer still has ready data to be written - ByteBuffer will be added to AsyncQueue. If an exception occurs, during direct writing - it will be propagated to the caller directly, otherwise, if the ByteBuffer is added to a writing queue - exception notification will come via AsyncWriteCallbackHandler.onIOException() Before data will be written on SelectableChannel, first it will be passed for preprocessing to AsyncQueueDataProcessor, and then preprocessor result data (AsyncQueueDataProcessor.getResultByteBuffer()) will be written on the SelectableChannel.

Specified by:
writeToAsyncQueue in interface AsyncQueueWritable
Overrides:
writeToAsyncQueue in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
Parameters:
dstAddress - destination SocketAddress data will be sent to
buffer - ByteBuffer
callbackHandler - AsyncWriteCallbackHandler, which will get notified, when ByteBuffer will be completely written
writePreProcessor - AsyncQueueDataProcessor, which will perform data processing, before it will be written on SelectableChannel
Throws:
IOException

readFromAsyncQueue

public Future<AsyncQueueReadUnit> readFromAsyncQueue(ByteBuffer buffer,
                                                     AsyncReadCallbackHandler callbackHandler)
                                              throws IOException
Description copied from class: AbstractConnectorHandler
Method reads data to the ByteBuffer using async read queue. First, if read queue is empty - it tries to read to the ByteBuffer directly (without putting to the queue). If associated read queue is not empty or after direct reading ByteBuffer still has remaining place for next read - ByteBuffer will be added to AsyncQueue. If an exception occurs, during direct reading - it will be propagated to the caller directly, otherwise, if the ByteBuffer is added to a reading queue - exception notification will come via AsyncReadCallbackHandler.onIOException()

Specified by:
readFromAsyncQueue in interface AsyncQueueReadable
Overrides:
readFromAsyncQueue in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
Parameters:
buffer - ByteBuffer
callbackHandler - AsyncReadCallbackHandler, which will get notified, when ByteBuffer will get full
Returns:
true, if ByteBuffer was read completely, false if read operation was put to queue
Throws:
IOException

readFromAsyncQueue

public Future<AsyncQueueReadUnit> readFromAsyncQueue(ByteBuffer buffer,
                                                     AsyncReadCallbackHandler callbackHandler,
                                                     AsyncReadCondition condition)
                                              throws IOException
Description copied from class: AbstractConnectorHandler
Method reads data to the ByteBuffer using async read queue. First, if read queue is empty - it tries to read to the ByteBuffer directly (without putting to the queue). If associated read queue is not empty or after direct reading ByteBuffer still has remaining place for next read - ByteBuffer will be added to AsyncQueue. If an exception occurs, during direct reading - it will be propagated to the caller directly, otherwise, if the ByteBuffer is added to a reading queue - exception notification will come via AsyncReadCallbackHandler.onIOException()

Specified by:
readFromAsyncQueue in interface AsyncQueueReadable
Overrides:
readFromAsyncQueue in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
Parameters:
buffer - ByteBuffer
callbackHandler - AsyncReadCallbackHandler, which will get notified, when ByteBuffer will get full
condition - AsyncReadCondition, which will be called to check if read data is complete, and callbackHandler could be called
Returns:
true, if ByteBuffer was read completely, false if read operation was put to queue
Throws:
IOException

readFromAsyncQueue

public Future<AsyncQueueReadUnit> readFromAsyncQueue(ByteBuffer buffer,
                                                     AsyncReadCallbackHandler callbackHandler,
                                                     AsyncReadCondition condition,
                                                     AsyncQueueDataProcessor readPostProcessor)
                                              throws IOException
Description copied from class: AbstractConnectorHandler
Method reads data to the ByteBuffer using async read queue. First, if read queue is empty - it tries to read to the ByteBuffer directly (without putting to the queue). If associated read queue is not empty or after direct reading ByteBuffer still has remaining place for next read - ByteBuffer will be added to AsyncQueue. If an exception occurs, during direct reading - it will be propagated to the caller directly, otherwise, if the ByteBuffer is added to a reading queue - exception notification will come via AsyncReadCallbackHandler.onIOException()

Specified by:
readFromAsyncQueue in interface AsyncQueueReadable
Overrides:
readFromAsyncQueue in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
Parameters:
buffer - ByteBuffer
callbackHandler - AsyncReadCallbackHandler, which will get notified, when ByteBuffer will get full
condition - AsyncReadCondition, which will be called to check if read data is complete, and callbackHandler could be called
readPostProcessor - post processor, to be called to process read data
Returns:
true, if ByteBuffer was read completely, false if read operation was put to queue
Throws:
IOException


Copyright © 2013 Oracle Corporation. All Rights Reserved.