T - The parameter type of the operation. This can be Void for no parameter.R - the return type of the operation. This can be Void for no return.public interface OperationHandler<T,R>
An instance of this must be returned from an OperationImpl annotated method in a
ServiceImpl. Simple synchronous operations can use sync(io.nexusrpc.handler.SynchronousOperationFunction<T, R>), more complex or
asynchronous operations can manually implement this interface.
| Modifier and Type | Method and Description |
|---|---|
void |
cancel(OperationContext context,
OperationCancelDetails details)
Cancel the asynchronously started operation.
|
OperationInfo |
fetchInfo(OperationContext context,
OperationFetchInfoDetails details)
Fetch information about the asynchronously started operation.
|
R |
fetchResult(OperationContext context,
OperationFetchResultDetails details)
Fetch the result for an asynchronously started operation.
|
OperationStartResult<R> |
start(OperationContext context,
OperationStartDetails details,
T param)
Handle the start of an operation.
|
static <T,R> OperationHandler<T,R> |
sync(SynchronousOperationFunction<T,R> func)
Create an operation handler for a synchronous operation backed by the given function.
|
static <T,R> OperationHandler<T,R> sync(SynchronousOperationFunction<T,R> func)
OperationStartResult<R> start(OperationContext context, OperationStartDetails details, T param) throws OperationException, HandlerException
The operation can be synchronous or asynchronous. Synchronous operations can return the
result via OperationStartResult.sync(R). Asynchronous operations can return the started
operation token via OperationStartResult.async(java.lang.String).
context - Context for the call.details - Details for the call.param - Parameter for the operation. This may be null if the parameter was not given.OperationException - If thrown, can have failure details and state such as saying the
operation was cancelled.HandlerException - Unexpected failures while running the handler.java.lang.RuntimeException - Any other exception, will be converted to an HandlerException
of type HandlerException.ErrorType.INTERNAL.R fetchResult(OperationContext context, OperationFetchResultDetails details) throws OperationStillRunningException, OperationException, HandlerException
context - Context for the call.details - Details for the call including the operation token. The details also contain a
timeout which affects how implementers should implement this function. See OperationFetchResultDetails.getTimeout() to see how to react to this value.OperationStillRunningException - Operation is still running beyond the given timeout.OperationException - Operation failed. If thrown, can have failure details and state such
as saying the operation was cancelled.HandlerException - Unexpected failures while running the handler. This should be thrown
with a type of HandlerException.ErrorType.NOT_FOUND if the operation token is not
found.java.lang.RuntimeException - Any other exception, will be converted to an HandlerException
of type HandlerException.ErrorType.INTERNAL.OperationInfo fetchInfo(OperationContext context, OperationFetchInfoDetails details) throws HandlerException
context - Context for the call.details - Details for the call including the operation token.HandlerException - Unexpected failures while running the handler. This should be thrown
with a type of HandlerException.ErrorType.NOT_FOUND if the operation token is not
found.java.lang.RuntimeException - Any other exception, will be converted to an HandlerException
of type HandlerException.ErrorType.INTERNAL.void cancel(OperationContext context, OperationCancelDetails details) throws HandlerException
This does not need to wait for cancellation to be processed, simply that cancellation is delivered. Duplicate cancellation requests for an operation or cancellation requests for an operation not running should just be ignored.
context - Context for the call.details - Details for the call including the operation token.HandlerException - Unexpected failures while running the handler. This should be thrown
with a type of HandlerException.ErrorType.NOT_FOUND if the operation token is not
found.java.lang.RuntimeException - Any other exception, will be converted to an HandlerException
of type HandlerException.ErrorType.INTERNAL.