public class RequestFilter<REQUEST extends Request,RESPONSE extends Response> extends AbstractIoFilter
IoFuture
for request/response protocol.
You send a request to the connected end-point and a IoFuture
is provided for handling the received request
response.
The filter find the received message matching the request, using Request.requestId()
and
Response.requestId()
.
RequestFilter rq = new RequestFilter(); service.setFilters(.., rq); IoFuture<Response> future = rq.request(session, message, 10000); response.register(new AbstractIoFutureListener<Response>() { @Override public void completed(Response result) { System.err.println("request completed ! response : " + result); } });
Constructor and Description |
---|
RequestFilter() |
Modifier and Type | Method and Description |
---|---|
void |
messageReceived(IoSession session,
Object message,
ReadFilterChainController controller)
Invoked when a message is received.
|
IoFuture<RESPONSE> |
request(IoSession session,
REQUEST request,
long timeoutInMs)
Send a request message and provide a
IoFuture for handling the response. |
void |
sessionClosed(IoSession session)
Invoked when a connection is closed.
|
void |
sessionOpened(IoSession session)
Invoked when a connection has been opened.
|
messageSent, messageWriting, sessionIdle
public IoFuture<RESPONSE> request(IoSession session, REQUEST request, long timeoutInMs)
IoFuture
for handling the response. WARNING : for now timeout
doesn't work (WIP).session
- the session where to write the requestrequest
- the request to be issuedtimeoutInMs
- the timeout in milli-seconds (doesn't work Work-in-progress).IoFuture
for waiting or listening the completion of this request.public void sessionOpened(IoSession session)
AbstractIoFilter
sessionOpened
in interface IoFilter
sessionOpened
in class AbstractIoFilter
session
- IoSession
associated with the invocationpublic void messageReceived(IoSession session, Object message, ReadFilterChainController controller)
AbstractIoFilter
messageReceived
in interface IoFilter
messageReceived
in class AbstractIoFilter
session
- IoSession
associated with the invocationmessage
- the incoming message to processpublic void sessionClosed(IoSession session)
sessionClosed
in interface IoFilter
sessionClosed
in class AbstractIoFilter
session
- IoSession
associated with the invocationCopyright © 2009–2013 Apache MINA Project. All rights reserved.