## com.sun.grizzly.async
Class AbstractAsyncQueueWriter

    java.lang.Object
      com.sun.grizzly.async.AbstractAsyncQueueWriter

All Implemented Interfaces:
  AsyncQueueWriter

Direct Known Subclasses:
  TCPAsyncQueueWriter, UDPAsyncQueueWriter

    public abstract class AbstractAsyncQueueWriter

extends Object
implements AsyncQueueWriter

Author:
  oleksiys

Constructor Summary
`AbstractAsyncQueueWriter(SelectorHandler selectorHandler)`

Method Summary
`void` `close()` Close `AsyncQueueWriter` and release its resources
`protected abstract void` `doWrite(WritableByteChannel channel, SocketAddress dstAddress, ByteBuffer byteBuffer)`
`protected void` `doWrite(WritableByteChannel channel, SocketAddress dstAddress, ByteBuffer byteBuffer, AsyncQueueDataProcessor writePreProcessor)`
`boolean` `hasReadyAsyncWriteData(SelectionKey key)` Checks whether there is any data in `AsyncQueue` ready to be written to the `SelectableChannel`, associated with the given `SelectionKey`
`void` `onClose(SelectableChannel channel)` Callback method, which should be called by `SelectorHandler` to notify, that given `SelectableChannel` is going to be closed, so related `SelectableChannel` data could be released from `AsyncQueue`
`void` `onWrite(SelectionKey key)` Callback method, which should be called by `SelectorHandler` to notify, that `SelectableChannel`, associated with the given `SelectionKey` is ready to transmit data.
`protected void` `registerForWriting(SelectionKey key)`
`void` `write(SelectionKey key, ByteBuffer buffer)` Method writes `ByteBuffer` to the `SelectableChannel` First, if `SelectableChannel` associated write queue is empty - it tries to write `ByteBuffer` to the given `SelectableChannel` directly (without putting to the queue).
`void` `write(SelectionKey key, ByteBuffer buffer, AsyncWriteCallbackHandler callbackHandler)` Method writes `ByteBuffer` to the `SelectableChannel` First, if `SelectableChannel` associated write queue is empty - it tries to write `ByteBuffer` to the given `SelectableChannel` directly (without putting to the queue).
`void` `write(SelectionKey key, ByteBuffer buffer, AsyncWriteCallbackHandler callbackHandler, AsyncQueueDataProcessor writePreProcessor)` Method writes `ByteBuffer` to the `SelectableChannel` First, if `SelectableChannel` associated write queue is empty - it tries to write `ByteBuffer` to the given `SelectableChannel` directly (without putting to the queue).
`void` `write(SelectionKey key, ByteBuffer buffer, AsyncWriteCallbackHandler callbackHandler, AsyncQueueDataProcessor writePreProcessor, boolean isCloneByteBuffer)` Method writes `ByteBuffer` to the `SelectableChannel` First, if `SelectableChannel` associated write queue is empty - it tries to write `ByteBuffer` to the given `SelectableChannel` directly (without putting to the queue).
`void` `write(SelectionKey key, SocketAddress dstAddress, ByteBuffer buffer)` Method sends `ByteBuffer` to the `SocketAddress` First, if `SelectableChannel` associated write queue is empty - it tries to write `ByteBuffer` to the given `SocketAddress` directly (without putting to the queue).
`void` `write(SelectionKey key, SocketAddress dstAddress, ByteBuffer buffer, AsyncWriteCallbackHandler callbackHandler)` Method sends `ByteBuffer` to the `SocketAddress` First, if `SelectableChannel` associated write queue is empty - it tries to write `ByteBuffer` to the given `SocketAddress` directly (without putting to the queue).
`void` `write(SelectionKey key, SocketAddress dstAddress, ByteBuffer buffer, AsyncWriteCallbackHandler callbackHandler, AsyncQueueDataProcessor writePreProcessor)` Method sends `ByteBuffer` to the `SocketAddress` First, if `SelectableChannel` associated write queue is empty - it tries to write `ByteBuffer` to the given `SocketAddress` directly (without putting to the queue).

`void`

