Package org.axonframework.migration
Class MigrateCommandGatewayInEventHandler
java.lang.Object
org.openrewrite.Recipe
org.axonframework.migration.MigrateCommandGatewayInEventHandler
- All Implemented Interfaces:
Cloneable
public class MigrateCommandGatewayInEventHandler
extends org.openrewrite.Recipe
Migrates an Axon Framework 4 event-handling component that dispatches commands via a class-level
CommandGateway field to the AF5 in-handler pattern: a method-parameter CommandDispatcher.
Decision rule from CommandDispatcher's Javadoc — gateway for top-of-chain entry points (controllers,
runners), dispatcher inside another message handler. Inside an @EventHandler the active
ProcessingContext makes CommandDispatcher the right tool, and AF5's dispatcher is auto-injected
into handler methods by the CommandDispatcherParameterResolverFactory. This recipe automates that
mechanical part of the migration:
- Inside every
@EventHandlermethod that calls<field>.send(...)or<field>.sendAndWait(...)on a class field of typeCommandGateway, the call is rewritten tocommandDispatcher.send(...)(theAndWaitsuffix is dropped — AF5's dispatcher only exposes the asyncsendfamily). - A
CommandDispatcher commandDispatcherparameter is appended to the method signature when the method does not already declare one. - For methods whose return type is
voidand whose body matches one of two supported shapes — a single dispatch expression statement, or a single try/catch where each branch ends in a dispatch expression statement — the return type is widened toCompletableFuture<?>, the dispatch expression is converted toreturn ... .getResultMessage();, andjava.util.concurrent.CompletableFutureis imported. Methods with non-voidreturn types (e.g.Mono<?>, custom types) are left alone — the call rewrite still applies, but the surrounding adaptation is left to the human. - Once every
@EventHandlerin the class has been visited, the recipe checks whether theCommandGatewayfield is still referenced anywhere. If it is not, the field declaration, the corresponding constructor parameter, and any matchingthis.field = field;assignment are removed — and the now-unusedCommandGatewayimport is dropped.
Axon4ToAxon5Messaging
package renames in the same composite. Anything that does not match the supported shapes (loops, multi-dispatch
branches, conditional dispatch, reactive return types) is left untouched: the build will still surface those
call sites as compile errors so the human can address them.- Since:
- 5.1.1
- 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 -
Method Summary
Modifier and TypeMethodDescriptionorg.openrewrite.TreeVisitor<?, org.openrewrite.ExecutionContext> Methods inherited from class org.openrewrite.Recipe
addDataTable, 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
-
Constructor Details
-
MigrateCommandGatewayInEventHandler
public MigrateCommandGatewayInEventHandler()
-
-
Method Details
-
getDisplayName
- Specified by:
getDisplayNamein classorg.openrewrite.Recipe
-
getDescription
- Specified by:
getDescriptionin classorg.openrewrite.Recipe
-
getVisitor
public org.openrewrite.TreeVisitor<?,org.openrewrite.ExecutionContext> getVisitor()- Overrides:
getVisitorin classorg.openrewrite.Recipe
-