Class ProcessingContextUtils

java.lang.Object
io.axoniq.framework.workflow.runtime.util.ProcessingContextUtils

@Internal public class ProcessingContextUtils extends Object
Processing context utility functions.
Since:
5.4.0
Author:
Simon Zambrovski, Steven van Beelen
  • Method Details

    • executeWithResult

      public static <R> CompletableFuture<R> executeWithResult(@Nullable String id, UnitOfWorkFactory unitOfWorkFactory, Executor executor, Context parentContext, Function<ProcessingContext,CompletableFuture<R>> action)
      Executes supplied action in a new processing context created via unit of work factory as a child of the provided processing context.
      Type Parameters:
      R - type of action result.
      Parameters:
      id - id of the unit of work.
      unitOfWorkFactory - unit of work factory to use.
      executor - executor to offload the action to.
      parentContext - parent processing context.
      action - action to execute.
      Returns:
      result of the action encapsulated in completable future.
    • executeWithResultInSeparateThread

      public static <R> CompletableFuture<R> executeWithResultInSeparateThread(@Nullable String id, UnitOfWorkFactory unitOfWorkFactory, ExecutorService executorService, ProcessingContext parentContext, Function<ProcessingContext,CompletableFuture<R>> action)
      Executes supplied action in a new thread and processing context created via unit of work factory as a child of the provided processing context. See executeWithResult(String, UnitOfWorkFactory, Executor, Context, Function) for running the action in the same thread.

      The returned future represents the complete action lifetime. For workflow bodies, that includes time spent parked while waiting for events or timers. It is composed rather than joined, so the submitting executor thread remains available while the workflow body is parked. This is not a durable-publication wait, so it must not use FutureResolver or apply a resolution timeout.

      Type Parameters:
      R - type of action result.
      Parameters:
      id - id of the unit of work.
      unitOfWorkFactory - unit of work factory to use.
      executorService - executor service to offload the action to.
      parentContext - parent processing context.
      action - action to execute.
      Returns:
      a future completing with the action result once the child unit of work completes
    • copyResources

      public static ProcessingContext copyResources(Context from, ProcessingContext to)
      Copies resources from the given context to the target processing context.

      An EventStoreTransaction is deliberately left behind. It stays bound to the unit of work that opened it, so appending through a copy registers the append on that unit of work and fails once it has committed. A workflow instance restored while a segment is claimed sources its state in the claim's short-lived unit of work and keeps that context on its steps; without this, every event the instance publishes afterwards would be routed back into the finished claim, leaving it restored but unable to make progress. Skipping the transaction makes to open its own.

      A resource to already holds wins over the one from carries under the same key. The target opens its own unit of work, and a transaction manager binds a connection to that one; overwriting it with the source's connection makes the target write on a connection it never commits, so on PostgreSQL its event stays uncommitted and the next append conflicts with it.

      Parameters:
      from - source containing resources.
      to - target processing context.
      Returns:
      resulting processing context.