users@grizzly.java.net

Re: Grizzly TCP Server: how to async call inside a filter

From: Oleksiy Stashok <oleksiy.stashok_at_oracle.com>
Date: Tue, 22 Oct 2013 09:30:33 -0700

Hi,


On 22.10.13 07:10, Raffaele Marcello wrote:
> Hi,
> i developed a TCP Server using Grizzly using two Filters:
> - MyProtocolFilter to manage the protocol( messages recognition )
> - MyCallerFilter to invoke a remote server (using RMI) and manage the
> answer.
>
> Unfortunately now it works using only one thread per connection. I'm
> having problems because sometimes some message can arrive while i'm
> waiting for the remote method invocation. In that case the new message
> is queued in input buffer and it can cause retransmissions.
> I want to ask if is possible to asynchronous invoke remote methods
> managing the results(Maybe using another thread). In this way i could
> manage new arriving messages while i'm waiting responses.
Sure, it's possible. As I understand your protocol doesn't require
responses to come in the same order as requests?
The easiest thing you can do in MyCallerFilter is:

public NextAction handleRead(FilterChainContext ctx) throws Exception {
              asyncMessageProcessor.doAsync(ctx.getMessage(),
ctx.getConnection()); // pass the message and the connection, so async
processor knows to whom it has to send the response
              return ctx.getStopAction();
}

If you can share your code - I'll be able to provide more details.

> Does anyone have a solution in order to maintain good performance? Can
> i use some Grizzly configuration or specific class?
Sure, you can tune I/O strategies, buffer sizes, etc, but first it will
be good to have something working :)))

Thanks.

WBR,
Alexey.

>
>
> Thanks
> R