Class SingleArgumentAnnotatedMethodPatternMatcher<ARGUMENT_COMMON_ROOT_TYPE>

  • Type Parameters:
    ARGUMENT_COMMON_ROOT_TYPE - The method argument common root type (i.e. a common superclass or common interface) for the argument-type that we're performing pattern matching on.
    If there isn't a common root type, then you can specify Object instead

    Example: Within a single class we have placed a set methods that can handle OrderEvent's, such as OrderCreated, OrderShipped, OrderAccepted, etc.
    In this case OrderEvent will be our ARGUMENT_ROOT_TYPE as it forms the root of the type hierarchy.

    All Implemented Interfaces:
    MethodPatternMatcher<ARGUMENT_COMMON_ROOT_TYPE>

    public class SingleArgumentAnnotatedMethodPatternMatcher<ARGUMENT_COMMON_ROOT_TYPE>
    extends Object
    implements MethodPatternMatcher<ARGUMENT_COMMON_ROOT_TYPE>
    A strategy that matches methods annotated with matchOnMethodsAnnotatedWith and have a single method argument that is the same type or a sub-type of the ARGUMENT_COMMON_ROOT_TYPE

    Example using parameterized types:
    
     var patternMatchingInvoker = new PatternMatchingMethodInvoker<>(invokeMethodsOn,
                                                                     new SingleArgumentAnnotatedMethodPatternMatcher<>(EventHandler.class,
                                                                                                                       new GenericType<Event<OrderId>>() {}),
                                                                     InvocationStrategy.InvokeMostSpecificTypeMatched);
     
    Example using non-parameterized types:
    
     var patternMatchingInvoker = new PatternMatchingMethodInvoker<>(invokeMethodsOn,
                                                                     new SingleArgumentAnnotatedMethodPatternMatcher<>(EventHandler.class,
                                                                                                                       OrderEvent.class),
                                                                     InvocationStrategy.InvokeMostSpecificTypeMatched);
     
    Usage:
    
     invoker.invoke(event, unmatchedEvent -> {
         // Decide how to handle if a given event doesn't have a corresponding handler
     });
     
    • Constructor Detail

      • SingleArgumentAnnotatedMethodPatternMatcher

        public SingleArgumentAnnotatedMethodPatternMatcher​(Class<? extends Annotation> matchOnMethodsAnnotatedWith,
                                                           Class<ARGUMENT_COMMON_ROOT_TYPE> argumentCommonRootType)
        Create a new strategy that matches methods annotated with matchOnMethodsAnnotatedWith and have a single method argument that is the same type or a sub-type of the ARGUMENT_COMMON_ROOT_TYPE
        Parameters:
        matchOnMethodsAnnotatedWith - the annotation that invokable methods are annotated with
        argumentCommonRootType - the base type for the single method argument
      • SingleArgumentAnnotatedMethodPatternMatcher

        public SingleArgumentAnnotatedMethodPatternMatcher​(Class<? extends Annotation> matchOnMethodsAnnotatedWith,
                                                           GenericType<ARGUMENT_COMMON_ROOT_TYPE> argumentCommonRootType)
        Create a new strategy that matches methods annotated with matchOnMethodsAnnotatedWith and have a single method argument that is the same type or a sub-type of the ARGUMENT_COMMON_ROOT_TYPE
        Parameters:
        matchOnMethodsAnnotatedWith - the annotation that invokable methods are annotated with
        argumentCommonRootType - the base type for the single method argument