Class AnnotatedCommandHandlingComponent<T>
- Type Parameters:
T- The target type of this command handling component.
- All Implemented Interfaces:
DescribableComponent,CommandHandler,CommandHandlingComponent,MessageHandler
CommandHandler
annotated methods into a CommandHandlingComponent.
Each annotated method is subscribed as a CommandHandler at the CommandHandlingComponent with the
command name specified by the parameter of that method.
- Since:
- 0.5.0
- Author:
- Allard Buijze
-
Constructor Summary
ConstructorsConstructorDescriptionAnnotatedCommandHandlingComponent(T annotatedCommandHandler, ParameterResolverFactory parameterResolverFactory, HandlerDefinition handlerDefinition, MessageTypeResolver messageTypeResolver, MessageConverter converter) Wraps the givenannotatedCommandHandler, allowing it to be subscribed to aCommandBusas aCommandHandlingComponent. -
Method Summary
Modifier and TypeMethodDescriptionvoiddescribeTo(ComponentDescriptor descriptor) Describe the properties ofthis DescribableComponentwith the givendescriptor.handle(CommandMessage command, ProcessingContext processingContext) Handles the givencommandwithin the givencontext.All supportedcommands, referenced through aQualifiedName.
-
Constructor Details
-
AnnotatedCommandHandlingComponent
public AnnotatedCommandHandlingComponent(@Nonnull T annotatedCommandHandler, @Nonnull ParameterResolverFactory parameterResolverFactory, @Nonnull HandlerDefinition handlerDefinition, @Nonnull MessageTypeResolver messageTypeResolver, @Nonnull MessageConverter converter) Wraps the givenannotatedCommandHandler, allowing it to be subscribed to aCommandBusas aCommandHandlingComponent.- Parameters:
annotatedCommandHandler- The object containing theCommandHandlerannotated methods.parameterResolverFactory- The parameter resolver factory to resolve handler parameters with.handlerDefinition- The handler definition used to create concrete handlers.messageTypeResolver- TheMessageTypeResolverresolving thenamesforCommandMessages.converter- The converter to use for converting the payload of the command to the type expected by the handling method.
-
-
Method Details
-
handle
@Nonnull public MessageStream.Single<CommandResultMessage> handle(@Nonnull CommandMessage command, @Nonnull ProcessingContext processingContext) Description copied from interface:CommandHandlerHandles the givencommandwithin the givencontext.The
result messagein the returnedstreammay benull. Only asingleoremptyresult message should ever be expected.- Specified by:
handlein interfaceCommandHandler- Parameters:
command- The command to handle.processingContext- The context to the givencommandis handled in.- Returns:
- A
MessagesStream.Singleof aCommandResultMessage.
-
supportedCommands
Description copied from interface:CommandHandlingComponentAll supportedcommands, referenced through aQualifiedName.- Specified by:
supportedCommandsin interfaceCommandHandlingComponent- Returns:
- All supported
commands, referenced through aQualifiedName.
-
describeTo
Description copied from interface:DescribableComponentDescribe the properties ofthis DescribableComponentwith the givendescriptor.Components should call the appropriate
describePropertymethods on the descriptor to register their properties. The descriptor is responsible for determining how these properties are formatted and structured in the final output.Best Practices: As a general rule, all relevant fields of a
DescribableComponentimplementation should be described in this method. However, developers have discretion to include only the fields that make sense in the context. Not every field may be meaningful for description purposes, especially internal implementation details. Furthermore, components might want to expose different information based on their current state. The final decision on what properties to include lies with the person implementing thedescribeTomethod, who should focus on providing information that is useful for understanding the component's configuration and state.Example implementation:
public void describeTo(ComponentDescriptor descriptor) { descriptor.describeProperty("name", this.name); descriptor.describeProperty("enabled", this.enabled); descriptor.describeProperty("configuration", this.configuration); // A nested component descriptor.describeProperty("handlers", this.eventHandlers); // A collection }- Specified by:
describeToin interfaceDescribableComponent- Parameters:
descriptor- The component descriptor to describethis DescribableComponentn its properties in.
-