protected Launcher<T> createLauncher(StreamMessageProducer reader, MessageConsumer messageConsumer, ExecutorService execService, T remoteProxy, RemoteEndpoint remoteEndpoint, ConcurrentMessageProcessor msgProcessor) { return new StandardLauncher<T>(execService, remoteProxy, remoteEndpoint, msgProcessor); }
/** * Create a new Launcher for a given local service object, a given remote interface and an input and output stream. * * @param localService - the object that receives method calls from the remote service * @param remoteInterface - an interface on which RPC methods are looked up * @param in - input stream to listen for incoming messages * @param out - output stream to send outgoing messages */ static <T> Launcher<T> createLauncher(Object localService, Class<T> remoteInterface, InputStream in, OutputStream out) { return new Builder<T>() .setLocalService(localService) .setRemoteInterface(remoteInterface) .setInput(in) .setOutput(out) .create(); }
/** * Send a notification to the remote endpoint. */ @Override public void notify(String method, Object parameter) { NotificationMessage notificationMessage = createNotificationMessage(method, parameter); try { out.consume(notificationMessage); } catch (Exception exception) { Level logLevel = JsonRpcException.indicatesStreamClosed(exception) ? Level.INFO : Level.WARNING; LOG.log(logLevel, "Failed to send notification message.", exception); } }
/** * Create the remote endpoint that communicates with the local services. */ protected RemoteEndpoint createRemoteEndpoint(MessageJsonHandler jsonHandler) { MessageConsumer outgoingMessageStream = new StreamMessageConsumer(output, jsonHandler); outgoingMessageStream = wrapMessageConsumer(outgoingMessageStream); RemoteEndpoint remoteEndpoint = new RemoteEndpoint(outgoingMessageStream, ServiceEndpoints.toEndpoint(localServices)); jsonHandler.setMethodProvider(remoteEndpoint); return remoteEndpoint; } }
protected void handleNotification(NotificationMessage notificationMessage) { if (!handleCancellation(notificationMessage)) { // Forward the notification to the local endpoint try { localEndpoint.notify(notificationMessage.getMethod(), notificationMessage.getParams()); } catch (Exception exception) { LOG.log(Level.WARNING, "Notification threw an exception: " + notificationMessage, exception); } } }
protected IWorkspaceConfig getWorkspaceConfig() { if ((this._workspaceConfig == null)) { final ResponseError error = new ResponseError(ResponseErrorCode.serverNotInitialized, "Workspace has not been initialized yet.", null); throw new ResponseErrorException(error); } return this._workspaceConfig; }
/** * Create a new Launcher for a given local service object, a given remote interface and an input and output stream. * Threads are started with the given executor service. The wrapper function is applied to the incoming and * outgoing message streams so additional message handling such as validation and tracing can be included. * * @param localService - the object that receives method calls from the remote service * @param remoteInterface - an interface on which RPC methods are looked up * @param in - input stream to listen for incoming messages * @param out - output stream to send outgoing messages * @param executorService - the executor service used to start threads * @param wrapper - a function for plugging in additional message consumers */ static <T> Launcher<T> createLauncher(Object localService, Class<T> remoteInterface, InputStream in, OutputStream out, ExecutorService executorService, Function<MessageConsumer, MessageConsumer> wrapper) { return createIoLauncher(localService, remoteInterface, in, out, executorService, wrapper); }
protected ResponseMessage createResultResponseMessage(RequestMessage requestMessage, Object result) { ResponseMessage responseMessage = createResponseMessage(requestMessage); responseMessage.setResult(result); return responseMessage; }
/** * Create the JSON handler for messages between the local and remote services. */ protected MessageJsonHandler createJsonHandler() { Map<String, JsonRpcMethod> supportedMethods = getSupportedMethods(); if (configureGson != null) return new MessageJsonHandler(supportedMethods, configureGson); else return new MessageJsonHandler(supportedMethods); }
protected ResponseMessage createErrorResponseMessage(RequestMessage requestMessage, ResponseError errorObject) { ResponseMessage responseMessage = createResponseMessage(requestMessage); responseMessage.setError(errorObject); return responseMessage; }
@Override public MessageConsumer apply(final MessageConsumer consumer) { //inject our own consumer to refresh the timestamp return message -> { lastActivityTime=System.currentTimeMillis(); consumer.consume(message); }; } }
@Override public CompletableFuture<List<DocumentLink>> documentLink(DocumentLinkParams params) { return CompletableFutures.computeAsync(canceler -> { return null; }); } });
@Override public void consume(Message message) throws JsonRpcException { throw new JsonRpcException(new SocketException("Socket closed")); } };
/** * Create a new Launcher for a given local service object, a given remote interface and an input and output stream. * * @param localService - the object that receives method calls from the remote service * @param remoteInterface - an interface on which RPC methods are looked up * @param in - input stream to listen for incoming messages * @param out - output stream to send outgoing messages */ static <T> Launcher<T> createLauncher(Object localService, Class<T> remoteInterface, InputStream in, OutputStream out) { return new Builder<T>() .setLocalService(localService) .setRemoteInterface(remoteInterface) .setInput(in) .setOutput(out) .create(); }
protected void handleNotification(NotificationMessage notificationMessage) { if (!handleCancellation(notificationMessage)) { // Forward the notification to the local endpoint try { localEndpoint.notify(notificationMessage.getMethod(), notificationMessage.getParams()); } catch (Exception exception) { LOG.log(Level.WARNING, "Notification threw an exception: " + notificationMessage, exception); } } }
/** * Send a notification to the remote endpoint. */ @Override public void notify(String method, Object parameter) { NotificationMessage notificationMessage = createNotificationMessage(method, parameter); try { out.consume(notificationMessage); } catch (Exception exception) { Level logLevel = JsonRpcException.indicatesStreamClosed(exception) ? Level.INFO : Level.WARNING; LOG.log(logLevel, "Failed to send notification message.", exception); } }
/** * Create a new Launcher for a given local service object, a given remote interface and an input and output stream. * Threads are started with the given executor service. The wrapper function is applied to the incoming and * outgoing message streams so additional message handling such as validation and tracing can be included. * * @param localService - the object that receives method calls from the remote service * @param remoteInterface - an interface on which RPC methods are looked up * @param in - input stream to listen for incoming messages * @param out - output stream to send outgoing messages * @param executorService - the executor service used to start threads * @param wrapper - a function for plugging in additional message consumers */ static <T> Launcher<T> createLauncher(Object localService, Class<T> remoteInterface, InputStream in, OutputStream out, ExecutorService executorService, Function<MessageConsumer, MessageConsumer> wrapper) { return createIoLauncher(localService, remoteInterface, in, out, executorService, wrapper); }
protected ResponseMessage createResultResponseMessage(RequestMessage requestMessage, Object result) { ResponseMessage responseMessage = createResponseMessage(requestMessage); responseMessage.setResult(result); return responseMessage; }
@Override public CompletableFuture<DocumentLink> documentLinkResolve(DocumentLink params) { return CompletableFutures.computeAsync(canceler -> { params.setTarget("resolved"); return params; }); } });
static <T> Launcher<T> createLauncher(Builder<T> builder, Object localService, Class<T> remoteInterface, InputStream in, OutputStream out) { return builder.setLocalService(localService) .setRemoteInterface(remoteInterface) .setInput(in).setOutput(out) .create(); }