AsyncCallable

Provides access to the details of the asynchronous callable (representing a child command to be executed asynchronously) when using org.apache.causeway.applib.services.wrapper.WrapperFactory#asyncWrap(Object, AsyncControl) and its brethren.

To explain in a little more depth; we can execute commands (actions etc) asynchronously using org.apache.causeway.applib.services.wrapper.WrapperFactory#asyncWrap(Object, AsyncControl) or similar. The AsyncControl parameter allows various aspects of this to be controlled, one such being the implementation of the java.util.concurrent.ExecutorService (using AsyncControl#with(ExecutorService) ).

The default ExecutorService is just java.util.concurrent.ForkJoinPool , and this and similar implementations will hold the provided callable in memory and execute it in due course. For these out-of-the-box implementations, the java.util.concurrent.Callable is a black box and they have no need to look inside it. So long as the implementation of the Callable is not serialized then deserialized (ie is only ever held in memory), then all will work fine.

This interface, though, is intended to expose the details of the passed java.util.concurrent.Callable , most notably the CommandDto to be executed. The main use case this supports is to allow a custom implementation of ExecutorService to be provided that could do more sophisticated things, for example persisting the callable somewhere, either exploiting the fact that the object is serializable, or perhaps by unpacking the parts and persisting (for example, as a CommandLogEntry courtesy of the commandlog extension).

These custom implementations of ExecutorService must however reinitialize the state of the callable, either by injecting in services using org.apache.causeway.applib.services.inject.ServiceInjector and then just call() ing it, or alternatively and more straightforwardly simply executing it using org.apache.causeway.applib.services.wrapper.WrapperFactory#execute(AsyncCallable) .

API

AsyncCallable.java
interface AsyncCallable<R> {
  InteractionContext getInteractionContext()     (1)
  Propagation getPropagation()     (2)
  CommandDto getCommandDto()     (3)
  Class<R> getReturnType()     (4)
  UUID getParentInteractionId()     (5)
}
1 getInteractionContext()

The requested InteractionContext to execute the command, as inferred from the AsyncControl that was used to call org.apache.causeway.applib.services.wrapper.WrapperFactory#asyncWrap(Object, AsyncControl) and its ilk.

2 getPropagation()

The transaction propagation to use when creating a new org.apache.causeway.applib.services.iactn.Interaction in which to execute the child command.

3 getCommandDto()

Details of the actual child command (action or property edit) to be performed.

4 getReturnType()

The type of the object returned by the child command once finally executed.

5 getParentInteractionId()

The unique Command#getInteractionId() interactionId of the parent Command , which is to say the Command that was active in the original interaction where org.apache.causeway.applib.services.wrapper.WrapperFactory#asyncWrap(Object, AsyncControl) (or its brethren) was called.

Members

getInteractionContext()

The requested InteractionContext to execute the command, as inferred from the AsyncControl that was used to call org.apache.causeway.applib.services.wrapper.WrapperFactory#asyncWrap(Object, AsyncControl) and its ilk.

getPropagation()

The transaction propagation to use when creating a new org.apache.causeway.applib.services.iactn.Interaction in which to execute the child command.

getCommandDto()

Details of the actual child command (action or property edit) to be performed.

(Ultimately this is handed onto the org.apache.causeway.applib.services.command.CommandExecutorService ).

getReturnType()

The type of the object returned by the child command once finally executed.

getParentInteractionId()

The unique Command#getInteractionId() interactionId of the parent Command , which is to say the Command that was active in the original interaction where org.apache.causeway.applib.services.wrapper.WrapperFactory#asyncWrap(Object, AsyncControl) (or its brethren) was called.

This can be useful for custom implementations of ExecutorService that use the commandlog extension’s CommandLogEntry , to link parent and child commands together.