mina-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Edouard De Oliveira <doe_wan...@yahoo.fr>
Subject Re : Server supporting multiple protocols at the same time
Date Tue, 14 Aug 2007 23:40:13 GMT
Hi community,

As the problem seems to touch some of the members of this community, i'm happy to share some
classes i wrote that can be used to dynamically circumvent the single ProtocolCodecFilter
limitation of mina 1.x mina. It is based on code grabbed from ProtocolCodecFilter classes.

Here's the use case :

A CumulativeIoFilter is inserted in the session filter chain. Then the CumulativeIoFilter#getConsumer(IoSession)
method forwards data to a DataConsumer which is in charge of delimiting messages and sending
each message to a IoFilterCodec which will wrap or unwrap the data before 
sending it down the chain.

With these classes you can add/remove dynamically several codecs to your session chain.
For example, i used it to add the DIGEST-MD5 SASL integrity and privacy mechanisms to my POP3
server 
(these services are dynamically negotiated during a POP3 session).

If these files can be usefull to someone, i'll be more than happy. 
Please note that these files are still under work, if you have any suggestions feel free to
express them :)

Regards,
-Edouard De Oliveira-

----- Message d'origine ----
De : Niklas Therning <niklas@trillian.se>
À : dev@mina.apache.org
Envoyé le : Mardi, 14 Août 2007, 20h05mn 52s
Objet : Re: Server supporting multiple protocols at the same time

If you are writing a server application and want to use a single
IoHandler implementation with different protocols you could give
different IoServiceConfig objects for each call to IoAcceptor.bind().
Before you call bind() you configure the filter chain of each
IoServiceConfig with an appropriate ProtocolCodecFilter.

Pseudo code for chat server supporting MSN and AIM protocols:

ProtocolCodecFilter aimCodecFilter = ...;
ProtocolCodecFilter msnCodecFilter = ...;

SocketAcceptorConfig aimConfig = new SocketAcceptorConfig();
aimConfig.getFilterChain().addFirst("aimCodec", aimCodecFilter);

SocketAcceptorConfig msnConfig = new SocketAcceptorConfig();
msnConfig.getFilterChain().addFirst("msnCodec", msnCodecFilter);

SocketAcceptor acceptor = ...;
acceptor.bind(new InetSocketAddress(...), myChatHandler, aimCodecFilter);
acceptor.bind(new InetSocketAddress(...), myChatHandler, msnCodecFilter);

Please note that I have no idea how the MSN and AIM protocols actually
work. The above is only to illustrate. :-)

In SpamDrain we use the same IoHandler to service both SSL encrypted and
non SSL POP3 and IMAP connections. It works similarly to the above.

BTW, IIRC you only need MINA 2.0 if you want to have several
ProtocolCodecFilters in the same filter chain.

HTH

/Niklas

mat wrote:
> Only in MINA 2.0, you will be able to add more than one ProtocolCodecFilter.
> Am I right?
>
> On 8/14/07, Kevin Williams <kevwil@gmail.com> wrote:
>   
>> Yes, you can. We have one IoHandler which delegates to different
>> codecs to process the request.
>>
>> On 8/14/07, Simon Aquilina <sim085@hotmail.com> wrote:
>>     
>>> Hi,
>>>
>>> I just managed to get the mina examples running in my free time :) I
>>>       
>> have
>>     
>>> also viewed the presentation available under the user documentations!
>>>       
>> From
>>     
>>> the documentation I can understand that mina allows you to have
>>>       
>> different
>>     
>>> protocols! However can I have different protocols at the same time? That
>>>       
>> is
>>     
>>> can I build a server that can accept both http and socket connections
>>>       
>> and
>>     
>>> feed their results with the same IOHandler? I am sorry if the question
>>> sounds newb! From what I read I feel that the answer is 'Yes' However
>>>       
>> wanted
>>     
>>> to confirm that!
>>>
>>> Thanks and Regards,
>>> Sim085
>>>
>>> _________________________________________________________________
>>> Express yourself instantly with MSN Messenger! Download today it's FREE!
>>> http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
>>>
>>>
>>>       
>> --
>> Cheers,
>>
>> Kevin Williams
>> http://www.almostserio.us/
>> http://kevwil.tumblr.com/
>> http://kevwil.jaiku.com/
>>
>>     
>
>   


-- 
Niklas Therning
www.spamdrain.net






      _____________________________________________________________________________ 
Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail 
Mime
  • Unnamed multipart/mixed (inline, None, 0 bytes)
View raw message