`write(SelectionKey key, SocketAddress dstAddress, ByteBuffer buffer, AsyncWriteCallbackHandler callbackHandler, AsyncQueueDataProcessor writePreProcessor, boolean isCloneByteBuffer)`
Method sends `ByteBuffer` to the `SocketAddress` First, if `SelectableChannel` associated write queue is empty - it tries to write `ByteBuffer` to the given `SocketAddress` directly (without putting to the queue).

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### AbstractAsyncQueueWriter

    public AbstractAsyncQueueWriter(SelectorHandler selectorHandler)

Method Detail

### write

    public void write(SelectionKey key,
                      ByteBuffer buffer)
               throws IOException

  Method writes `ByteBuffer` to the `SelectableChannel` First, if `SelectableChannel` associated write queue is empty - it tries to write `ByteBuffer` to the given `SelectableChannel` 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` and `SelectableChannel` will be registered on `SelectorHandler`, waiting for OP_WRITE event. 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:
    `write` in interface `AsyncQueueWriter`
  Parameters:
    `key` - `SelectionKey` associated with `SelectableChannel` `ByteBuffer` should be written to
    `buffer` - `ByteBuffer`
  Throws:
    `IOException`

### write

    public void write(SelectionKey key,
                      ByteBuffer buffer,
                      AsyncWriteCallbackHandler callbackHandler)
               throws IOException

  Method writes `ByteBuffer` to the `SelectableChannel` First, if `SelectableChannel` associated write queue is empty - it tries to write `ByteBuffer` to the given `SelectableChannel` 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` and `SelectableChannel` will be registered on `SelectorHandler`, waiting for OP_WRITE event. 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:
    `write` in interface `AsyncQueueWriter`
  Parameters:
    `key` - `SelectionKey` associated with `SelectableChannel` `ByteBuffer` should be written to
    `buffer` - `ByteBuffer`
    `callbackHandler` - `AsyncWriteCallbackHandler`, which will get notified, when `ByteBuffer` will be completely written
  Throws:
    `IOException`

### write

    public void write(SelectionKey key,
                      ByteBuffer buffer,
                      AsyncWriteCallbackHandler callbackHandler,
                      AsyncQueueDataProcessor writePreProcessor)
               throws IOException

  Method writes `ByteBuffer` to the `SelectableChannel` First, if `SelectableChannel` associated write queue is empty - it tries to write `ByteBuffer` to the given `SelectableChannel` 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` and `SelectableChannel` will be registered on `SelectorHandler`, waiting for OP_WRITE event. 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:
    `write` in interface `AsyncQueueWriter`
  Parameters:
    `key` - `SelectionKey` associated with `SelectableChannel` `ByteBuffer` should be written 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`

### write

    public void write(SelectionKey key,
                      ByteBuffer buffer,
                      AsyncWriteCallbackHandler callbackHandler,
                      AsyncQueueDataProcessor writePreProcessor,
                      boolean isCloneByteBuffer)
               throws IOException

  Method writes `ByteBuffer` to the `SelectableChannel` First, if `SelectableChannel` associated write queue is empty - it tries to write `ByteBuffer` to the given `SelectableChannel` 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` and `SelectableChannel` will be registered on `SelectorHandler`, waiting for OP_WRITE event. 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:
    `write` in interface `AsyncQueueWriter`
  Parameters:
    `key` - `SelectionKey` associated with `SelectableChannel` `ByteBuffer` should be written 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`
    `isCloneByteBuffer` - if true - `AsyncQueueWriter` will clone given `ByteBuffer` before puting it to the `AsyncQueue`
  Throws:
    `IOException`

### write

    public void write(SelectionKey key,
                      SocketAddress dstAddress,
                      ByteBuffer buffer)
               throws IOException

  Method sends `ByteBuffer` to the `SocketAddress` First, if `SelectableChannel` associated write queue is empty - it tries to write `ByteBuffer` to the given `SocketAddress` 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` and `SelectableChannel` will be registered on `SelectorHandler`, waiting for OP_WRITE event. 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:
    `write` in interface `AsyncQueueWriter`
  Parameters:
    `key` - `SelectionKey` associated with `SelectableChannel`, which will be used to send`ByteBuffer` to
    `dstAddress` - destination address `ByteBuffer` will be sent to
    `buffer` - `ByteBuffer`
  Throws:
    `IOException`

### write

    public void write(SelectionKey key,
                      SocketAddress dstAddress,
                      ByteBuffer buffer,
                      AsyncWriteCallbackHandler callbackHandler)
               throws IOException

  Method sends `ByteBuffer` to the `SocketAddress` First, if `SelectableChannel` associated write queue is empty - it tries to write `ByteBuffer` to the given `SocketAddress` 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` and `SelectableChannel` will be registered on `SelectorHandler`, waiting for OP_WRITE event. 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:
    `write` in interface `AsyncQueueWriter`
  Parameters:
    `key` - `SelectionKey` associated with `SelectableChannel` `ByteBuffer` should be written to
    `dstAddress` - destination address `ByteBuffer` will be sent to
    `buffer` - `ByteBuffer`
    `callbackHandler` - `AsyncWriteCallbackHandler`, which will get notified, when `ByteBuffer` will be completely written
  Throws:
    `IOException`

