Binding the Async Write Queue

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Binding the Async Write Queue

Dave
Hi,

I am looking at a method to bind the Async write queue when using a
TCPNIOConnection to a specific number of application packets or bytes.
 From the documentation I found the following setting which I thought
would do the trick:

maxAsyncWriteQueueSizeInBytes

When I dug into the code I seen in order to use this I would have to
register a WriteHandler via the notifyCanWrite(...) API. This is
triggered after the queue has been serviced i.e. at least one packet
must be written to the queue.
However, I would like a way to determine at the time I write to the
queue whether the queue is full or not and take action at that point in
time.

One solution is to pass in a completionHandler when I call write on the
Connection. I can then keep track of the number of outstanding packets
(or bytes) outside the grizzly framework and on each write check if I
have exceeded my configured size and then take th appropriate action.

Can I get a brief explanation of how "maxAsyncWriteQueueSizeInBytes" is
intended to work and if I have missed anything that can give me what I
want within the grizzly framework.

Thank you,
Dave.


Reply | Threaded
Open this post in threaded view
|

Re: Binding the Async Write Queue

oleksiys
Administrator
Hi Dave,

the maxAsyncWriteQueueSizeInBytes and WriteHandler are related. The
WriteHandler, once registered, will be called (just once) when the queue
size is less than the max, so you can perform connection.write(...).


On 03.11.15 06:43, Dave wrote:
>
> When I dug into the code I seen in order to use this I would have to
> register a WriteHandler via the notifyCanWrite(...) API. This is
> triggered after the queue has been serviced i.e. at least one packet
> must be written to the queue.
You don't have to write any packet to make your WriteHandler to be
triggered, these two things are not related.

> However, I would like a way to determine at the time I write to the
> queue whether the queue is full or not and take action at that point
> in time.
connection.canWrite() is probably what you're looking for.

canWrite/notifyWritePossible methods are declared in OutputSink
interface, which is implemented by Grizzly Connection, additionally this
interface is implemented by HTTP Server's NIOOutputStream, which you can
get from HTTP Response object passed to your HttpHandler.


WBR,
Alexey.

>
> One solution is to pass in a completionHandler when I call write on
> the Connection. I can then keep track of the number of outstanding
> packets (or bytes) outside the grizzly framework and on each write
> check if I have exceeded my configured size and then take th
> appropriate action.
>
> Can I get a brief explanation of how "maxAsyncWriteQueueSizeInBytes"
> is intended to work and if I have missed anything that can give me
> what I want within the grizzly framework.
>
> Thank you,
> Dave.
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Binding the Async Write Queue

Dave
Thanks Oleksiy,

If I register a write handler and the queue is empty, will the handler
get triggered at that point i.e. no writes have taken place yet.
 From the code it looked like it was only triggered once a successful
write had taken place, then the queue size is checked (processAsync,
write API's).

Thanks,
Dave.



On 04/11/15 23:52, Oleksiy Stashok wrote:

> Hi Dave,
>
> the maxAsyncWriteQueueSizeInBytes and WriteHandler are related. The
> WriteHandler, once registered, will be called (just once) when the
> queue size is less than the max, so you can perform
> connection.write(...).
>
>
> On 03.11.15 06:43, Dave wrote:
>>
>> When I dug into the code I seen in order to use this I would have to
>> register a WriteHandler via the notifyCanWrite(...) API. This is
>> triggered after the queue has been serviced i.e. at least one packet
>> must be written to the queue.
> You don't have to write any packet to make your WriteHandler to be
> triggered, these two things are not related.
>
>> However, I would like a way to determine at the time I write to the
>> queue whether the queue is full or not and take action at that point
>> in time.
> connection.canWrite() is probably what you're looking for.
>
> canWrite/notifyWritePossible methods are declared in OutputSink
> interface, which is implemented by Grizzly Connection, additionally
> this interface is implemented by HTTP Server's NIOOutputStream, which
> you can get from HTTP Response object passed to your HttpHandler.
>
>
> WBR,
> Alexey.
>
>>
>> One solution is to pass in a completionHandler when I call write on
>> the Connection. I can then keep track of the number of outstanding
>> packets (or bytes) outside the grizzly framework and on each write
>> check if I have exceeded my configured size and then take th
>> appropriate action.
>>
>> Can I get a brief explanation of how "maxAsyncWriteQueueSizeInBytes"
>> is intended to work and if I have missed anything that can give me
>> what I want within the grizzly framework.
>>
>> Thank you,
>> Dave.
>>
>>
>

Reply | Threaded
Open this post in threaded view
|

Re: Binding the Async Write Queue

Dave
In reply to this post by oleksiys
Hi,

Apologies, I missed some of the answers below which have already
answered my last question.
Thanks Oleksiy and Alexey, I appreciate the quick response.

Thanks,
Dave.

On 04/11/15 23:52, Oleksiy Stashok wrote:

> Hi Dave,
>
> the maxAsyncWriteQueueSizeInBytes and WriteHandler are related. The
> WriteHandler, once registered, will be called (just once) when the
> queue size is less than the max, so you can perform
> connection.write(...).
>
>
> On 03.11.15 06:43, Dave wrote:
>>
>> When I dug into the code I seen in order to use this I would have to
>> register a WriteHandler via the notifyCanWrite(...) API. This is
>> triggered after the queue has been serviced i.e. at least one packet
>> must be written to the queue.
> You don't have to write any packet to make your WriteHandler to be
> triggered, these two things are not related.
>
>> However, I would like a way to determine at the time I write to the
>> queue whether the queue is full or not and take action at that point
>> in time.
> connection.canWrite() is probably what you're looking for.
>
> canWrite/notifyWritePossible methods are declared in OutputSink
> interface, which is implemented by Grizzly Connection, additionally
> this interface is implemented by HTTP Server's NIOOutputStream, which
> you can get from HTTP Response object passed to your HttpHandler.
>
>
> WBR,
> Alexey.
>
>>
>> One solution is to pass in a completionHandler when I call write on
>> the Connection. I can then keep track of the number of outstanding
>> packets (or bytes) outside the grizzly framework and on each write
>> check if I have exceeded my configured size and then take th
>> appropriate action.
>>
>> Can I get a brief explanation of how "maxAsyncWriteQueueSizeInBytes"
>> is intended to work and if I have missed anything that can give me
>> what I want within the grizzly framework.
>>
>> Thank you,
>> Dave.
>>
>>
>