Hi Luis,

Are your producer and consumer two processes that use MINA to communicate ?
So you are calling ioSession.suspendRead in process A (the consumer end)
in the hope that this would block the producer in process B (at the other
end of the wire), right ?

I guess this would work, if you are using TCP:

It is my understanding that MINA will stop requesting incoming data from the
OS when you call suspendRead.
Eventually, the OS'es buffer of incoming data will be full and TCP will ask
the other side to stop writing.

from
http://en.wikipedia.org/wiki/Transmission_Control_Protocol#TCP_window_size

"The TCP receive window size is the amount of received data (in bytes) that
can be buffered during a connection. The sending host can send only up to
that amount of data before it must wait for an acknowledgment and window
update from the receiving host. When a receiver advertises the window size
of 0, the sender stops sending data and starts the persist timer."

Maarten

On 7/24/07, Trustin Lee <[EMAIL PROTECTED]> wrote:

Hi Luis,

On 7/22/07, Luis Neves <[EMAIL PROTECTED]> wrote:
>
> Hello all.
> I think I'm misunderstanding something fundamental about how the
> IoSession.suspendRead() and IoSession.resumeRead() methods work and I
would
> appreciate any insight you guys can offer.
> I have a producer and consumer both based on Mina. What I want to
achieve is to
> block the producer while the the consumer is still processing the
message.
>
> The way I thought I could do this was do something like this in the
producer side:
>
> [...]
> WriteFuture wf = ioSession.write(message);
> wf.awaitUninterruptibly();
> [...]
>
> and in the consumer side:
>
> public void messageReceived(IoSession iosession, Object message) throws
Exception
> {
> long readMsg = iosession.getReadMessages();
> iosession.suspendRead();
> [... slow message processing ...]
> iosession.resumeRead();
> }
>
> I was under the impression that the iosession.suspendRead()  would make
the
> producer block, but this is not the behaviour I'm seeing.
> What I'm seeing is that the even with the IoSession in suspend state the
> producer manages to successfully write the messages and the
> iosession.getReadMessages() in the consumer side keeps getting bigger.
> Are my expectations wrong? Is there any way I can achieve the desired
behaviour
> with Mina?

suspend/resumeRead() is an asynchronous operation.  It means message
can be received *after* suspendRead() is called.  However, once
suspension request is processed by SocketIoProcessor, no more message
will be received.

Do we need TrafficFuture or something similar for more fine-grained
control?

Trustin
--
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6

Reply via email to