/** * Send a request to the remote endpoint. */ @Override public CompletableFuture<Object> request(String method, Object parameter) { final RequestMessage requestMessage = createRequestMessage(method, parameter); final CompletableFuture<Object> result = new CompletableFuture<Object>() { @Override public boolean cancel(boolean mayInterruptIfRunning) { sendCancelNotification(requestMessage.getRawId()); return super.cancel(mayInterruptIfRunning); } }; synchronized(sentRequestMap) { // Store request information so it can be handled when the response is received sentRequestMap.put(requestMessage.getId(), new PendingRequestInfo(requestMessage, result)); } try { // Send the request to the remote service out.consume(requestMessage); } catch (Exception exception) { // The message could not be sent, e.g. because the communication channel was closed result.completeExceptionally(exception); } return result; }
/** * Send a request to the remote endpoint. */ @Override public CompletableFuture<Object> request(String method, Object parameter) { final RequestMessage requestMessage = createRequestMessage(method, parameter); final CompletableFuture<Object> result = new CompletableFuture<Object>() { @Override public boolean cancel(boolean mayInterruptIfRunning) { sendCancelNotification(requestMessage.getRawId()); return super.cancel(mayInterruptIfRunning); } }; synchronized(sentRequestMap) { // Store request information so it can be handled when the response is received sentRequestMap.put(requestMessage.getId(), new PendingRequestInfo(requestMessage, result)); } try { // Send the request to the remote service out.consume(requestMessage); } catch (Exception exception) { // The message could not be sent, e.g. because the communication channel was closed result.completeExceptionally(exception); } return result; }
final String messageId = requestMessage.getId(); synchronized (receivedRequestMap) { receivedRequestMap.put(messageId, future);
final String messageId = requestMessage.getId(); synchronized (receivedRequestMap) { receivedRequestMap.put(messageId, future);