Package dev.getelements.elements.rt
Interface HandlerContext
- All Known Implementing Classes:
SimpleHandlerContext
public interface HandlerContext
Used to manage handler-type
Resource instances. These are intended to be short-lived and managed entirely
on the server side. Unlike using the bare ResourceContext the methods in this interface will automatically
guaranteed the lifecycle of the remote Resource.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe timeout for theHandlerContextin milliseconds. -
Method Summary
Modifier and TypeMethodDescriptiondefault ObjectinvokeRetainedHandler(Attributes attributes, String module, String method, Object... args) Synchronously invokesinvokeRetainedHandlerAsync(Consumer, Consumer, Attributes, String, String, Object...)blocking until the call returns.voidinvokeRetainedHandlerAsync(Consumer<Object> success, Consumer<Throwable> failure, Attributes attributes, String module, String method, Object... args) default ObjectinvokeSingleUseHandler(Attributes attributes, String module, String method, Object... args) Synchronously invokesinvokeSingleUseHandlerAsync(Consumer, Consumer, Attributes, String, String, Object...)blocking until the call returns.voidinvokeSingleUseHandlerAsync(Consumer<Object> success, Consumer<Throwable> failure, Attributes attributes, String module, String method, Object... args) default voidstart()Starts thisHandlerContext.default voidstop()Stops thisHandlerContext.
-
Field Details
-
HANDLER_TIMEOUT_MSEC
The timeout for theHandlerContextin milliseconds.- See Also:
-
-
Method Details
-
start
default void start()Starts thisHandlerContext. -
stop
default void stop()Stops thisHandlerContext. -
invokeSingleUseHandler
default Object invokeSingleUseHandler(Attributes attributes, String module, String method, Object... args) Synchronously invokesinvokeSingleUseHandlerAsync(Consumer, Consumer, Attributes, String, String, Object...)blocking until the call returns.- Parameters:
attributes- theAttributessupplied to the underlyingResourcemodule- the module name used to instantiate the resourcemethod- the method to invokeargs- the arguments passed to the method- Returns:
- the invocation result
-
invokeSingleUseHandlerAsync
void invokeSingleUseHandlerAsync(Consumer<Object> success, Consumer<Throwable> failure, Attributes attributes, String module, String method, Object... args) Creates aResource, invokes a method on thatResource, and returns the result as either a success or a failure. TheHandlerContextwill assign a temporaryPath, andResourceIdwhich will not be exposed to the client code. Further, this will guaranteed the destruction of the createdResourceeven if the client abandons the call this method. The underlyingHandlerContextmay time out theResource. In which case the caller will receive an instance foHandlerTimeoutExceptionthrough the returnedFutureor in theConsumer<Throwable>handed to the method.- Parameters:
success- invoked when the invocation successfully returnsfailure- invoked whent he invocation encounters an errorattributes- theAttributessupplied to the underlyingResourcemodule- the module name used to instantiate the resourcemethod- the method to invokeargs- the arguments passed to the method
-
invokeRetainedHandler
default Object invokeRetainedHandler(Attributes attributes, String module, String method, Object... args) Synchronously invokesinvokeRetainedHandlerAsync(Consumer, Consumer, Attributes, String, String, Object...)blocking until the call returns.- Parameters:
attributes- theAttributessupplied to the underlyingResourcemodule- the module name used to instantiate the resourcemethod- the method to invokeargs- the arguments passed to the method- Returns:
- the invocation result
-
invokeRetainedHandlerAsync
void invokeRetainedHandlerAsync(Consumer<Object> success, Consumer<Throwable> failure, Attributes attributes, String module, String method, Object... args) Creates aResource, invokes a method on thatResource, and returns the result as either a success or a failure. TheHandlerContextwill assign a temporaryPath, andResourceIdwhich will not be exposed to the client code. UnlikeinvokeSingleUseHandlerAsync(Consumer, Consumer, Attributes, String, String, Object...)this will just unlink theResourceafter it invokes the specified method. It will be responsiblity of the invoked method to provide further retentions should it be desired. The underlyingHandlerContextmay time out theResource. In which case the caller will receive an instance foHandlerTimeoutExceptionthrough the returnedFutureor in theConsumer<Throwable>handed to the method.- Parameters:
success- invoked when the invocation successfully returnsfailure- invoked whent he invocation encounters an errorattributes- theAttributessupplied to the underlyingResourcemodule- the module name used to instantiate the resourcemethod- the method to invokeargs- the arguments passed to the method
-