users@grizzly.java.net

Re: manage ad-hoc protocol over TCP connections

From: Oleksiy Stashok <oleksiy.stashok_at_oracle.com>
Date: Mon, 23 Apr 2012 15:06:55 +0200

sorry, skipped one bullet...

On 04/23/2012 02:28 PM, marcelloraffaele_at_gmail.com wrote:
> - i need to manage timeouts while the packet is coming. If the packet
> isn't completely received i need to send a "nack". How i can do it over
> a Filter?
You can use connection.write() if you're not inside FilterChain, or
FilterChainContext.write() if you're inside FilterChain.
Connection.write(message) will make your message to pass *all* the
FilterChain's Filters from last to first;
FilterChainContext.write(message) will make your message pass the
FilterChain's Filters from *current* Filter to first.

So if you have FilterChain like:

Filter1 <-> Filter2 <-> Filter3 <-> Filter4

Connection.write(message) will make your message pass
Filter4.handleWrite(), Filter3.handleWrite(), Filter2.handleWrite(),
Filter1.handleWrite();
But if you're inside Filter3 and call FilterChainContext.write(message)
- then your message will pass Filter2.handleWrite(), Filter1.handleWrite();

Hope this helps.

WBR,
Alexey.

>
> Is Filter the best way to do it or i can use other Grizzly Object to
> make it?
> Maybe i need to extend some class and implement something.
>
> I hope that you can help me.
> Thanks
> R