### write

    public void write(SelectionKey key,
                      SocketAddress dstAddress,
                      ByteBuffer buffer,
                      AsyncWriteCallbackHandler callbackHandler,
                      AsyncQueueDataProcessor writePreProcessor)
               throws IOException

  Method sends `ByteBuffer` to the `SocketAddress` First, if `SelectableChannel` associated write queue is empty - it tries to write `ByteBuffer` to the given `SocketAddress` 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` and `SelectableChannel` will be registered on `SelectorHandler`, waiting for OP_WRITE event. 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:
    `write` in interface `AsyncQueueWriter`
  Parameters:
    `key` - `SelectionKey` associated with `SelectableChannel` `ByteBuffer` should be written to
    `dstAddress` - destination address `ByteBuffer` 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`

### write

    public void write(SelectionKey key,
                      SocketAddress dstAddress,
                      ByteBuffer buffer,
                      AsyncWriteCallbackHandler callbackHandler,
                      AsyncQueueDataProcessor writePreProcessor,
                      boolean isCloneByteBuffer)
               throws IOException

  Method sends `ByteBuffer` to the `SocketAddress` First, if `SelectableChannel` associated write queue is empty - it tries to write `ByteBuffer` to the given `SocketAddress` 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` and `SelectableChannel` will be registered on `SelectorHandler`, waiting for OP_WRITE event. 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:
    `write` in interface `AsyncQueueWriter`
  Parameters:
    `key` - `SelectionKey` associated with `SelectableChannel` `ByteBuffer` should be written to
    `dstAddress` - destination address `ByteBuffer` 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`
    `isCloneByteBuffer` - if true - `AsyncQueueWriter` will clone given `ByteBuffer` before puting it to the `AsyncQueue`
  Throws:
    `IOException`

### hasReadyAsyncWriteData

    public boolean hasReadyAsyncWriteData(SelectionKey key)

  Checks whether there is any data in `AsyncQueue` ready to be written to the `SelectableChannel`, associated with the given `SelectionKey`

  Specified by:
    `hasReadyAsyncWriteData` in interface `AsyncQueueWriter`
  Parameters:
    `key` - `SelectionKey` associated with `SelectableChannel`
  Returns:
    true, if there is ready data. False otherwise.

### onWrite

    public void onWrite(SelectionKey key)
                 throws IOException

  Callback method, which should be called by `SelectorHandler` to notify, that `SelectableChannel`, associated with the given `SelectionKey` is ready to transmit data.

  Specified by:
    `onWrite` in interface `AsyncQueueWriter`
  Parameters:
    `key` - `SelectionKey` associated with `SelectableChannel`
  Throws:
    `IOException`

### onClose

    public void onClose(SelectableChannel channel)

  Callback method, which should be called by `SelectorHandler` to notify, that given `SelectableChannel` is going to be closed, so related `SelectableChannel` data could be released from `AsyncQueue`

  Specified by:
    `onClose` in interface `AsyncQueueWriter`

### close

    public void close()

  Close `AsyncQueueWriter` and release its resources

  Specified by:
    `close` in interface `AsyncQueueWriter`

### doWrite

    protected void doWrite(WritableByteChannel channel,
                           SocketAddress dstAddress,
                           ByteBuffer byteBuffer,
                           AsyncQueueDataProcessor writePreProcessor)
                    throws IOException

  Throws:
    `IOException`

### doWrite

    protected abstract void doWrite(WritableByteChannel channel,
                                    SocketAddress dstAddress,
                                    ByteBuffer byteBuffer)
                             throws IOException

  Throws:
    `IOException`

### registerForWriting

    protected void registerForWriting(SelectionKey key)

Copyright © 2008 SUN Microsystems. All Rights Reserved.