Class MigrateLegacyFixtureInterceptorLambdas

java.lang.Object
org.openrewrite.Recipe
org.axonframework.migration.MigrateLegacyFixtureInterceptorLambdas
All Implemented Interfaces:
Cloneable

public class MigrateLegacyFixtureInterceptorLambdas extends org.openrewrite.Recipe
Rewrites the Axon Framework 4 interceptor lambdas registered on the legacy test fixtures to the Axon Framework 5 interceptor signatures, which the fixtures ported by axoniq-legacy-test take.

Axon Framework 4 dispatch interceptors were a function over a message batch, messages -> (index, message) -> changed, and handler interceptors received the unit of work, (unitOfWork, chain) -> chain.proceed(), changing the message through unitOfWork.transformMessage(..). Axon Framework 5 interceptors receive the single message, the processing context and the chain, and continue by handing the (possibly changed) message to the chain. The recipe rewrites the lambdas passed to:

  • SagaTestFixture and the Saga FixtureConfiguration: registerDeadlineDispatchInterceptor(..), registerDeadlineHandlerInterceptor(..) and registerEventHandlerInterceptor(..);
  • StubDeadlineManager: registerDispatchInterceptor(..) and registerHandlerInterceptor(..).
These shapes are rewritten, each to (message, context, chain) -> chain.proceed(..., context):
  • messages -> (i, m) -> expression, passing the expression with m renamed;
  • messages -> (i, m) -> { statements; return expression; }, keeping the statements and passing the returned expression, with m renamed, when the block has no other return;
  • (unitOfWork, chain) -> chain.proceed(), passing the message unchanged;
  • (unitOfWork, chain) -> { statements; return chain.proceed(); }, keeping the statements and passing the message unchanged, when the statements use the unit of work only to read unitOfWork.getMessage(), which becomes the message, and neither use the chain nor return;
  • (unitOfWork, chain) -> { unitOfWork.transformMessage(m -> expression); return chain.proceed(); }, passing the expression with m renamed.
Any other interceptor written in place (a lambda of another shape, one that still uses the batch, index, unit of work or chain otherwise, a method reference, or an anonymous class) gets a // TODO(axon4to5): marker on its statement describing the Axon Framework 5 signature. An interceptor passed as a variable or as an instance of a named class is left alone: the class is migrated by MigrateMessageInterceptorSignatures. Lambda parameter names that would clash with a name already in scope get a numeric suffix. Java sources only. Idempotent: a lambda already taking three parameters is in the Axon Framework 5 shape and is left alone.
Since:
5.4.0
Author:
Mateusz Nowak
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.openrewrite.Recipe

    org.openrewrite.Recipe.Builder, org.openrewrite.Recipe.DelegatingRecipe
  • Field Summary

    Fields inherited from class org.openrewrite.Recipe

    contributors, examples, PANIC
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
     
     
    org.openrewrite.TreeVisitor<?,org.openrewrite.ExecutionContext>
     

    Methods inherited from class org.openrewrite.Recipe

    addDataTable, aggregateDataTableDescriptors, builder, buildRecipeList, causesAnotherCycle, clone, createRecipeDescriptor, equals, getContributors, getDataTableDescriptors, getDescriptor, getEstimatedEffortPerOccurrence, getExamples, getInstanceName, getInstanceNameSuffix, getJacksonPolymorphicTypeTag, getMaintainers, getName, getRecipeList, getTags, hashCode, maxCycles, noop, onComplete, run, run, run, setContributors, setExamples, validate, validate, validateAll, validateAll, withOptions

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MigrateLegacyFixtureInterceptorLambdas

      public MigrateLegacyFixtureInterceptorLambdas()
  • Method Details

    • getDisplayName

      public String getDisplayName()
      Specified by:
      getDisplayName in class org.openrewrite.Recipe
    • getDescription

      public String getDescription()
      Specified by:
      getDescription in class org.openrewrite.Recipe
    • getVisitor

      public org.openrewrite.TreeVisitor<?,org.openrewrite.ExecutionContext> getVisitor()
      Overrides:
      getVisitor in class org.openrewrite.Recipe