Hey Mina users!
I'm a newbie for Apache Mina (2.0.0 RC1). I will build a framework for sending
and receiving ucp messages (see
http://en.wikipedia.org/wiki/Universal_Computer_Protocol) for sending and
receiving short messages. I have done a Client which send/receives ucp messages
asynchronous (which was really easy with Apache Mina - thanks! :-) ).
But for convenience, I also will provide the possibility to sends/receives ucp
messages synchronous. My first try looks as following:
public UCPMessage sendSync(UCPMessage req) throws Throwable {
WriteFuture writeFuture = session.write(req);
writeFuture = writeFuture.awaitUninterruptibly();
if (writeFuture.getException() != null) {
throw writeFuture.getException();
}
ReadFuture readFuture = session.read();
readFuture.awaitUninterruptibly();
if (readFuture.getException() != null) {
throw readFuture.getException();
}
return (UCPMessage) readFuture.getMessage();
}
Is this the right way?
The java doc for IoSession says, that the IoSession is thread safe. If I use
'session.read()', I think my client is not thread safe anymore, because
'session.read()' returns the next response from the queue, whatever if this the
response for this request or for another request (which is send with the same
client). I'm right?
Do you have a better solution for a synchronous client which is maybe thread
safe?
Thanks for your help,
Christian