Request<? extends Object> request,
Class<JsonElement> clazz,
final Continuation<Response<JsonElement>> continuation) {
try {
handlerManager.handleRequest(session,
(Request) request, new ResponseSender() {
@Override
public void sendResponse(Message message)
throws IOException {
continuation
.onSuccess((Response) message);
}
});
} catch (IOException e) {
continuation.onError(e);
}
}
@Override
protected <P, R> Response<R> internalSendRequest(
Request<P> request, Class<R> resultClass)
throws IOException {
final Object[] response = new Object[1];
try {
handlerManager.handleRequest(session,
(Request) request, new ResponseSender() {
@Override
public void sendResponse(Message message)
throws IOException {
response[0] = message;
}
});
Response<R> response2 = (Response<R>) response[0];
Object result = response2.getResult();
if (result == null
|| resultClass.isAssignableFrom(result
.getClass())) {
return response2;
} else if (resultClass == JsonElement.class) {
response2.setResult((R) JsonUtils
.toJsonElement(result));
return response2;
} else {
throw new ClassCastException("Class " + result
+ " cannot be converted to "
+ resultClass);
}
} catch (IOException e) {
return new Response(request.getId(), ResponseError
.newFromException(e));
}
}
});
TransactionImpl t = new TransactionImpl(clientSession, newRequest,
new ResponseSender() {
@Override
public void sendResponse(Message message)
throws IOException {
response[0] = (Response<JsonObject>) message;