View Javadoc
1   package com.atlassian.event.spi;
2   
3   import java.util.Optional;
4   import java.util.Set;
5   
6   /**
7    * <p>Implementation of this interface know how to invoke 'given types' of listeners so that they handle given events.</p>
8    * <p><strong>Note:</strong> Implementations <strong>MUST</strong> provide correct implementations of the
9    * {@link Object#equals(Object)} and {@link Object#hashCode()} method.</p>
10   *
11   * @since 2.0
12   */
13  public interface ListenerInvoker {
14      /**
15       * The types of events supported by this invoker. I.e. {@link #invoke(Object)} can be safely called with any object
16       * that is an instance of at least one of those types.
17       *
18       * @return the set of supported event types.
19       */
20      Set<Class<?>> getSupportedEventTypes();
21  
22      /**
23       * Invokes the underlying listener for the given event.
24       *
25       * @param event the event to tell the listener about.
26       * @throws IllegalArgumentException if the event is not an instance of any of the types returned by
27       *                                  {@link #getSupportedEventTypes()}
28       */
29      void invoke(Object event);
30  
31      /**
32       * Whether or not the underlying listener can handle asynchronous event.
33       *
34       * @return {@code true} if the underlying listener can handle asynchronous events, {@code false} otherwise
35       */
36      boolean supportAsynchronousEvents();
37  
38      default Optional<String> getScope()
39      {
40          return Optional.empty();
41      }
42  }