// to add namespace to method name for JSON-RPC.
if (method.getName().equals("getId")) {
return proxyId;
} else if (method.getName().equals("receive")
&& args.length > 1) {
JSONResponse response = null;
if (args[0] != null) {
response = receive(args[0]);
}
if (response != null) {
JsonNode id = null;
if (response.getId() != null) {
id = response.getId();
}
final AsyncCallbackQueue<JSONResponse> cbs = host
.getCallbackQueue(proxyId,
JSONResponse.class);
if (cbs != null) {
final AsyncCallback<JSONResponse> callback = cbs
.pull(id);
if (callback != null) {
if (response.getError() != null) {
callback.onFailure(response
.getError());
} else {
callback.onSuccess(response);
}
}
}
}
return null;
} else {
final JSONRequest request = JSONRPC.createRequest(
method, args);
final SyncCallback<JSONResponse> callback = new SyncCallback<JSONResponse>();
final AsyncCallbackQueue<JSONResponse> cbs = host
.getCallbackQueue(proxyId,
JSONResponse.class);
if (cbs != null) {
cbs.push(request.getId(), "", callback);
}
try {
host.sendAsync(receiverUrl, request, agent,
null);
} catch (final IOException e1) {
throw new JSONRPCException(
CODE.REMOTE_EXCEPTION, "", e1);
}
JSONResponse response;
try {
response = callback.get();
} catch (final Exception e) {
throw new JSONRPCException(
CODE.REMOTE_EXCEPTION, "", e);
}
final JSONRPCException err = response.getError();
if (err != null) {
throw err;
} else if (response.getResult() != null
&& !method.getReturnType()
.equals(Void.TYPE)) {
return TypeUtil.inject(response.getResult(),
method.getGenericReturnType());
} else {
return null;
}
}