directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Niklas Therning" <nik...@trillian.se>
Subject RE: [mina] Filter management (was Spring Integration)
Date Thu, 10 Nov 2005 16:15:30 GMT
 

 

  _____  

From: Jose Alberto Fernandez [mailto:jalberto@cellectivity.com] 
Sent: den 10 november 2005 16:41
To: Apache Directory Developers List
Subject: RE: [mina] Filter management (was Spring Integration)

 

Well, I hope you are right.

 

  _____  

From: Trustin Lee [mailto:trustin@gmail.com] 

 

2a) Instead, insert ProtocolCodecFilter with your codec factory in your
IoHandler.sessionCreated() method. For example:

public void sessionCreated( IoSession session ) throws Exception {
    session.getFilterChain().addFirst( "codec", new ProtocolCodecFilter(
YOUR_CODEC_FACTORY ) );
}

This is one place, where the approach I mentioned would make a lot of sense.
You are running several protocols using several different handlers. You
really do not want to specify on every session the adding of new
CodecFilters, for example. You know all sessions will use the same filters
and if your filters are stateless, they should be using the same one. It
would make a lot of sense to be able to set this things once during bind()
and not need to do it on every session creation.





 

(My reply)

If I understand you correctly you want your IoHandler to implement
IoFilterManager:

 

public class MyIoHandler implements IoHandler, IoFilterManager {

    public void configureFilters(IoFilterChain chain) {

        chain.addFirst( "codec", new ProtocolCodecFilter( YOUR_CODEC_FACTORY
) );

    }

    // Other IoHandler methods

}

 

configureFilters will be called at bind-time.Of course the passed in
IoFilterChain which is modified has to be local to that port you are binding
to. Otherwise the next bind-call using another IoFilterManager and port will
mess up the chain modified by the first call to bind. You can achieve
exactly the same thing using a shared filter and Trustin's approach above:

 

public class MyIoHandler implements IoHandler {

    private ProtocolCodecFilter codecFilter = new ProtocolCodecFilter(
YOUR_CODEC_FACTORY );

  public void sessionCreated( IoSession session ) throws Exception {

      session.getFilterChain().addFirst( "codec", codecFilter );

  }

    // Other IoHandler methods

}

 

These two approaches look very similar to me. There's really no difference.
The same filter instance (which must be stateless) will be used anytime the
same MyIoHandler instance is used.

 

You still need to know in your IoHandler/IoFilterManager how the filter
chain should be modified which is exactly what I want to avoid. Let's say I
have a POP3Handler and want to support both SSL and non-SSL. With your
approach I will have the make my POP3Handler implement IoFilterManager and
somehow determine in configureFilters if the current bind is for the SLL or
non-SSL port to know whether an SSLFilter should be added or not. I want my
POP3Handler to be completely unaware of whether traffic is being encrypted
or not. It doesn't have to known that. 

 

If you have an additional bind method where you may specify an IoFilterChain
for that binding if will be quite easy to set up that chain using Spring.

 

BTW, I just realized that I have no idea whether SSLFilter is stateless or
not. Is it?

 

/Niklas

 


Mime
View raw message