0

How does Apache Mina' filter handle different request? For example I have two requests: LoginRequest and StudentRequest, and I have written corresponding factory: LoginCodecFactory and StudentCodecFactory. then I added them into the filter:

acceptor.getFilterChain().addLast("protocol", new ProtocolCodecFilter(new LoginCodecFactory(false)));
    acceptor.getFilterChain().addLast("protocoltest", new ProtocolCodecFilter(new StudentCodecFactory(false)));

This does not work...So how to let the filter pick up the corresponding factory to handle the request at runtime?

user2716189
  • 63
  • 1
  • 6

1 Answers1

0

I think you are trying to put too much logic into your filter. Based on the docs, its appropriate to use a filter to convert an IoBuffer into some application specific object (ex. a generic Request object) but then the filter's work is done and this new object should be passed to an IoHandler.

In this design, a single filter would process every incoming IoBuffer and convert it the same way. Since there is only one filter, the problem of choosing which filter is gone.

The IoHandler then receives all incoming requests, figures out which is the LoginRequest, StudentRequest etc and handles it appropriately. The design of the request object and the logic to determine what type of request it is, is a part of your application, not part of MINA, so you can implement this any way you want.

Guido Simone
  • 7,912
  • 2
  • 19
  • 21
  • Right, thank you for your answer. I saw this class in the api: DemuxingProtocolDecoder. It seems that it can demultiplex the incoming request into different decoder. I googled it but couldnt find an example of it. Do you know how to use that? – user2716189 Sep 12 '13 at 01:03
  • No I have never used that. Ok - I just read some of the docs. Looks cool. However - if it were me - I'd stick to the simple design in the MINA tutorial - simple filter which forwards data to the IoHandler. – Guido Simone Sep 12 '13 at 01:19