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 String
The timeout for theHandlerContext
in milliseconds. -
Method Summary
Modifier and TypeMethodDescriptiondefault Object
invokeRetainedHandler
(Attributes attributes, String module, String method, Object... args) Synchronously invokesinvokeRetainedHandlerAsync(Consumer, Consumer, Attributes, String, String, Object...)
blocking until the call returns.void
invokeRetainedHandlerAsync
(Consumer<Object> success, Consumer<Throwable> failure, Attributes attributes, String module, String method, Object... args) default Object
invokeSingleUseHandler
(Attributes attributes, String module, String method, Object... args) Synchronously invokesinvokeSingleUseHandlerAsync(Consumer, Consumer, Attributes, String, String, Object...)
blocking until the call returns.void
invokeSingleUseHandlerAsync
(Consumer<Object> success, Consumer<Throwable> failure, Attributes attributes, String module, String method, Object... args) default void
start()
Starts thisHandlerContext
.default void
stop()
Stops thisHandlerContext
.
-
Field Details
-
HANDLER_TIMEOUT_MSEC
The timeout for theHandlerContext
in 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
- theAttributes
supplied to the underlyingResource
module
- 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. TheHandlerContext
will assign a temporaryPath
, andResourceId
which will not be exposed to the client code. Further, this will guaranteed the destruction of the createdResource
even if the client abandons the call this method. The underlyingHandlerContext
may time out theResource
. In which case the caller will receive an instance foHandlerTimeoutException
through the returnedFuture
or in theConsumer<Throwable>
handed to the method.- Parameters:
success
- invoked when the invocation successfully returnsfailure
- invoked whent he invocation encounters an errorattributes
- theAttributes
supplied to the underlyingResource
module
- 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
- theAttributes
supplied to the underlyingResource
module
- 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. TheHandlerContext
will assign a temporaryPath
, andResourceId
which will not be exposed to the client code. UnlikeinvokeSingleUseHandlerAsync(Consumer, Consumer, Attributes, String, String, Object...)
this will just unlink theResource
after it invokes the specified method. It will be responsiblity of the invoked method to provide further retentions should it be desired. The underlyingHandlerContext
may time out theResource
. In which case the caller will receive an instance foHandlerTimeoutException
through the returnedFuture
or in theConsumer<Throwable>
handed to the method.- Parameters:
success
- invoked when the invocation successfully returnsfailure
- invoked whent he invocation encounters an errorattributes
- theAttributes
supplied to the underlyingResource
module
- the module name used to instantiate the resourcemethod
- the method to invokeargs
- the arguments passed to the method
-