Class ConcurrencyOperation<T>

Type Parameters:
T - the result type of this operation
All Implemented Interfaces:
DurableFuture<T>
Direct Known Subclasses:
MapOperation, ParallelOperation

public abstract class ConcurrencyOperation<T> extends SerializableDurableOperation<T>
Abstract base class for concurrent execution of multiple child context operations.

Encapsulates shared concurrency logic: queue-based concurrency control, success/failure counting, and completion checking. Both ParallelOperation and MapOperation extend this base.

Key design points:

  • Does NOT register its own thread — child context threads handle all suspension
  • Uses a pending queue + running counter for concurrency control
  • Completion is determined by subclass-specific logic via abstract canComplete() and validateItemCount()
  • When a child suspends, the running count is NOT decremented
  • Field Details

  • Constructor Details

  • Method Details

    • createItem

      protected <R> ChildContextOperation<R> createItem(String operationId, String name, Function<DurableContext,R> function, TypeToken<R> resultType, SerDes serDes, OperationSubType branchSubType, DurableContextImpl parentContext)
      Creates a child context operation for a single item (branch or iteration).
      Type Parameters:
      R - the result type of the child operation
      Parameters:
      operationId - the unique operation ID for this item
      name - the name of this item
      function - the user function to execute
      resultType - the result type token
      branchSubType - the sub-type of the branch operation
      parentContext - the parent durable context
      Returns:
      a new ChildContextOperation
    • handleCompletion

      protected abstract void handleCompletion(ConcurrencyCompletionStatus concurrencyCompletionStatus)
      Called when the concurrency operation completes. Subclasses define checkpointing behavior.
    • enqueueItem

      protected <R> ChildContextOperation<R> enqueueItem(String name, Function<DurableContext,R> function, TypeToken<R> resultType, SerDes serDes, OperationSubType branchSubType)
      Creates and enqueues an item without starting execution. Use executeItems() to begin execution after all items have been enqueued. This prevents early termination from blocking item creation when all items are known upfront (e.g., map operations).
    • executeItems

      protected void executeItems()
      Starts execution of all enqueued items.
    • join

      protected void join()
      Blocks the calling thread until the concurrency operation reaches a terminal state. Validates item count, handles zero-branch case, then delegates to waitForOperationCompletion() from BaseDurableOperation.
    • getBranches

      protected List<ChildContextOperation<?>> getBranches()