public class RemoteEndpoint extends java.lang.Object implements Endpoint, MessageConsumer, MessageIssueHandler, MethodProvider
MessageConsumer
by calling
request(String, Object)
or notify(String, Object)
. When connected to a MessageProducer
,
this class forwards received messages to the local Endpoint
given in the constructor.Modifier and Type | Field and Description |
---|---|
static java.util.function.Function<java.lang.Throwable,ResponseError> |
DEFAULT_EXCEPTION_HANDLER |
Constructor and Description |
---|
RemoteEndpoint(MessageConsumer out,
Endpoint localEndpoint) |
RemoteEndpoint(MessageConsumer out,
Endpoint localEndpoint,
java.util.function.Function<java.lang.Throwable,ResponseError> exceptionHandler) |
Modifier and Type | Method and Description |
---|---|
void |
consume(Message message)
Consume a single message.
|
protected ResponseMessage |
createErrorResponseMessage(RequestMessage requestMessage,
ResponseError errorObject) |
protected NotificationMessage |
createNotificationMessage(java.lang.String method,
java.lang.Object parameter) |
protected RequestMessage |
createRequestMessage(java.lang.String method,
java.lang.Object parameter) |
protected ResponseMessage |
createResponseMessage(RequestMessage requestMessage) |
protected ResponseMessage |
createResultResponseMessage(RequestMessage requestMessage,
java.lang.Object result) |
void |
handle(Message message,
java.util.List<MessageIssue> issues)
Handle issues found while parsing or validating a message.
|
protected boolean |
handleCancellation(NotificationMessage notificationMessage)
Cancellation is handled inside this class and not forwarded to the local endpoint.
|
protected void |
handleNotification(NotificationMessage notificationMessage) |
protected void |
handleRequest(RequestMessage requestMessage) |
protected void |
handleRequestIssues(RequestMessage requestMessage,
java.util.List<MessageIssue> issues) |
protected void |
handleResponse(ResponseMessage responseMessage) |
protected void |
handleResponseIssues(ResponseMessage responseMessage,
java.util.List<MessageIssue> issues) |
protected boolean |
isCancellation(java.lang.Throwable t) |
protected void |
logIssues(Message message,
java.util.List<MessageIssue> issues) |
void |
notify(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.String |
resolveMethod(java.lang.String requestId)
Returns the method name for a given request id, or null if such request id is unknown.
|
protected void |
sendCancelNotification(Either<java.lang.String,java.lang.Number> id) |
public static final java.util.function.Function<java.lang.Throwable,ResponseError> DEFAULT_EXCEPTION_HANDLER
public RemoteEndpoint(MessageConsumer out, Endpoint localEndpoint, java.util.function.Function<java.lang.Throwable,ResponseError> exceptionHandler)
out
- - a consumer that transmits messages to the remote servicelocalEndpoint
- - the local service implementationexceptionHandler
- - an exception handler that should never return null.public RemoteEndpoint(MessageConsumer out, Endpoint localEndpoint)
out
- - a consumer that transmits messages to the remote servicelocalEndpoint
- - the local service implementationpublic void notify(java.lang.String method, java.lang.Object parameter)
protected NotificationMessage createNotificationMessage(java.lang.String method, java.lang.Object parameter)
public java.util.concurrent.CompletableFuture<java.lang.Object> request(java.lang.String method, java.lang.Object parameter)
protected RequestMessage createRequestMessage(java.lang.String method, java.lang.Object parameter)
protected void sendCancelNotification(Either<java.lang.String,java.lang.Number> id)
public void consume(Message message)
MessageConsumer
consume
in interface MessageConsumer
protected void handleResponse(ResponseMessage responseMessage)
protected void handleNotification(NotificationMessage notificationMessage)
protected boolean handleCancellation(NotificationMessage notificationMessage)
true
if the given message is a cancellation notification,
false
if it can be handled by the local endpointprotected void handleRequest(RequestMessage requestMessage)
public void handle(Message message, java.util.List<MessageIssue> issues)
MessageIssueHandler
handle
in interface MessageIssueHandler
protected void logIssues(Message message, java.util.List<MessageIssue> issues)
protected void handleRequestIssues(RequestMessage requestMessage, java.util.List<MessageIssue> issues)
protected void handleResponseIssues(ResponseMessage responseMessage, java.util.List<MessageIssue> issues)
protected ResponseMessage createResponseMessage(RequestMessage requestMessage)
protected ResponseMessage createResultResponseMessage(RequestMessage requestMessage, java.lang.Object result)
protected ResponseMessage createErrorResponseMessage(RequestMessage requestMessage, ResponseError errorObject)
protected boolean isCancellation(java.lang.Throwable t)
public java.lang.String resolveMethod(java.lang.String requestId)
MethodProvider
resolveMethod
in interface MethodProvider
null