org.apache.mina.filter.query

## Class RequestFilter<REQUEST extends Request,RESPONSE extends Response>

- java.lang.Object
- - org.apache.mina.api.AbstractIoFilter
  - - org.apache.mina.filter.query.RequestFilter<REQUEST,RESPONSE>

All Implemented Interfaces:
  IoFilter

    public class RequestFilter<REQUEST extends Request,RESPONSE extends Response>
    extends AbstractIoFilter

A filter providing `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);
         }
     });

Author:
  Apache MINA Project

### Constructor Summary

Constructors
Constructor and Description
`RequestFilter()`

### Method Summary

Methods
`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.

### Methods inherited from class org.apache.mina.api.AbstractIoFilter

`messageSent, messageWriting, sessionIdle`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### RequestFilter

    public RequestFilter()

### Method Detail

#### request

    public IoFuture<RESPONSE> request(IoSession session,
                             REQUEST request,
                             long timeoutInMs)

Send a request message and provide a `IoFuture` for handling the response. WARNING : for now timeout doesn't work (WIP).

Parameters:
  `session` - the session where to write the request
  `request` - the request to be issued
  `timeoutInMs` - the timeout in milli-seconds (doesn't work Work-in-progress).
Returns:
  the `IoFuture` for waiting or listening the completion of this request.

#### sessionOpened

    public void sessionOpened(IoSession session)

Description copied from class: `AbstractIoFilter`
Invoked when a connection has been opened.

Specified by:
  `sessionOpened` in interface `IoFilter`
Overrides:
  `sessionOpened` in class `AbstractIoFilter`
Parameters:
  `session` - `IoSession` associated with the invocation

#### messageReceived

    public void messageReceived(IoSession session,
                       Object message,
                       ReadFilterChainController controller)

Description copied from class: `AbstractIoFilter`
Invoked when a message is received.

Specified by:
  `messageReceived` in interface `IoFilter`
Overrides:
  `messageReceived` in class `AbstractIoFilter`
Parameters:
  `session` - `IoSession` associated with the invocation
  `message` - the incoming message to process

#### sessionClosed

    public void sessionClosed(IoSession session)

Invoked when a connection is closed. cancel remaining requests

Specified by:
  `sessionClosed` in interface `IoFilter`
Overrides:
  `sessionClosed` in class `AbstractIoFilter`
Parameters:
  `session` - `IoSession` associated with the invocation