Class LocalExecution

java.lang.Object
io.fluxzero.sdk.tracking.handling.LocalExecution
All Implemented Interfaces:
HandlerInput<DeserializingMessage>, LocalHandlerInput

public final class LocalExecution extends Object implements LocalHandlerInput
Holds the state of one payload-first local handler invocation.

This is a Fluxzero infrastructure type. It is public so dispatch interceptors, handler registries, and parameter resolvers in different SDK packages can cooperate on the same lazy invocation. Applications should not construct, retain, or reuse an instance. An execution is confined to the invoking thread and its contents are valid only while that invocation is active.

  • Method Details

    • handle

      public static LocalExecution handle(Object payload, MessageType messageType, String topic, Serializer serializer, PreparedLocalDispatch dispatch, HandlerRegistry registry)
      Attempts to handle a payload through the prepared local path.

      This infrastructure method returns null when prepared handling is unsafe in the current context or when the registry requests the regular message-based path. A non-null execution contains the completed local result and must be followed by releaseResult() after the result has been consumed.

      Parameters:
      payload - the dispatched payload
      messageType - the type of message being dispatched
      topic - the dispatch topic, or null
      serializer - the serializer used if a complete message becomes necessary
      dispatch - the prepared dispatch-interceptor policy
      registry - the local handler registry
      Returns:
      the completed execution, or null to use regular message-based dispatch
    • complete

      public void complete(Object value)
      Stores a synchronously completed handler value in this execution.
      Parameters:
      value - the value returned by the handler
    • completeAsync

      public void completeAsync(CompletableFuture<?> future)
      Stores an asynchronous handler result in this execution.
      Parameters:
      future - the handler result future
    • completeExceptionally

      public void completeExceptionally(Throwable error)
      Stores a handler failure in this execution.
      Parameters:
      error - the handling error
    • isCompletedSuccessfully

      public boolean isCompletedSuccessfully()
      Returns whether handling completed synchronously without throwing.
      Returns:
      true when getResult() contains the synchronous result
    • getResult

      public Object getResult()
      Returns the synchronously completed handler value.
      Returns:
      the handler value, which may be null
    • getResultFuture

      public CompletableFuture<Object> getResultFuture()
    • getResultMessage

      public Message getResultMessage()
    • releaseResult

      public void releaseResult()
    • currentMessage

      public static DeserializingMessage currentMessage()
      Returns the message for the active payload-first invocation on this thread.

      Calling this method materializes the message if necessary.

      Returns:
      the active local message, or null outside a payload-first invocation
    • markBatchContextUsed

      public static void markBatchContextUsed()
      Marks batch-scoped message state as used by the active payload-first handler.

      This infrastructure hook ensures that batch callbacks and resources are completed after the invocation.

    • getPayload

      public Object getPayload()
      Returns the payload that is being handled.
      Specified by:
      getPayload in interface HandlerInput<DeserializingMessage>
      Returns:
      the payload; never null
    • getMessage

      public DeserializingMessage getMessage()
      Returns the message that contains the payload, creating it first when necessary.
      Specified by:
      getMessage in interface HandlerInput<DeserializingMessage>
      Returns:
      the message being handled
    • getMessageIfAvailable

      public DeserializingMessage getMessageIfAvailable()
      Returns the message if it is already available.

      The default implementation calls HandlerInput.getMessage(). Implementations that create messages lazily should override this method and return null while no message has been created.

      Specified by:
      getMessageIfAvailable in interface HandlerInput<DeserializingMessage>
      Returns:
      the existing message, or null if a lazy implementation has not created it yet
    • getMessageType

      public MessageType getMessageType()
      Returns the type of message being handled.
      Specified by:
      getMessageType in interface LocalHandlerInput
      Returns:
      the current message type
    • getUser

      public User getUser(UserProvider provider)
      Returns the user selected for this local dispatch.
      Specified by:
      getUser in interface LocalHandlerInput
      Parameters:
      provider - the configured provider whose user is requested
      Returns:
      the resolved user, or null if the dispatch has no user
    • setUser

      public void setUser(User user)
      Stores the user selected during dispatch for later handler-parameter resolution.
      Parameters:
      user - the selected user, or null
    • hasResolvedUser

      public boolean hasResolvedUser()
      Returns whether user resolution has already completed for this input.
      Specified by:
      hasResolvedUser in interface LocalHandlerInput
      Returns:
      true when LocalHandlerInput.getUser(UserProvider) can be used without materializing the message
    • getMetadata

      public Metadata getMetadata()
      Returns the local message metadata, computing deferred metadata changes when necessary.
      Specified by:
      getMetadata in interface LocalHandlerInput
      Returns:
      the current metadata
    • containsMetadata

      public boolean containsMetadata(String key)
      Tests already available metadata without forcing deferred metadata creation.
      Specified by:
      containsMetadata in interface LocalHandlerInput
      Parameters:
      key - the metadata key to look up
      Returns:
      true if already available metadata contains the key
    • getIndex

      public Long getIndex()
      Returns the message index when the local input represents a stored message.
      Specified by:
      getIndex in interface LocalHandlerInput
      Returns:
      the message index, or null for a newly dispatched local message
    • invoke

      Invokes a prepared handler plan while installing the required local handling context.
      Specified by:
      invoke in interface LocalHandlerInput
      Parameters:
      plan - the handler plan to invoke
      Returns:
      the handler result