|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sun.grizzly.AbstractConnectorHandler<SelectorHandler,CallbackHandler>
com.sun.grizzly.connectioncache.client.CacheableConnectorHandler
public class CacheableConnectorHandler
Extended implementation of the DefaultSelectionKeyHandler with ConnectionManagement integrated in it
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 |
---|
public CacheableConnectorHandler(CacheableConnectorHandlerPool parentPool)
Method Detail |
---|
public void connect(SocketAddress remoteAddress, CallbackHandler callbackHandler, SelectorHandler selectorHandler) throws IOException
AbstractConnectorHandler
Controller
will invoke
the CallBackHandler.
connect
in interface ConnectorHandler<SelectorHandler,CallbackHandler>
connect
in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
remoteAddress
- remote address to connectcallbackHandler
- 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.
IOException
public void connect(SocketAddress remoteAddress, CallbackHandler callbackHandler) throws IOException
AbstractConnectorHandler
Controller
will invoke
the CallBackHandler.
connect
in interface ConnectorHandler<SelectorHandler,CallbackHandler>
connect
in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
remoteAddress
- remote address to connectcallbackHandler
- 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
.
IOException
public void connect(SocketAddress remoteAddress) throws IOException
AbstractConnectorHandler
connect
in interface ConnectorHandler<SelectorHandler,CallbackHandler>
connect
in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
remoteAddress
- remote address to connect
IOException
public void connect(SocketAddress remoteAddress, SocketAddress localAddress, CallbackHandler callbackHandler, SelectorHandler selectorHandler) throws IOException
ConnectorHandler
Controller
will invoke
the CallBackHandler.
remoteAddress
- remote address to connectlocalAddress
- local address to bindcallbackHandler
- the handler invoked by the Controller when
an non blocking operation is ready to be handled.selectorHandler
- SelectorHandler
IOException
public void connect(SocketAddress remoteAddress, SocketAddress localAddress, CallbackHandler callbackHandler) throws IOException
AbstractConnectorHandler
Controller
will invoke
the CallBackHandler.
connect
in interface ConnectorHandler<SelectorHandler,CallbackHandler>
connect
in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
remoteAddress
- remote address to connectlocalAddress
- local address to bindcallbackHandler
- 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
.
IOException
public void connect(SocketAddress remoteAddress, SocketAddress localAddress) throws IOException
ConnectorHandler
remoteAddress
- remote address to connectlocalAddress
- local address to bind
IOException
public void release(int expectedResponseCount)
CacheableConnectorHandler
, however this
CacheableConnectorHandler
will be still interested in getting
expectedResponseCount responses on it.
expectedResponseCount
- number of reponses expected on the connectionpublic void responseReceived()
public SelectorHandler getSelectorHandler()
AbstractConnectorHandler
SelectorHandler
.
getSelectorHandler
in interface ConnectorHandler<SelectorHandler,CallbackHandler>
getSelectorHandler
in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
SelectorHandler
.public SelectableChannel getUnderlyingChannel()
AbstractConnectorHandler
SelectableChannel
used.
getUnderlyingChannel
in interface ConnectorHandler<SelectorHandler,CallbackHandler>
getUnderlyingChannel
in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
SelectableChannel
used.public void forceClose() throws IOException
IOException
public void close() throws IOException
ConnectorHandler
IOException
public long read(ByteBuffer byteBuffer, boolean blocking) throws IOException
AbstractConnectorHandler
Selector
will be used to read bytes.
read
in interface ConnectorHandler<SelectorHandler,CallbackHandler>
read
in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
byteBuffer
- The byteBuffer to store bytes.blocking
- true if a a pool of temporary Selector
is required to handle a blocking read.
IOException
public long write(ByteBuffer byteBuffer, boolean blocking) throws IOException
AbstractConnectorHandler
Selector
will be used to writes bytes.
write
in interface ConnectorHandler<SelectorHandler,CallbackHandler>
write
in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
byteBuffer
- The byteBuffer to write.blocking
- true if a a pool of temporary Selector
is required to handle a blocking write.
IOException
public void finishConnect(SelectionKey key) throws IOException
ConnectorHandler
key
- SelectionKey
IOException
public boolean isConnected()
AbstractConnectorHandler
isConnected
in interface ConnectorHandler<SelectorHandler,CallbackHandler>
isConnected
in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
public boolean isReusing()
public ConnectorHandler getUnderlyingConnectorHandler()
public Future<AsyncQueueWriteUnit> writeToAsyncQueue(ByteBuffer buffer) throws IOException
AbstractConnectorHandler
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.
writeToAsyncQueue
in interface AsyncQueueWritable
writeToAsyncQueue
in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
buffer
- ByteBuffer
IOException
public Future<AsyncQueueWriteUnit> writeToAsyncQueue(ByteBuffer buffer, AsyncWriteCallbackHandler callbackHandler) throws IOException
AbstractConnectorHandler
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()
writeToAsyncQueue
in interface AsyncQueueWritable
writeToAsyncQueue
in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
buffer
- ByteBuffer
callbackHandler
- AsyncWriteCallbackHandler
,
which will get notified, when
ByteBuffer
will be completely written
IOException
public Future<AsyncQueueWriteUnit> writeToAsyncQueue(ByteBuffer buffer, AsyncWriteCallbackHandler callbackHandler, AsyncQueueDataProcessor writePreProcessor) throws IOException
AbstractConnectorHandler
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
.
writeToAsyncQueue
in interface AsyncQueueWritable
writeToAsyncQueue
in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
buffer
- ByteBuffer
callbackHandler
- AsyncWriteCallbackHandler
,
which will get notified, when
ByteBuffer
will be completely writtenwritePreProcessor
- AsyncQueueDataProcessor
, which
will perform data processing, before it will be
written on SelectableChannel
IOException
public Future<AsyncQueueWriteUnit> writeToAsyncQueue(ByteBuffer buffer, AsyncWriteCallbackHandler callbackHandler, AsyncQueueDataProcessor writePreProcessor, ByteBufferCloner cloner) throws IOException
AbstractConnectorHandler
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
.
writeToAsyncQueue
in interface AsyncQueueWritable
writeToAsyncQueue
in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
buffer
- ByteBuffer
callbackHandler
- AsyncWriteCallbackHandler
,
which will get notified, when
ByteBuffer
will be completely writtenwritePreProcessor
- AsyncQueueDataProcessor
, which
will perform data processing, before it will be
written on SelectableChannel
IOException
public Future<AsyncQueueWriteUnit> writeToAsyncQueue(SocketAddress dstAddress, ByteBuffer buffer) throws IOException
AbstractConnectorHandler
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.
writeToAsyncQueue
in interface AsyncQueueWritable
writeToAsyncQueue
in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
dstAddress
- destination SocketAddress
data will
be sent tobuffer
- ByteBuffer
IOException
public Future<AsyncQueueWriteUnit> writeToAsyncQueue(SocketAddress dstAddress, ByteBuffer buffer, AsyncWriteCallbackHandler callbackHandler) throws IOException
AbstractConnectorHandler
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()
writeToAsyncQueue
in interface AsyncQueueWritable
writeToAsyncQueue
in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
dstAddress
- destination SocketAddress
data will
be sent tobuffer
- ByteBuffer
callbackHandler
- AsyncWriteCallbackHandler
,
which will get notified, when
ByteBuffer
will be completely written
IOException
public Future<AsyncQueueWriteUnit> writeToAsyncQueue(SocketAddress dstAddress, ByteBuffer buffer, AsyncWriteCallbackHandler callbackHandler, AsyncQueueDataProcessor writePreProcessor) throws IOException
AbstractConnectorHandler
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
.
writeToAsyncQueue
in interface AsyncQueueWritable
writeToAsyncQueue
in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
dstAddress
- destination SocketAddress
data will
be sent tobuffer
- ByteBuffer
callbackHandler
- AsyncWriteCallbackHandler
,
which will get notified, when
ByteBuffer
will be completely writtenwritePreProcessor
- AsyncQueueDataProcessor
, which
will perform data processing, before it will be
written on SelectableChannel
IOException
public Future<AsyncQueueWriteUnit> writeToAsyncQueue(SocketAddress dstAddress, ByteBuffer buffer, AsyncWriteCallbackHandler callbackHandler, AsyncQueueDataProcessor writePreProcessor, ByteBufferCloner cloner) throws IOException
AbstractConnectorHandler
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
.
writeToAsyncQueue
in interface AsyncQueueWritable
writeToAsyncQueue
in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
dstAddress
- destination SocketAddress
data will
be sent tobuffer
- ByteBuffer
callbackHandler
- AsyncWriteCallbackHandler
,
which will get notified, when
ByteBuffer
will be completely writtenwritePreProcessor
- AsyncQueueDataProcessor
, which
will perform data processing, before it will be
written on SelectableChannel
IOException
public Future<AsyncQueueReadUnit> readFromAsyncQueue(ByteBuffer buffer, AsyncReadCallbackHandler callbackHandler) throws IOException
AbstractConnectorHandler
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()
readFromAsyncQueue
in interface AsyncQueueReadable
readFromAsyncQueue
in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
buffer
- ByteBuffer
callbackHandler
- AsyncReadCallbackHandler
,
which will get notified, when
ByteBuffer
will get full
ByteBuffer
was read completely,
false if read operation was put to queue
IOException
public Future<AsyncQueueReadUnit> readFromAsyncQueue(ByteBuffer buffer, AsyncReadCallbackHandler callbackHandler, AsyncReadCondition condition) throws IOException
AbstractConnectorHandler
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()
readFromAsyncQueue
in interface AsyncQueueReadable
readFromAsyncQueue
in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
buffer
- ByteBuffer
callbackHandler
- AsyncReadCallbackHandler
,
which will get notified, when
ByteBuffer
will get fullcondition
- AsyncReadCondition
, which will be called to
check if read data is complete, and callbackHandler could
be called
ByteBuffer
was read completely,
false if read operation was put to queue
IOException
public Future<AsyncQueueReadUnit> readFromAsyncQueue(ByteBuffer buffer, AsyncReadCallbackHandler callbackHandler, AsyncReadCondition condition, AsyncQueueDataProcessor readPostProcessor) throws IOException
AbstractConnectorHandler
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()
readFromAsyncQueue
in interface AsyncQueueReadable
readFromAsyncQueue
in class AbstractConnectorHandler<SelectorHandler,CallbackHandler>
buffer
- ByteBuffer
callbackHandler
- AsyncReadCallbackHandler
,
which will get notified, when
ByteBuffer
will get fullcondition
- AsyncReadCondition
, which will be called to
check if read data is complete, and callbackHandler could
be calledreadPostProcessor
- post processor, to be called to process read data
ByteBuffer
was read completely,
false if read operation was put to queue
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |