Hi Tigran,
On 25.02.13 14:06, Tigran Mkrtchyan wrote:
> On 22.02.13 02:22, Tigran Mkrtchyan wrote:
>>> Hi,
>>>
>>> I have in the code following lines:
>>>
>>> context.write(context.getAddress(), buffer, null);
>>>
>>> is it safe to replace with:
>>>
>>> connection = context.getConnection();
>>> remoteAddress = (InetSocketAddress)context.getAddress();
>>>
>>> connection.write(remoteAddress, buffer, null);
>>>
>>> The main difference is that point where I use connection is much later
>>> and executed by other thread ( e.q. I am building in async reply
>>> mechanism).
>>>
>>> Well, it works but I want to be sure that it's reliable.
>> ctx.write(...) is basically writing message starting from the *current*
>> (FilterChainContext) filter downstream.
>> connection.write(...) writes the message start from the *last* Filter in
>> chain downstream.
>>
> Ok, I do this in the last filter:
>
>
> @Override
> public NextAction handleRead(final FilterChainContext ctx) throws
> IOException {
>
> final RpcCall call = ctx.getMessage();
>
> _asyncExecutorService.execute( new Runnable() {
>
> @Override
> public void run() {
> program.dispatchCall(call);
> }
> });
> return ctx.getInvokeAction();
> }
>
> is the be best practice, or there is another to do the processing. The
> main reason is that we get multiple requests over the same TCP
> connection and some of them may take quite some time, while the others
> have to be processed independently.
If you use SameThreadStrategy - the sample looks fine.
Also, if you can distinguish if the request might be processed
immediately or take longer time - you may want to dispatch the "fast"
request in the same thread to avoid thread context switch.
WBR,
Alexey.
>
> Tigran.
>
>> WBR,
>> Alexey.
>>
>>> Thanks,
>>> Tigran.
>>