Hi J-F,

On 6/29/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

Quoting peter royal <[EMAIL PROTECTED]>:

> On Jun 29, 2006, at 11:02 AM, [EMAIL PROTECTED] wrote:
>> I face the current situation:
>>
>> 1) a device connects to my server and sends a first message to
>> initiate a logical session
>> 2) the server replies
>> 3) the device now listens on the port
>> 4) the server sends some requests (and waits for replies)
>> 5) when it has finished, the server sends a final message to close
>>  logical session
>> 6) the device replies and closes connection
>>
>> I thought that I could use a filter to handle message exchanges of
>>  1), 2), 5) and 6). A separate handler would deal with exhanges in
>> 4).
>>
>> The filter would completely hide logical session handling. This  means
that
>>
>> a) the handler would receive a sessionOpened() when filter has
>> completed point 2).
>> b) a call to close() by the handler would initiate 5)
>>
>> I have implemented it, but when I write a message in my filter, the
>>   messageSent is never called.
>>
>> Where am I wrong?

I now have problem when filtering 'close'.

In filterClose, I send a message and directly return (no call to
nextFilter.filterClose)

The message is never sent. I added a Callback to WriteFuture, and
isWritten returns false.

What am I doing wrong?

How could intercept close?


I guess I answered this question before, but I'm not sure.  So I will answer
again. :)

You need to create an IoFilter with a filterClose() method.  The
filterClose() method can call nextFilter.filterWrite() to write a message.
But you shouldn't call nextFilter.filterClose() right now, you have to call
it in the callback of the returned WriteFuture:

public void filterClose(...) {
   WriteFuture f = nextFilter.filterWrite(...);
   f.setCallback(new IoFuture.Callback() {
       public void operationComplete(...) {
           nextFilter.filterClose(...);  // nextFilter should be final
       }
   });
}

HTH,
Trustin
--
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP key fingerprints:
* E167 E6AF E73A CBCE EE41  4A29 544D DE48 FE95 4E7E
* B693 628E 6047 4F8F CFA4  455E 1C62 A7DC 0255 ECA6

Reply via email to