|
[
Permlink
| « Hide
]
Trustin Lee added a comment - 22/Sep/05 12:31 PM
This attachment (Protocol.zip) is the contribution from Thomas Muller. We have to review it and create our one.
Trustin Lee made changes - 22/Sep/05 12:31 PM
His implementation is very impressive and provides a lot of features, but it seems like it is designed to be very specific to a specific protocol and management environment IMHO.
Here's my implementation plan: * RequestMessage which has a method 'getMessageId()' which returns an Object. The messageId type will have to implement equals and hashCode methods properly. * ResponseMessage which has a method 'getRequestMessageId()' which returns an Object. The constraint is same with that of RequestMessage. * RequestResponseProtocolFilter that remembers sent RequestMessages and fires an 'exceptionCaught' event with an appropriate 'RequestTimeoutException' to ProtocolHandler if the ResponseMessage is not arriving for certain specified time. WDYT?
Trustin Lee made changes - 17/Oct/05 07:09 PM
Trustin Lee made changes - 18/Oct/05 12:27 AM
I have attached a zip with some classes for a 'synchronious' request-response model. May out of topic, may it help...
The solution only wokrs with object serialization i guess.
Johannes Zillmann made changes - 28/Dec/05 03:42 AM
Trustin Lee made changes - 23/Jan/06 12:14 PM
attached queryreply.zip, the filter based on trustin ideas I use in my apps. WDYT ? I whould like to have comments before finishing it and integrate it in MINA.
Julien
Julien Vermillard made changes - 16/Aug/06 08:29 AM
a good idea whould be to add a "request without reply" counter, for detect dead connection.
Hi Julien,
I tried to use the stuff in queryreply.zip. How should I use the classes? I did the following: - ... chain.addFirst( "queryReply", new RequestResponseFilter(new BasicRequestFactory(10000))); //timeout == 10 secs ... and then what to do? I guess that I must call the RequestResponseFilter's query() method somewhere. I did that in my customized IoHandler for sending a message. The problem is that the query method blocks the application because of the following line in the query method: ... try { lastRequest.wait(lastRequest.getResponseTimeout()); } catch (InterruptedException e) { throw new RuntimeException(e); } ... Mina does not send the message after the set response timeout. I set the response timeout to 10000 (10 secs) and the application blocks for 10 seconds Do you have a test case for your RequestResponseFilter? Did I do something wrong? Another comment on RequestImpl's getReplyMessage(): it should be renamed to getResponseMessage according to the method setResponseMessage() Klaus This feature has been implemented finally. Please refer to the following ViewVC page to browse the source code.
http://tinyurl.com/3ahxg6 I didn't write the JavaDoc and the tutorial yet (I will do soon). Meanwhile, the following step-by-step example will help you understand how to use the RequestResponseFilter. 0) Scenario: A client sends a MyRequest message with a certain ID, then the server will respond with MyResponse message with the same ID, to identify that the response message related to the request message with the same ID. 1) Implement ResponseInspector. public class MyResponseInspector implements ResponseInspector { public Object getRequestId(Object message) { if (!(message instanceof MyResponse)) { return null; } MyResponse response = (MyResponse) message; return response.getId(); } public ResponseType getResponseType(Object message) { // You can return PARTIAL or PARTIAL_LAST if the protocol has multiple responses per request. return ResponseType.WHOLE; } } 2) Insert the RequestResponseFilter. connector.getFilterChain().addLast( "reqres", new RequestResponseFilter(new MyResponseInspector())); 3) Implement IoHandler. import org.apache.mina.filter.reqres.Request; import org.apache.mina.filter.reqres.Response; public class MyHandler extends IoHandlerAdapter { public void sessionOpened(IoSession session) throws Exception { MyRequest req = ...; // Send the request with 5 seconds timeout. session.write(new Request(req.getId(), req, 5, TimeUnit.SECONDS)); } public void messageReceived(IoSession session, Object message) throws Exception { Response res = (Response) message; MyRequest req = res.getRequest().getMessage(); MyResponse res = res.getMessage(); // Do something with the messages. ...... } public void exceptionCaught(IoSession session, Throwable cause) throws Exception { if (cause instanceof RequestTimeoutException) { RequestTimeoutException rte = (RequestTimeoutException) cause; rte.getRequest(); // Do something with the failed request. // RequestTimeoutException is thrown also when // a connection is closed but the related response is not received yet. ...... } } } Please give me feedback if the API doesn't make sense or needs improvement.
Trustin Lee made changes - 12/Apr/07 09:15 AM
Alternatively, you can use awaitResponse() method:
Request req = ...; session.write(req); try { Response res = req.awaitResponse(); // Do something the the response. ...... } catch (RequestTimeoutException e) { ...... }
Emmanuel Lecharny made changes - 26/May/09 02:47 PM
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||