Le 12/7/12 10:27 AM, Victor Baxan a écrit :
> Hello Apache MINA Users!
>
> I have studied the Apache MINA documentation, but it seems to me that it
> only covers the Server Messages Inflow Architecture and Client Messages
> Outflow Architecture.
>
> I am kindly asking for help in understanding the MINA Server Architecture,
> specifically the messages outflow architecture.
>
> Are the messages get first sent in the IOHanlder, and then traverse the
> filter chain initially set and only then do they get sent over the network
> via the appropriate underlying socket channel, or is this being done in
> some other way compared to the way that the messages come in from the
> network?
>
> The same question applies to the MINA Client Architecture, specifically the
> messages inflow architecture.
>
> Many thanks in advance.
This is quite convoluted. As we never know if we will be able to write
in the socket (for TCP/UDP transports), the session.write() method goes
though the filter chain and write the bytes into a WriteQueue. The
IoProcessor thread will pull those messages from the writeQueue and
write them into the socket, if it's not full. When the socket is full,
it will raise the OP_WRITE flag so that when the socket is ready to
write, the IoProcessor will be informed and will try to write some more
messages, after pulling them from the write queue.
Let's see how it works with this schema :
IoProcessor thread :
for ever
process message received :
(Message received) --> filter -> ... -> filter -> IoHandler ->
session.write -> filter -> ... -> filter -> message pushed into the
write queue
process write :
while write queue not empty
pull message from the write queue
try to write it in the socket
if socket full
then
set flag OP_WRITE
break
done
As you can see, writing a message is done in one single thread, and you
can't for instance do something like :
WriteFuture wf = session.write( message );
wf.await();
because it will block for ever, as the thread that processes the write
is the one which notify the WriteFuture, and the one that is blocked
when you do the wf.await().
I hope I clarified the algorithm.
Note : in MINA 3, it will be completely different. Instead of using the
IoProcessor thread to process the read then the writes, we will have
separated thread processing both events, so we won't be blocked anymore.
Also we will try to write directly into the socket, instead of pushing
the messages into a queue.
On the client side, it's totally symetrical : the inflow processing is
exactly the same.
--
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com