|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.sun.grizzly.UDPConnectorHandler
public class UDPConnectorHandler
Client side interface used to implement non blocking client operation. Implementation of this class must make sure the following methods are invoked in that order:
(1) connect()
(2) read() or write().
| Field Summary | |
|---|---|
protected CallbackHandler |
callbackHandler
A CallbackHandler handler invoked by the UDPSelectorHandler
when a non blocking operation is ready to be processed. |
protected Controller |
controller
The internal Controller used (in case not specified). |
protected DatagramChannel |
datagramChannel
The connection's DatagramChannel. |
protected ByteBufferInputStream |
inputStream
A blocking InputStream that use a pool of Selector
to execute a blocking read operation. |
protected boolean |
isConnected
Is the connection established. |
protected CountDownLatch |
isConnectedLatch
IsConnected Latch related |
protected UDPSelectorHandler |
selectorHandler
The underlying UDPSelectorHandler used to mange SelectionKeys. |
| Constructor Summary | |
|---|---|
UDPConnectorHandler()
|
|
| 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,
UDPSelectorHandler 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,
UDPSelectorHandler selectorHandler)
Connect to hostname:port. |
void |
finishConnect(SelectionKey key)
Finish handling the OP_CONNECT interest ops. |
CallbackHandler |
getCallbackHandler()
Returns ConnectorHandler's callback handler instance,
which is used to process occuring events |
Controller |
getController()
Return the Controller |
UDPSelectorHandler |
getSelectorHandler()
Method returns SelectorHandler, which manages this
ConnectorHandler |
SelectableChannel |
getUnderlyingChannel()
Method returns ConnectorHandler's underlying channel |
boolean |
isConnected()
Is the underlying DatagramChannel connected. |
Controller.Protocol |
protocol()
A token decribing the protocol supported by an implementation of this interface |
long |
read(ByteBuffer byteBuffer,
boolean blocking)
Read bytes. |
void |
readFromAsyncQueue(ByteBuffer buffer,
AsyncReadCallbackHandler callbackHandler)
Method reads data to the ByteBuffer using async read queue. |
void |
readFromAsyncQueue(ByteBuffer buffer,
AsyncReadCallbackHandler callbackHandler,
AsyncReadCondition condition)
Method reads data to the ByteBuffer using async read queue. |
void |
readFromAsyncQueue(ByteBuffer buffer,
AsyncReadCallbackHandler callbackHandler,
AsyncReadCondition condition,
AsyncQueueDataProcessor readPostProcessor)
Method reads data to the ByteBuffer using async read queue. |
SocketAddress |
receive(ByteBuffer byteBuffer)
Receive bytes. |
long |
send(ByteBuffer byteBuffer,
SocketAddress socketAddress)
Receive bytes. |
void |
setCallbackHandler(CallbackHandler callbackHandler)
Sets ConnectorHandler's callback handler instance,
which is used to process occuring events |
void |
setController(Controller controller)
Set the Controller associated with this instance. |
long |
write(ByteBuffer byteBuffer,
boolean blocking)
Writes bytes. |
void |
writeToAsyncQueue(ByteBuffer buffer)
Method writes ByteBuffer using async write queue. |
void |
writeToAsyncQueue(ByteBuffer buffer,
AsyncWriteCallbackHandler callbackHandler)
Method writes ByteBuffer using async write queue. |
void |
writeToAsyncQueue(ByteBuffer buffer,
AsyncWriteCallbackHandler callbackHandler,
AsyncQueueDataProcessor writePreProcessor)
Method writes ByteBuffer using async write queue. |
void |
writeToAsyncQueue(ByteBuffer buffer,
AsyncWriteCallbackHandler callbackHandler,
AsyncQueueDataProcessor writePreProcessor,
boolean isCloneByteBuffer)
Method writes ByteBuffer using async write queue. |
void |
writeToAsyncQueue(SocketAddress dstAddress,
ByteBuffer buffer)
Method sends ByteBuffer using async write queue. |
void |
writeToAsyncQueue(SocketAddress dstAddress,
ByteBuffer buffer,
AsyncWriteCallbackHandler callbackHandler)
Method sends ByteBuffer using async write queue. |
void |
writeToAsyncQueue(SocketAddress dstAddress,
ByteBuffer buffer,
AsyncWriteCallbackHandler callbackHandler,
AsyncQueueDataProcessor writePreProcessor)
Method sends ByteBuffer using async write queue. |
void |
writeToAsyncQueue(SocketAddress dstAddress,
ByteBuffer buffer,
AsyncWriteCallbackHandler callbackHandler,
AsyncQueueDataProcessor writePreProcessor,
boolean isCloneByteBuffer)
Method sends ByteBuffer using async write queue. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected UDPSelectorHandler selectorHandler
protected CallbackHandler callbackHandler
CallbackHandler handler invoked by the UDPSelectorHandler
when a non blocking operation is ready to be processed.
protected DatagramChannel datagramChannel
protected volatile boolean isConnected
protected Controller controller
protected CountDownLatch isConnectedLatch
protected ByteBufferInputStream inputStream
InputStream that use a pool of Selector
to execute a blocking read operation.
| Constructor Detail |
|---|
public UDPConnectorHandler()
| Method Detail |
|---|
public void connect(SocketAddress remoteAddress,
CallbackHandler callbackHandler)
throws IOException
Controller will invoke
the CallBackHandler.
connect in interface ConnectorHandler<UDPSelectorHandler,CallbackHandler>remoteAddress - remote address to connectcallbackHandler - the handler invoked by the Controller when
an non blocking operation is ready to be handled.
IOException
public void connect(SocketAddress remoteAddress,
SocketAddress localAddress,
CallbackHandler callbackHandler)
throws IOException
Controller will invoke
the CallBackHandler.
connect in interface ConnectorHandler<UDPSelectorHandler,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.
IOException
public void connect(SocketAddress remoteAddress,
CallbackHandler callbackHandler,
UDPSelectorHandler selectorHandler)
throws IOException
Controller will invoke
the CallBackHandler.
connect in interface ConnectorHandler<UDPSelectorHandler,CallbackHandler>remoteAddress - remote address to connectcallbackHandler - the handler invoked by the Controller when
an non blocking operation is ready to be handled.selectorHandler - an instance of SelectorHandler.
IOException
public void connect(SocketAddress remoteAddress,
SocketAddress localAddress,
CallbackHandler callbackHandler,
UDPSelectorHandler selectorHandler)
throws IOException
Controller will invoke
the CallBackHandler.
connect in interface ConnectorHandler<UDPSelectorHandler,CallbackHandler>remoteAddress - remote address to connectlocalAddress - local address to bincallbackHandler - the handler invoked by the Controller when
an non blocking operation is ready to be handled.selectorHandler - an instance of SelectorHandler.
IOException
public void connect(SocketAddress remoteAddress)
throws IOException
connect in interface ConnectorHandler<UDPSelectorHandler,CallbackHandler>remoteAddress - remote address to connect
IOException
public void connect(SocketAddress remoteAddress,
SocketAddress localAddress)
throws IOException
connect in interface ConnectorHandler<UDPSelectorHandler,CallbackHandler>remoteAddress - remote address to connectlocalAddress - local address to bin
IOException
public long read(ByteBuffer byteBuffer,
boolean blocking)
throws IOException
Selector will be used to read bytes.
read in interface ConnectorHandler<UDPSelectorHandler,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
Selector will be used to writes bytes.
write in interface ConnectorHandler<UDPSelectorHandler,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 readFromAsyncQueue(ByteBuffer buffer,
AsyncReadCallbackHandler callbackHandler)
throws IOException
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 AsyncQueueReadablebuffer - ByteBuffercallbackHandler - AsyncReadCallbackHandler,
which will get notified, when
ByteBuffer will get full
IOException
public void readFromAsyncQueue(ByteBuffer buffer,
AsyncReadCallbackHandler callbackHandler,
AsyncReadCondition condition)
throws IOException
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 AsyncQueueReadablebuffer - ByteBuffercallbackHandler - 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
IOException
public void readFromAsyncQueue(ByteBuffer buffer,
AsyncReadCallbackHandler callbackHandler,
AsyncReadCondition condition,
AsyncQueueDataProcessor readPostProcessor)
throws IOException
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 AsyncQueueReadablebuffer - ByteBuffercallbackHandler - 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
IOException
public void writeToAsyncQueue(ByteBuffer buffer)
throws IOException
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 AsyncQueueWritablebuffer - ByteBuffer
IOException
public void writeToAsyncQueue(ByteBuffer buffer,
AsyncWriteCallbackHandler callbackHandler)
throws IOException
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 AsyncQueueWritablebuffer - ByteBuffercallbackHandler - AsyncWriteCallbackHandler,
which will get notified, when
ByteBuffer will be completely written
IOException
public void writeToAsyncQueue(ByteBuffer buffer,
AsyncWriteCallbackHandler callbackHandler,
AsyncQueueDataProcessor writePreProcessor)
throws IOException
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 AsyncQueueWritablebuffer - ByteBuffercallbackHandler - 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 void writeToAsyncQueue(ByteBuffer buffer,
AsyncWriteCallbackHandler callbackHandler,
AsyncQueueDataProcessor writePreProcessor,
boolean isCloneByteBuffer)
throws IOException
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 AsyncQueueWritablebuffer - ByteBuffercallbackHandler - AsyncWriteCallbackHandler,
which will get notified, when
ByteBuffer will be completely writtenwritePreProcessor - AsyncQueueDataProcessor, which
will perform data processing, before it will be
written on SelectableChannelisCloneByteBuffer - if true - AsyncQueueWriter
will clone given
ByteBuffer before puting it to the
AsyncQueue
IOException
public void writeToAsyncQueue(SocketAddress dstAddress,
ByteBuffer buffer)
throws IOException
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 AsyncQueueWritabledstAddress - destination SocketAddress data will
be sent tobuffer - ByteBuffer
IOException
public void writeToAsyncQueue(SocketAddress dstAddress,
ByteBuffer buffer,
AsyncWriteCallbackHandler callbackHandler)
throws IOException
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 AsyncQueueWritabledstAddress - destination SocketAddress data will
be sent tobuffer - ByteBuffercallbackHandler - AsyncWriteCallbackHandler,
which will get notified, when
ByteBuffer will be completely written
IOException
public void writeToAsyncQueue(SocketAddress dstAddress,
ByteBuffer buffer,
AsyncWriteCallbackHandler callbackHandler,
AsyncQueueDataProcessor writePreProcessor)
throws IOException
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 AsyncQueueWritabledstAddress - destination SocketAddress data will
be sent tobuffer - ByteBuffercallbackHandler - 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 void writeToAsyncQueue(SocketAddress dstAddress,
ByteBuffer buffer,
AsyncWriteCallbackHandler callbackHandler,
AsyncQueueDataProcessor writePreProcessor,
boolean isCloneByteBuffer)
throws IOException
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 AsyncQueueWritabledstAddress - destination SocketAddress data will
be sent tobuffer - ByteBuffercallbackHandler - AsyncWriteCallbackHandler,
which will get notified, when
ByteBuffer will be completely writtenwritePreProcessor - AsyncQueueDataProcessor, which
will perform data processing, before it will be
written on SelectableChannelisCloneByteBuffer - if true - AsyncQueueWriter
will clone given
ByteBuffer before puting it to the
AsyncQueue
IOException
public long send(ByteBuffer byteBuffer,
SocketAddress socketAddress)
throws IOException
byteBuffer - The byteBuffer to store bytes.socketAddress -
IOException
public SocketAddress receive(ByteBuffer byteBuffer)
throws IOException
byteBuffer - The byteBuffer to store bytes.
SocketAddress
IOException
public void close()
throws IOException
close in interface ConnectorHandler<UDPSelectorHandler,CallbackHandler>close in interface CloseableIOException
public void finishConnect(SelectionKey key)
throws IOException
finishConnect in interface ConnectorHandler<UDPSelectorHandler,CallbackHandler>key - SelectionKey
IOExceptionpublic Controller.Protocol protocol()
protocol in interface ConnectorHandler<UDPSelectorHandler,CallbackHandler>Controller.Protocolpublic boolean isConnected()
public Controller getController()
ConnectorHandlerController
getController in interface ConnectorHandler<UDPSelectorHandler,CallbackHandler>public void setController(Controller controller)
ConnectorHandlerController associated with this instance.
setController in interface ConnectorHandler<UDPSelectorHandler,CallbackHandler>controller - Controllerpublic SelectableChannel getUnderlyingChannel()
ConnectorHandlerConnectorHandler's underlying channel
getUnderlyingChannel in interface ConnectorHandler<UDPSelectorHandler,CallbackHandler>public CallbackHandler getCallbackHandler()
ConnectorHandlerConnectorHandler's callback handler instance,
which is used to process occuring events
getCallbackHandler in interface ConnectorHandler<UDPSelectorHandler,CallbackHandler>public void setCallbackHandler(CallbackHandler callbackHandler)
ConnectorHandlerConnectorHandler's callback handler instance,
which is used to process occuring events
setCallbackHandler in interface ConnectorHandler<UDPSelectorHandler,CallbackHandler>callbackHandler - handlerpublic UDPSelectorHandler getSelectorHandler()
ConnectorHandlerSelectorHandler, which manages this
ConnectorHandler
getSelectorHandler in interface ConnectorHandler<UDPSelectorHandler,CallbackHandler>SelectorHandler
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||