View Javadoc

1   package com.atlassian.johnson.event;
2   
3   import com.atlassian.event.api.EventListener;
4   import com.atlassian.johnson.Johnson;
5   
6   import javax.annotation.Nonnull;
7   import javax.servlet.ServletContext;
8   
9   /**
10   * A simple listener which may be used with the Atlassian Events framework to listen for {@link AddEvent add} and
11   * {@link RemoveEvent remove} events on the bus, allowing simplified interaction with Johnson.
12   *
13   * @since 2.0
14   */
15  public class JohnsonEventListener {
16  
17      private final ServletContext servletContext;
18  
19      public JohnsonEventListener(@Nonnull ServletContext servletContext) {
20          this.servletContext = servletContext;
21      }
22  
23      /**
24       * Adds the Johnson {@link Event} wrapped by the provided {@link AddEvent}  to the container.
25       *
26       * @param e the add event
27       */
28      @EventListener
29      public void onAdd(@Nonnull AddEvent e) {
30          Johnson.getEventContainer(servletContext).addEvent(e.getEvent());
31      }
32  
33      /**
34       * Attempts to remove the Johnson {@link Event} wrapped by the provided {@link RemoveEvent} from the container.
35       *
36       * @param e the remove event
37       */
38      @EventListener
39      public void onRemove(@Nonnull RemoveEvent e) {
40          Johnson.getEventContainer(servletContext).removeEvent(e.getEvent());
41      }
42  }