Interface MaterializationAware

All Known Implementing Classes:
ConnectionExecutor, EntityManagerExecutor

@Internal public interface MaterializationAware
Optionally implemented by a TransactionalExecutor that lazily materializes its resource, so
invalid reference
TransactionalExecutorProvider#applyPreferringIndependent
can prefer an independently-managed resource over forcing this one to materialize - reusing it instead when it's already active.

Deliberately kept off TransactionalExecutor itself: materialization awareness is a provider-orchestration concern, not an operation a consumer of a TransactionalExecutor should ever need - consumers only need accept/apply.

Since:
5.4.0
Author:
John Hendrikx
  • Method Details

    • withMaterializationShielded

      <R> R withMaterializationShielded(Function<Boolean,R> decision)
      Runs decision, passing whether this executor already has a resource materialized, while preventing a concurrent TransactionalExecutor.apply(org.axonframework.common.function.ThrowingFunction<T, R, java.lang.Exception>) call from materializing it for the duration - so a caller can fall back to an independent executor without racing a concurrent materialization.
      Type Parameters:
      R - the type of the result produced by decision
      Parameters:
      decision - given true if this executor already has a resource materialized, otherwise false; run shielded from a concurrent materialization, cannot be null
      Returns:
      the result of decision
      Throws:
      NullPointerException - when decision is null