Le 2/15/13 10:20 PM, Ricardo Cristian Ramirez a écrit :
> I have a client application which has a sending state. If sending state is
> enabled, this means client can send something to the server and if it is
> disabled, client can not send  anything. Sending state is directed by
> server, i.e. server sends a message "sending_enabled" and client's state
> changes. And, when client's sending state is disabled, it should   not send
> anything to the server.
>
> Currently, I have a mina client application whose connector is
> NioSocketConnector. On the client side, I use session.write() method for
> sending data. However, in order to achieve the above situation, I have to
> do some extra thing. Consider the below situation:
>
> check the client state before sending -> assume that sending is enabled, so
> we can send our data
> call session.write(...) -> code inside the write() method is being executed
> Now, assume that before locking the channel in the sender thread, it has
> lost the processor. Then, receiver thread takes the processor and got a
> message which says "sending_disabled". Hence, client's state is changed.
> When the sender thread takes the processor again, our message will be sent
> to the server without checking the client's       state. However, that
> message should not send.
There is a time issue : you can have a client which has just sent some
data at T0, which will be sent to the server at T0+n, with the server
which as sent a "sending-disabled' at T0+x, where T0+x is < T0 + n. In
this case, there is no way for the client to stop the message it as
already sent, even if it's still somewhere between the client and the
server.

The sender thread never lock the channel : it tries to write the data
into it, and either it succeeded in one operation, or it has just wrote
a part of the data, and will wait for the channel to be ready for a new
write (ie, the socket is ready to accept some new data). If the thread
can't write all the data, it just stack it into a queue, which will be
read again when the channel is ready for sending some new data, which
may be done a long time after. It's perfectly possible that in the mean
time, the cient receives a sending-disabled, but still, the message *is*
considered as sent.
>
> Briefly, I want to make a check when the session.write() method locks the
> channel. Can I do this, how?
No, you can't, because the channel is never locked. Or 'locks' stands
for something different, and you need to be a bit more explicit.

What exactly do you want to do ? Is this interrupting some sending if a
message is received from the server ?


-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com 

Reply via email to