Package org.eclipse.lsp4j.jsonrpc
Class RemoteEndpoint
- java.lang.Object
-
- org.eclipse.lsp4j.jsonrpc.RemoteEndpoint
-
- All Implemented Interfaces:
Endpoint,MethodProvider,MessageConsumer,MessageIssueHandler
public class RemoteEndpoint extends java.lang.Object implements Endpoint, MessageConsumer, MessageIssueHandler, MethodProvider
An endpoint that can be used to send messages to a givenMessageConsumerby callingrequest(String, Object)ornotify(String, Object). When connected to aMessageProducer, this class forwards received messages to the localEndpointgiven in the constructor.
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.function.Function<java.lang.Throwable,ResponseError>DEFAULT_EXCEPTION_HANDLER
-
Constructor Summary
Constructors Constructor Description RemoteEndpoint(MessageConsumer out, Endpoint localEndpoint)RemoteEndpoint(MessageConsumer out, Endpoint localEndpoint, java.util.function.Function<java.lang.Throwable,ResponseError> exceptionHandler)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidconsume(Message message)Consume a single message.protected ResponseMessagecreateErrorResponseMessage(RequestMessage requestMessage, ResponseError errorObject)protected NotificationMessagecreateNotificationMessage(java.lang.String method, java.lang.Object parameter)protected RequestMessagecreateRequestMessage(java.lang.String method, java.lang.Object parameter)protected ResponseMessagecreateResponseMessage(RequestMessage requestMessage)protected ResponseMessagecreateResultResponseMessage(RequestMessage requestMessage, java.lang.Object result)MessageJsonHandlergetJsonHandler()voidhandle(Message message, java.util.List<MessageIssue> issues)Handle issues found while parsing or validating a message.protected booleanhandleCancellation(NotificationMessage notificationMessage)Cancellation is handled inside this class and not forwarded to the local endpoint.protected voidhandleNotification(NotificationMessage notificationMessage)protected voidhandleRequest(RequestMessage requestMessage)protected voidhandleRequestIssues(RequestMessage requestMessage, java.util.List<MessageIssue> issues)protected voidhandleResponse(ResponseMessage responseMessage)protected voidhandleResponseIssues(ResponseMessage responseMessage, java.util.List<MessageIssue> issues)protected booleanisCancellation(java.lang.Throwable t)protected voidlogIssues(Message message, java.util.List<MessageIssue> issues)voidnotify(java.lang.String method, java.lang.Object parameter)Send a notification to the remote endpoint.java.util.concurrent.CompletableFuture<java.lang.Object>request(java.lang.String method, java.lang.Object parameter)Send a request to the remote endpoint.java.lang.StringresolveMethod(java.lang.String requestId)Returns the method name for a given request id, or null if such request id is unknown.protected voidsendCancelNotification(Either<java.lang.String,java.lang.Number> id)voidsetJsonHandler(MessageJsonHandler jsonHandler)
-
-
-
Field Detail
-
DEFAULT_EXCEPTION_HANDLER
public static final java.util.function.Function<java.lang.Throwable,ResponseError> DEFAULT_EXCEPTION_HANDLER
-
-
Constructor Detail
-
RemoteEndpoint
public RemoteEndpoint(MessageConsumer out, Endpoint localEndpoint, java.util.function.Function<java.lang.Throwable,ResponseError> exceptionHandler)
- Parameters:
out- - a consumer that transmits messages to the remote servicelocalEndpoint- - the local service implementationexceptionHandler- - an exception handler that should never return null.
-
RemoteEndpoint
public RemoteEndpoint(MessageConsumer out, Endpoint localEndpoint)
- Parameters:
out- - a consumer that transmits messages to the remote servicelocalEndpoint- - the local service implementation
-
-
Method Detail
-
setJsonHandler
public void setJsonHandler(MessageJsonHandler jsonHandler)
-
getJsonHandler
public MessageJsonHandler getJsonHandler()
-
notify
public void notify(java.lang.String method, java.lang.Object parameter)Send a notification to the remote endpoint.
-
createNotificationMessage
protected NotificationMessage createNotificationMessage(java.lang.String method, java.lang.Object parameter)
-
request
public java.util.concurrent.CompletableFuture<java.lang.Object> request(java.lang.String method, java.lang.Object parameter)Send a request to the remote endpoint.
-
createRequestMessage
protected RequestMessage createRequestMessage(java.lang.String method, java.lang.Object parameter)
-
sendCancelNotification
protected void sendCancelNotification(Either<java.lang.String,java.lang.Number> id)
-
consume
public void consume(Message message)
Description copied from interface:MessageConsumerConsume a single message.- Specified by:
consumein interfaceMessageConsumer
-
handleResponse
protected void handleResponse(ResponseMessage responseMessage)
-
handleNotification
protected void handleNotification(NotificationMessage notificationMessage)
-
handleCancellation
protected boolean handleCancellation(NotificationMessage notificationMessage)
Cancellation is handled inside this class and not forwarded to the local endpoint.- Returns:
trueif the given message is a cancellation notification,falseif it can be handled by the local endpoint
-
handleRequest
protected void handleRequest(RequestMessage requestMessage)
-
handle
public void handle(Message message, java.util.List<MessageIssue> issues)
Description copied from interface:MessageIssueHandlerHandle issues found while parsing or validating a message. The list of issues must not be empty.- Specified by:
handlein interfaceMessageIssueHandler
-
logIssues
protected void logIssues(Message message, java.util.List<MessageIssue> issues)
-
handleRequestIssues
protected void handleRequestIssues(RequestMessage requestMessage, java.util.List<MessageIssue> issues)
-
handleResponseIssues
protected void handleResponseIssues(ResponseMessage responseMessage, java.util.List<MessageIssue> issues)
-
createResponseMessage
protected ResponseMessage createResponseMessage(RequestMessage requestMessage)
-
createResultResponseMessage
protected ResponseMessage createResultResponseMessage(RequestMessage requestMessage, java.lang.Object result)
-
createErrorResponseMessage
protected ResponseMessage createErrorResponseMessage(RequestMessage requestMessage, ResponseError errorObject)
-
isCancellation
protected boolean isCancellation(java.lang.Throwable t)
-
resolveMethod
public java.lang.String resolveMethod(java.lang.String requestId)
Description copied from interface:MethodProviderReturns the method name for a given request id, or null if such request id is unknown.- Specified by:
resolveMethodin interfaceMethodProvider- Returns:
- method name or
null
-
-