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 Fluxzero entities to transform messages before applying them, enforce invariants, and apply updates.
-
Method Summary
Modifier and TypeMethodDescriptiondefault Optional<HandlerInvoker> applyInvoker(DeserializingMessage message, Entity<?> entity) Returns an invoker that can apply the given event to the provided entity.default Optional<HandlerInvoker> applyInvoker(DeserializingMessage message, Entity<?> entity, boolean searchChildren) Returns an invoker for applying the event to the entity, optionally checking nested entities.applyInvoker(DeserializingMessage message, Entity<?> entity, boolean searchChildren, boolean checkCompatibility) Returns an invoker for applying the event to the entity, optionally checking nested entities.<E extends Exception>
voidassertLegal(Object value, Entity<?> entity) Validates whether the given value results in a legal state transition for the specified entity.checkLegality(Object value, Entity<?> entity) Checks if the given value would be considered legal for the specified entity.Stream<?> Intercepts the given value before it is applied to an entity.booleanReturns whether the given value is considered legal for the specified entity.
-
Method Details
-
intercept
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 messageentity- the entity receiving the value- Returns:
- a stream of intercepted values or messages to be applied
-
applyInvoker
Returns an invoker that can apply the given event to the provided entity.- Parameters:
message- the message to applyentity- the entity to which the message should be applied- Returns:
- a handler invoker if an applicable handler method is found
-
applyInvoker
default 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 applyentity- the root or intermediate entitysearchChildren- whether to search nested child entities for applicable handlers- Returns:
- a handler invoker if a suitable method is located
-
applyInvoker
Optional<HandlerInvoker> applyInvoker(DeserializingMessage message, Entity<?> entity, boolean searchChildren, boolean checkCompatibility) Returns an invoker for applying the event to the entity, optionally checking nested entities.- Parameters:
message- the event to applyentity- the root or intermediate entitysearchChildren- whether to search nested child entities for applicable handlerscheckCompatibility- whether to check if the entity state is compatible with the event being applied- Returns:
- a handler invoker if a suitable method is located
-
assertLegal
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 validateentity- the current entity state- Throws:
E- if the value is deemed illegal
-
checkLegality
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 validateentity- the entity context- Returns:
- an exception if illegal, or an empty Optional if legal
-
isLegal
-