Interface MethodPatternMatcher<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 Known Implementing Classes:
    SingleArgumentAnnotatedMethodPatternMatcher

    public interface MethodPatternMatcher<ARGUMENT_COMMON_ROOT_TYPE>
    Strategy interface that determines the mechanics of which methods are candidates for matching, what type a given method supports and how the method is invoked
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void invokeMethod​(Method methodToInvoke, Object argument, Object invokeMethodOn, Class<?> resolvedInvokeMethodWithArgumentOfType)
      This method is responsible for calling the methodToInvoke on the invokeMethodOnObject object using the right parameters based on the withObject.
      For simple cases the argument will only be the withObject, where it for other cases may involve extracting the real object to pass onto the methodToInvoke from within the withObject (e.g.
      boolean isInvokableMethod​(Method candidateMethod)
      Determines if a candidateMethod is a candidate for being invoked by PatternMatchingMethodInvoker
      Class<?> resolveInvocationArgumentTypeFromMethodDefinition​(Method method)
      Returns the (single) type this method can be invoked with.
      Class<?> resolveInvocationArgumentTypeFromObject​(Object argument)
      Resolves which type should be used for looking up matching invokable methods
      In simple cases this will be the same type as the argument's, but for enveloped types (such as Messages that encapsulate a payload) we may want to match methods against the message' payload type instead of the message type
    • Method Detail

      • isInvokableMethod

        boolean isInvokableMethod​(Method candidateMethod)
        Determines if a candidateMethod is a candidate for being invoked by PatternMatchingMethodInvoker
        Parameters:
        candidateMethod - the candidate method to test for invocation
        Returns:
        true if the candidateMethod is invokable, otherwise false
      • resolveInvocationArgumentTypeFromMethodDefinition

        Class<?> resolveInvocationArgumentTypeFromMethodDefinition​(Method method)
        Returns the (single) type this method can be invoked with. This method MUST return the type supported OR throw a RuntimeException in case the method doesn't allow resolving a type
        Parameters:
        method - the method to resolve the invokeWithObject type (requirement the method has passed the isInvokableMethod(Method) test)
        Returns:
        The type supported
      • resolveInvocationArgumentTypeFromObject

        Class<?> resolveInvocationArgumentTypeFromObject​(Object argument)
        Resolves which type should be used for looking up matching invokable methods
        In simple cases this will be the same type as the argument's, but for enveloped types (such as Messages that encapsulate a payload) we may want to match methods against the message' payload type instead of the message type
        Parameters:
        argument - the argument instance
        Returns:
        the type that should be used for looking up matching invokable methods
      • invokeMethod

        void invokeMethod​(Method methodToInvoke,
                          Object argument,
                          Object invokeMethodOn,
                          Class<?> resolvedInvokeMethodWithArgumentOfType)
                   throws Exception
        This method is responsible for calling the methodToInvoke on the invokeMethodOnObject object using the right parameters based on the withObject.
        For simple cases the argument will only be the withObject, where it for other cases may involve extracting the real object to pass onto the methodToInvoke from within the withObject (e.g. in case of a wrapped type, such as a message object that contains the real payload to supply to the methodToInvoke)
        Parameters:
        methodToInvoke - the method that must be reflectively invoked. You can assume that the method is Acessible already
        argument - The argument instance passed to PatternMatchingMethodInvoker.invoke(Object)/PatternMatchingMethodInvoker.invoke(Object, NoMatchingMethodsHandler) and which was used in the call to resolveInvocationArgumentTypeFromObject(Object)
        In simple cases this will be the same type as the argument's, but for enveloped types (such as Messages that encapsulate a payload) we may want to match methods against the message' payload type instead of the message type.
        invokeMethodOn - the object that the methodToInvoke must be invoked on (the target object of the Method.invoke(Object, Object...))
        resolvedInvokeMethodWithArgumentOfType - The resolved withObjectType (as resolved by resolveInvocationArgumentTypeFromObject(Object))
        Throws:
        Exception - Feel free to throw any Reflection exceptions, etc.
        The PatternMatchingMethodInvoker will ensure to either unwrap the real cause or wrap any checked exceptions in a Runtime exception.