Package org.rribbit

Interface RequestResponseBus

All Known Implementing Classes:
DefaultRequestResponseBus

public interface RequestResponseBus
The bus to which requests can be sent and responses received. The following rules apply to all methods of this interface:
  • When you send a request, ALL Listeners that match the request are executed, even if you only send for a single result
  • The order in which the Listeners are executed is not specified
  • The order in which the results are returned is not specified and does not necessarily match the execution order of the Listeners
  • If exactly one of the Listeners throws a Throwable, then that Throwable is thrown
  • If multiple Listeners throw a Throwable, then a MultipleThrowablesOccurredException is thrown, containing all the Throwables that were thrown
  • If any method parameter is 'null', then an IllegalArgumentException is thrown (null values may occur in the 'parameters' varargs array, however)
Author:
G.J. Schouten
  • Method Details

    • sendForSingleOfClass

      <T> T sendForSingleOfClass(Class<T> returnType, Object... parameters)
      Send a request to all Listeners that satisfy the following requirements.
      • They return an Object that the parameter 'returnType' is assignable from and
      • they belong to a method with parameters that match the given 'parameters' objects
      Parameters:
      returnType - the return type that has to be assignable from the return type of the Listeners
      parameters - the parameters to give to the Listeners
      Returns:
      a single return value from one of the listeners that executed (which one is unspecified) or 'null' if no matching Listeners were found
    • sendForMultipleOfClass

      <T> Collection<T> sendForMultipleOfClass(Class<T> returnType, Object... parameters)
      Send a request to all Listeners that satisfy the following requirements.
      • They return an Object that the parameter 'returnType' is assignable from and
      • they belong to a method with parameters that match the given 'parameters' objects
      The number of Listeners that are executed may be larger than the number of return values that is returned, because some Listeners may return nothing (void).
      Parameters:
      returnType - the return type that has to be assignable from the return type of the Listeners
      parameters - the parameters to give to the Listeners
      Returns:
      all return values from the listeners that executed or an empty Collection if no matching Listeners were found. This method never returns null.
    • sendForNothing

      void sendForNothing(Object... parameters)
      Send a request to all Listeners that satisfy the following requirements. Ignore all return values and return nothing.
      • They belong to a method with parameters that match the given 'parameters' objects
      Parameters:
      parameters - the parameters to give to the Listeners
    • sendForSingleWithHint

      <T> T sendForSingleWithHint(String hint, Object... parameters)
      Send a request to all Listeners that satisfy the following requirements.
      • They have a hint that is equals to the 'hint' parameter and
      • they belong to a method with parameters that match the given 'parameters' objects
      Parameters:
      hint - the hint that has to be equal to the hint of the Listeners
      parameters - the parameters to give to the Listeners
      Returns:
      a single return value from one of the listeners that executed (which one is unspecified) or 'null' if no matching Listeners were found or none of them returned anything
    • sendForMultipleWithHint

      <T> Collection<T> sendForMultipleWithHint(String hint, Object... parameters)
      Send a request to all Listeners that satisfy the following requirements.
      • They have a hint that is equals to the 'hint' parameter and
      • they belong to a method with parameters that match the given 'parameters' objects
      The number of Listeners that are executed may be larger than the number of return values that is returned, because some Listeners may return nothing (void).
      Parameters:
      hint - the hint that has to be equal to the hint of the Listeners
      parameters - the parameters to give to the Listeners
      Returns:
      all return values from the listeners that executed or an empty Collection if no matching Listeners were found or none of them returned anything. This method never returns null.
    • sendForNothingWithHint

      void sendForNothingWithHint(String hint, Object... parameters)
      Send a request to all Listeners that satisfy the following requirements. Ignore all return values and return nothing.
      • They have a hint that is equals to the 'hint' parameter and
      • they belong to a method with parameters that match the given 'parameters' objects
      Parameters:
      hint - the hint that has to be equal to the hint of the Listeners
      parameters - the parameters to give to the Listeners
    • sendForSingleOfClassWithHint

      <T> T sendForSingleOfClassWithHint(Class<T> returnType, String hint, Object... parameters)
      Send a request to all Listeners that satisfy the following requirements.
      • They return an Object that the parameter 'returnType' is assignable from and
      • they have a hint that is equals to the 'hint' parameter and
      • they belong to a method with parameters that match the given 'parameters' objects
      Parameters:
      returnType - the return type that has to be assignable from the return type of the Listeners
      hint - the hint that has to be equal to the hint of the Listeners
      parameters - the parameters to give to the Listeners
      Returns:
      a single return value from one of the listeners that executed (which one is unspecified) or 'null' if no matching Listeners were found
    • sendForMultipleOfClassWithHint

      <T> Collection<T> sendForMultipleOfClassWithHint(Class<T> returnType, String hint, Object... parameters)
      Send a request to all Listeners that satisfy the following requirements.
      • They return an Object that the parameter 'returnType' is assignable from and
      • they have a hint that is equals to the 'hint' parameter and
      • they belong to a method with parameters that match the given 'parameters' objects
      The number of Listeners that are executed may be larger than the number of return values that is returned, because some Listeners may return nothing (void).
      Parameters:
      returnType - the return type that has to be assignable from the return type of the Listeners
      hint - the hint that has to be equal to the hint of the Listeners
      parameters - the parameters to give to the Listeners
      Returns:
      all return values from the listeners that executed or an empty Collection if no matching Listeners were found. This method never returns null.
    • send

      <T> T send(String hint, Object... parameters)
      Equivalent to sendForSingleWithHint(String, Object...), since that is probably the most widely used method, because generally, when you know the hint, you know the returntype and you don't have to pass it specifically.

      This method is just a convenience shorthand method with a shorter name.

      Parameters:
      hint -
      parameters -
      Returns:
      same as sendForSingleWithHint