Class MultipleInstancesResponseType<R>

java.lang.Object
org.axonframework.messaging.responsetypes.AbstractResponseType<List<R>>
org.axonframework.messaging.responsetypes.MultipleInstancesResponseType<R>
Type Parameters:
R - The response type which will be matched against and converted to
All Implemented Interfaces:
Serializable, ResponseType<List<R>>

public class MultipleInstancesResponseType<R> extends AbstractResponseType<List<R>>
A ResponseType implementation that will match with query handlers which return a multiple instances of the expected response type. If matching succeeds, the ResponseType.convert(Object) function will be called, which will cast the query handler it's response to a List with generic type R.
Since:
3.2
Author:
Steven van Beelen
See Also:
  • Field Details

  • Constructor Details

    • MultipleInstancesResponseType

      @ConstructorProperties("expectedResponseType") public MultipleInstancesResponseType(Class<R> expectedCollectionGenericType)
      Instantiate a MultipleInstancesResponseType with the given expectedCollectionGenericType as the type to be matched against and which the convert function will use as the generic for the List return value.
      Parameters:
      expectedCollectionGenericType - the response type which is expected to be matched against and returned
  • Method Details

    • matches

      public boolean matches(Type responseType)
      Match the query handler its response Type with this implementation its responseType R. Will return true in the following scenarios:
      • If the response type is an array of the expected type. For example a ExpectedType[]
      • If the response type is a GenericArrayType of the expected type. For example a <E extends ExpectedType> E[]
      • If the response type is a ParameterizedType containing a single TypeVariable which is assignable to the response type, taking generic types into account. For example a List<ExpectedType> or <E extends ExpectedType> List<E>.
      • If the response type is a ParameterizedType containing a single WildcardType which is assignable to the response type, taking generic types into account. For example a <E extends ExpectedType> List<? extends E>.
      • If the responseType is a single instance type matching the given Type.

      If there is no match at all, it will return false to indicate a non-match.

      Parameters:
      responseType - the response Type of the query handler which is matched against
      Returns:
      true for arrays, generic arrays and ParameterizedTypes (like a Iterable) for which the contained type is assignable to the expected type, ResponseType.MATCH for matching single instances and ResponseType.NO_MATCH for non-matches
    • matchRank

      public Integer matchRank(Type responseType)
      Match the query handler its response Type with this implementation its responseType R. Will return a value greater than 0 in the following scenarios:
      • ITERABLE_MATCH: If the response type is an array of the expected type. For example a ExpectedType[]
      • ITERABLE_MATCH: If the response type is a GenericArrayType of the expected type. For example a <E extends ExpectedType> E[]
      • ITERABLE_MATCH: If the response type is a ParameterizedType containing a single TypeVariable which is assignable to the response type, taking generic types into account. For example a List<ExpectedType> or <E extends ExpectedType> List<E>.
      • ITERABLE_MATCH: If the response type is a ParameterizedType containing a single WildcardType which is assignable to the response type, taking generic types into account. For example a <E extends ExpectedType> List<? extends E>.
      • ResponseType.MATCH: If the responseType is a single instance type matching the given Type.

      If there is no match at all, it will return ResponseType.NO_MATCH to indicate a non-match.

      Parameters:
      responseType - the response Type of the query handler which is matched against
      Returns:
      ITERABLE_MATCH for arrays, generic arrays and ParameterizedTypes (like a Iterable) for which the contained type is assignable to the expected type, ResponseType.MATCH for matching single instances and ResponseType.NO_MATCH for non-matches
    • convert

      public List<R> convert(Object response)
      Converts the given response of type Object into the type List with generic type R from this ResponseType instance. Will ensure that if the given response is of another collections format (e.g. an array, or a Stream) that it will be converted to a List. Should only be called if ResponseType.matches(Type) returns true. Will throw an IllegalArgumentException if the given response is not convertible to a List of the expected response type.
      Parameters:
      response - the Object to convert into a List of generic type R
      Returns:
      a List of generic type R, based on the given response
    • responseMessagePayloadType

      public Class responseMessagePayloadType()
      Description copied from interface: ResponseType
      Returns a Class representing the type of the payload to be contained in the response message.
      Returns:
      a Class representing the type of the payload to be contained in the response message
    • toString

      public String toString()
      Overrides:
      toString in class Object