Hmm, no response. I hope I am posting to the right place.
OK, With a few trial and error, I seem to get reqres to work (more or
less).
However, I found that the setting of request timeout impact the client
behavior in ways I can't understand. I assume that I should have the
same behavior with the sumup example, start the server, start the
client, client exit by itself and result is printed out in the log. The
test shows otherwise.
My test program is a minor modification of the sumup example (add the
reqres filter):
In ClientSessionHandler.java:
public class ClientSessionHandler extends IoHandlerAdapter {
public static class Inspector implements ResponseInspector {
public Object getRequestId (Object message) {
AbstractMessage am = (AbstractMessage)message;
return Integer.valueOf(am.getSequence());
}
public ResponseType getResponseType (Object message) {
return ResponseType.WHOLE;
}
}
...
@Override
public void sessionOpened(IoSession session) {
// send summation requests
for (int i = 0; i < values.length; i++) {
AddMessage m = new AddMessage();
m.setSequence(i);
m.setValue(values[i]);
Request req = new Request (Integer.valueOf(i), m, 10); <--
timeout set to 10 milliseconds
session.write(req);
}
}
...
@Override
public void messageReceived(IoSession session, Object message) {
// server only sends ResultMessage. otherwise, we will have to
identify
// its type using instanceof operator.
Response res = (Response)message;
ResultMessage rm = (ResultMessage) res.getMessage();
if (rm.isOk()) {
...
In Client.java:
...
connector.getFilterChain().addLast("logger", new
LoggingFilter());
connector.getFilterChain().addLast ("reqres",
new RequestResponseFilter(new
ClientS\
essionHandler.Inspector(), new ScheduledThreadPoolExecutor(2)));
...
I found that if I set the request timeout to be 1000, then I got sum
result in the log, but Client program won't exit (session can't be
closed?). If I set the request timeout to 10, then I got
WriteToClosedSessionException.
I'd really appreciate if somebody can point me to the right direction on
how to use reqres filter correctly.
Thanks
Haijun
2009-08-11 01:15:20,490 INFO [NioProcessor-1]
reqres.ClientSessionHandler The sum: 10
2009-08-11 01:23:02,007 WARN [NioProcessor-1] logging.LoggingFilter
EXCEPTION :
org.apache.mina.core.write.WriteToClosedSessionException
at
org.apache.mina.core.polling.AbstractPollingIoProcessor.clearWriteReques
tQueue(AbstractPollingIoProcessor.java:539)
at
org.apache.mina.core.polling.AbstractPollingIoProcessor.removeNow(Abstra
ctPollingIoProcessor.java:492)
at
org.apache.mina.core.polling.AbstractPollingIoProcessor.remove(AbstractP
ollingIoProcessor.java:471)
at
org.apache.mina.core.polling.AbstractPollingIoProcessor.access$600(Abstr
actPollingIoProcessor.java:56)
at
org.apache.mina.core.polling.AbstractPollingIoProcessor$Processor.run(Ab
stractPollingIoProcessor.java:896)
at
org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.j
ava:64)
at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecuto
r.java:886)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.ja
va:908)
at java.lang.Thread.run(Thread.java:619)
-----Original Message-----
From: Haijun Cao [mailto:[email protected]]
Sent: Monday, August 10, 2009 12:09 PM
To: [email protected]
Subject: RequestResponseFilter
Hi
I am new to MINA. I am considering when RequestResponseFilter class,
wondering if somebody can give me some example code on how to use it?
Thanks
Haijun