View Javadoc

1   package com.atlassian.event.internal;
2   
3   import com.atlassian.event.api.AsynchronousPreferred;
4   
5   import static com.google.common.base.Preconditions.checkNotNull;
6   
7   /**
8    * <p>Annotation based {@link AsynchronousEventResolver}. This will check whether the event is annotated with the given
9    * annotation.</p>
10   * <p>The default annotation used is {@link com.atlassian.event.api.AsynchronousPreferred}</p>
11   *
12   * @see com.atlassian.event.api.AsynchronousPreferred
13   * @since 2.0
14   */
15  public final class AnnotationAsynchronousEventResolver implements AsynchronousEventResolver {
16      private final Class annotationClass;
17  
18      AnnotationAsynchronousEventResolver() {
19          this(AsynchronousPreferred.class);
20      }
21  
22      AnnotationAsynchronousEventResolver(Class annotationClass) {
23          this.annotationClass = checkNotNull(annotationClass);
24      }
25  
26      @SuppressWarnings("unchecked")
27      public boolean isAsynchronousEvent(Object event) {
28          return checkNotNull(event).getClass().getAnnotation(annotationClass) != null;
29      }
30  }