private void doCall(Map<String, Object> input, int serial) { try { Object result = target.onCommand(new Command(input)); sendToRemote("ref", serial, "result", result); } catch (RemoteException e) { sendErrorNoExceptions(serial, e.getRemoteErrorClass(), e.getRemoteErrorText()); } catch (Exception e) { sendErrorNoExceptions(serial, e.getClass().getSimpleName(), e.getMessage()); } }
private void processReply(Map<String, Object> input, Integer ref) { CommandResult dr; // synchronized (resultQueue) { dr = resultQueue.remove(ref); // } if (dr != null) { Object error = input.get("error"); if (error != null) { dr.sendFailure(RemoteException.makeException(error)); } else { Object result = input.get("result"); dr.sendSuccess(result); } } }
@SuppressWarnings("unchecked") static Exception makeException(Object error) { if (error instanceof Map) { return new RemoteException((Map<String, Object>) error); } return new ProtocolException("bad remote exception record: " + error); }
@Override public Object onCommand(Command command) throws Exception { throw new RemoteException("unknown_command", "command is not known"); } });