Interface EntityHelper

All Known Implementing Classes:
DefaultEntityHelper

public interface EntityHelper
Strategy interface for handling domain entity operations such as applying updates, validating state transitions, and intercepting updates.

Implementations of this interface coordinate the invocation of methods annotated with InterceptApply, AssertLegal, and Apply.

These operations allow Flux Capacitor entities to transform messages before applying them, enforce invariants, and apply updates.

  • Method Details

    • intercept

      Stream<?> intercept(Object value, Entity<?> entity)
      Intercepts the given value before it is applied to an entity. This may result in transformation or expansion of the value to one or more derived messages.
      Parameters:
      value - the value to be intercepted, typically the payload of a message
      entity - the entity receiving the value
      Returns:
      a stream of intercepted values or messages to be applied
    • applyInvoker

      default Optional<HandlerInvoker> applyInvoker(DeserializingMessage message, Entity<?> entity)
      Returns an invoker that can apply the given event to the provided entity.
      Parameters:
      message - the message to apply
      entity - the entity to which the message should be applied
      Returns:
      a handler invoker if an applicable handler method is found
    • applyInvoker

      Optional<HandlerInvoker> applyInvoker(DeserializingMessage message, Entity<?> entity, boolean searchChildren)
      Returns an invoker for applying the event to the entity, optionally checking nested entities.
      Parameters:
      message - the event to apply
      entity - the root or intermediate entity
      searchChildren - whether to search nested child entities for applicable handlers
      Returns:
      a handler invoker if a suitable method is located
    • assertLegal

      <E extends Exception> void assertLegal(Object value, Entity<?> entity) throws E
      Validates whether the given value results in a legal state transition for the specified entity. Throws an exception if the result would be illegal.
      Type Parameters:
      E - the type of exception that may be thrown
      Parameters:
      value - the value to validate
      entity - the current entity state
      Throws:
      E - if the value is deemed illegal
    • checkLegality

      <E extends Exception> Optional<E> checkLegality(Object value, Entity<?> entity)
      Checks if the given value would be considered legal for the specified entity. Does not throw but instead returns an exception if illegal.
      Type Parameters:
      E - the type of exception
      Parameters:
      value - the value to validate
      entity - the entity context
      Returns:
      an exception if illegal, or an empty Optional if legal
    • isLegal

      boolean isLegal(Object value, Entity<?> entity)
      Returns whether the given value is considered legal for the specified entity.
      Parameters:
      value - the value to check
      entity - the entity context
      Returns:
      true if legal, false otherwise