Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top