directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Burmester <>
Subject Re: [mina] MINA server design question
Date Fri, 15 Jul 2005 17:23:54 GMT
Hi Karim,  If I am understanding your issue correctly what you
need is a way to correlate client requests with server responses.

In my server each request has a unique transaction Id in the packet.

In your case if you have an id, when you send a message to your mileage 
server you can store a reference to the source session in a HashMap
with the transaction id as a key.  That way when you get a packet back 
from your mileage server you can get the id from the message and use that 
to get the source session out of your hashmap and the write the response
message to the source session and then possibly close the session.

One thing to keep in mind is that your mina server will be multithreaded 
so any data structure you use to keep track of outstanding messages will
need to have synchronized access.


On Fri, 15 Jul 2005 wrote:

> Trustin,
> Thanks for the reply. What I am struggling to understand is, in my MINA
> server protocol handler when I get a response back from milage server {i.e.
> I am inside messageReceived(ProtocolSession session, Object message) method
> } the session object represents session between MINA server and milage
> server. But I need to write received message back to session between MINA
> server and the calling clients {i.e inbound connections to MINA server}.
> How do I do that?
> If I just write it to the session that I've received, isn't it writing to
> the milage server?
> Hope this make sense or am I totally lost.
> ----------------------------------------
> Sadat Karim
> Information Technology
> Schneider National, Inc.
> 920-592-2540
> ----------------------------------------
>                       Trustin Lee                                                   
>                       <        To:       Apache Directory Developers
List <>                   
>                       m>                       cc:                               
>                                                Subject:  Re: [mina] MINA server design
>                       07/15/2005 01:16                                              
>                       AM                                                            
>                       Please respond to                                             
>                       "Apache Directory                                             
>                       Developers List"                                              
> Hi Karim,
> I apologize for my late reply.  I almost forgot to reply.
> 2005/7/14, < >:
>   What I am trying to implement is, provide a MINA server. The MINA server
>   will be client of a  third party TCP/IP socket milage server that serves
>   milage calculation. It accepts TCP/IP socket requests in ASCII form on
>   multiple ports. The way it works is, client opens a connection, it
>   confirms
>   that connection is ok. Then client send milage calculation request and it
>   sends multi-line response. The connection between client(in this case
>   MINA
>   server) and milage server never gets disconnected. On that open
>   connection
>   it keeps serving. The reason it does that is to avoid cost of opening a
>   connection.
> I see.  You can do that with MINA.
>   Now in the attached code I've done some POC. It is a mixture of sumup and
>   reverse example. As you can see that it opens a new connection for every
>   request. Now my questions to you are;
>   1. How do I keep the connection between MINA server and milage server
>   keep
>   open and keep sending new milage requests on that same opened connection?
> Connection is not closed if you don't call session.close(), so you don't
> need to worry about that.
>   2. How does MINA server works with multiple ports on milage server?
> You can bind same protocol provider to more than one ports.  Just call
> Acceptor.bind() as many times as you want.
>   3. How does the connection pooling and thread management will be working
>   between MINA server and milage server? Also between MINA server and its
>   clients (in my case these may be EJB calls)?
>  We use leader-followers thread pool.  It keeps the order of events fired
> sequential not compromising performance.  More than one threads can handle
> one connection because threads are reused for all connections.  So you
> cannot use any mechanism that uses Thread.currentThread() as a key such as
> ThreadLocal.  But MINA provides user-defined attributes in Session.  Please
> take a look at IoSession.get/setAttribute().
> I didn't look into your code yet.  Please let me know my reply is not
> sufficient.  I'll take a look at the code and answer again.
> Trustin
> --
> what we call human nature is actually human habit
> --

View raw message