You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by Brad Baker <bb...@gmail.com> on 2005/06/09 08:15:41 UTC

[mina] How to delay reading and writing when using Mina

I have only just begun to examine the Mina code base and was hoping someone 
could validate the following assumptions for me. What follows is a mini 
design followed by my assumptions.

Mini Design :
=============

* What I want to acheive is a "MINA process" that accepts incoming client 
connections, and then "buffers" them ready for a completely separate process 
(eg outside the VM) which will ask for "any incoming requests". The 
processing of requests and replies would be done in a asynch manner.

* For the record this "separate process" is a commercial message broker that 
talks other protocols but doesnt do native TCPIP sockets. Hence the 
separation of TCPIP handling and the cross process communication.

* The "MINA process" would accept client requests without reading them or 
replying to them (timeout handling is assumed here of course) . Rather the 
"MINA process" would "put the "ProtocolSession" aside in a memory table 
ready for later "reading and processing". (This might be tweaked to read the 
request first but certainly not write a reply then and there)

* The "outside process" would ask for "work" from ther MINA process at its 
leisure, at which time the "MINA process" would "read" the data from the 
"stored ProtocolSession" and pass that over to the "outside process". 

* Once the "outside process" had finished working on the "data" it would 
"pass a reply back" to the "MINA process" and have the MINA process "write" 
the reply data down the "stored" ProtocolSession.


Assumptions:
=============

* The ProtocolSession objects can be "stored" for later use and do not have 
to read from nor written to immediately. Rather they can be "set aside" and 
read from at some later asynch event (inside a timeout periods of course)

* The use of 2 ThreadPoolFilters (the IO one and the Protocol one) will 
enabled a level of "asynchronisity" to allow for "asynch" servicing of 
requests.

* The "MINA" process can "listen" on more than 1 port at a time (one for 
client request communication and one for "MINA process to outside process" 
communication)

* Arbitary "periods" can occur between accepting/reading and writing to the 
Session objects.

Second Mini Design 
================

* The MINA process could do the same sort thing as above but acting as a 
client instead of a server. eg the "outside prcocess" could ask for a client 
connection to be made to some other system. The MINA process would "call 
out" as a client and then "store" the outbound Session somewhere.

* Multiple outbound "client calls" could be made with one or more "selector" 
threads looking for potential replies, never waiting long for any given 
reply. if it gets a reply message, it would read the data and store it.

* The "outside process" would periodically ask for "replies" (using a magic 
key assigned earlier) in which case any replies found with that key would be 
returned.


Assumptions:
=============

* MINA can do client style connections as well as server style connections

* MINA code can have multiple outstanding "client connections" with a 
"selector" thread that can "tell" when they have become readable?

* Multiple SocketConnectors would be the way to do this?

Cheers
Brad Baker

Re: [mina] How to delay reading and writing when using Mina

Posted by Trustin Lee <tr...@gmail.com>.
2005/6/10, Brad Baker <bb...@gmail.com>:

> >>MINA doesn't have any traffic control support for now, so you can't stop 
> MINA from reading from >>socket and firing messageReceived event. It is a 
> known issue and we are going to fix it in 0.9 stream.
> 
> Cool . In my case I can read and "store" the data for later retreival.
> 
> >>MINA code can have multiple outstanding "client connections" with a 
> "selector" thread that can "tell" >>when they have become readable? >>Yes, 
> of course. :)
> >>Multiple SocketConnectors would be the way to do this? >>You can do the 
> same thing with single SocketConnector. :)
> 
> My impression of SocketConnect was that you needed 1 per outward bound 
> client connection. So are you saying that if my programs makes 50 outbound 
> client connections to "some server" I only need to use 1 SocketConnector.
> 
> And if so does the "pooling threads" tell me when any one of the multiple 
> outbound client connections is now readable?
> 
 Please note that IoConnector.connect() is a blocking operation. It returns 
IoSession when socket is connected. If once socket is connect, it works 
asynchronously.

 What I am trying to achieve is having the MINA process perform many 
> outbound "client connections" and for it to "manage" when data has come back 
> on any one of those connections. 
> 
 As I told you above, IoConnector.connect() is synchronous operation, so 
you'll have to manage your own thread pool to initiate many connections. In 
0.9 stream, we will provide Future interface so that these operations are 
done asynchronously.

 My "outside process" would "ask to initiatiate" an outbound connection and 
> later ask the MINA server if any one of them had become readbable. I am 
> hoping the MINA code manage multiple "outbound client connections" and tell 
> me when any one of them is readable?
> 
 Once connection is established, all connections will be managed by a single 
selector thread in SocketIoProcessor. 
 Thanks,
Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/

Re: [mina] How to delay reading and writing when using Mina

Posted by Trustin Lee <tr...@gmail.com>.
Hi Brad,

2005/6/9, Brad Baker bbakerman@gmail.com:
<snip/>
 MINA doesn't have any traffic control support for now, so you can't stop 
MINA from reading from socket and firing messageReceived event. It is a 
known issue and we are going to fix it in 0.9 stream.
 
> Assumptions:
> =============
> * The use of 2 ThreadPoolFilters (the IO one and the Protocol one) will 
> enabled a level of "asynchronisity" to allow for "asynch" servicing of 
> requests.

 I didn't get it what you mean. Could you explain more?

* The "MINA" process can "listen" on more than 1 port at a time (one for 
> client request communication and one for "MINA process to outside process" 
> communication)

 Yes, it can.

* Arbitary "periods" can occur between accepting/reading and writing to the 
> Session objects.

 No, as I told you above.

Second Mini Design 
> ================
> * The MINA process could do the same sort thing as above but acting as a 
> client instead of a server. eg the "outside prcocess" could ask for a client 
> connection to be made to some other system. The MINA process would "call 
> out" as a client and then "store" the outbound Session somewhere.

 MINA provides 'Connectors' which makes it possible to be used for 
developing client applications.

* Multiple outbound "client calls" could be made with one or more "selector" 
> threads looking for potential replies, never waiting long for any given 
> reply. if it gets a reply message, it would read the data and store it.

 Yes, you can. And you can specify timeout using Session.setIdleTime().
 
* The "outside process" would periodically ask for "replies" (using a magic 
> key assigned earlier) in which case any replies found with that key would be 
> returned.

 You can use java.util.Timer or Quartz to send periodic messages, and you 
can also use idleTime feature instead though it is not that accurate.

Assumptions:
> =============
> * MINA can do client style connections as well as server style connections

 True.

* MINA code can have multiple outstanding "client connections" with a 
> "selector" thread that can "tell" when they have become readable?

 Yes, of course. :)

* Multiple SocketConnectors would be the way to do this?

 You can do the same thing with single SocketConnector. :)

Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/