Jesse Hou wrote:
> So if I add three filter and the three filter(filter1, filter2, filter3)
> must be execute from head to tail (first to last).  Both of client and
> server side will be add the three filters.  When the server receive the
> message from client , the method messageReceived will be fired and the
> message will travel through filter1 filter2 filter3,  maybe when I invoke
> session.write(message) in method messageReceived  I also want to the
> message
> travel through filter1 filter2 filter3,  then how to do realize it? 
> and I
> think the filter consuming by session.wirte (close) and
> messageReceive() is
> a little inconsistent. How do you think so ?
When you invoke session.write() the message will travel though filter3
filter2 filter1. Think of it like a stack (similar to the TCP/IP stack):

IoHandler
      |
Filter3
      |
Filter2 (LoggingFilter)
      |
Filter1 (SSLFilter)
      |
Java NIO

Events from NIO (messageReceived, sessionOpened, etc) travels up the
stack while events from your IoHandler (write, close) travels down the
stack. If Filter1 is an SSLFilter you wouldn't want the data you write
using session.write() to be encrypted *before* it gets logged using
Filter2 would you?

It's not inconsistent at all acutally. :) Just think of it as events
traveling upstream (from NIO to your handler) and downstream (from your
handler to NIO).

What is it that you would like to achieve by having all events always
going head to tail?

-- 
Niklas Therning
www.spamdrain.net

Reply via email to