Code example for EventBus

Methods: register

0
  public void setup() throws Exception {
    injector = Guice.createInjector(new InMemoryDefaultTestModule());
    injector.getInstance(GuiceJpaInitializer.class);
 
    eventPublisher = injector.getInstance(AmbariEventPublisher.class);
    EventBus synchronizedBus = new EventBus();
 
    // force singleton init via Guice so the listener registers with the bus 
    synchronizedBus.register(injector.getInstance(AlertLifecycleListener.class));
    synchronizedBus.register(injector.getInstance(AlertStateChangedListener.class));
    synchronizedBus.register(injector.getInstance(AlertServiceStateListener.class));
 
    // !!! need a synchronous op for testing 
    Field field = AmbariEventPublisher.class.getDeclaredField("m_eventBus");
    field.setAccessible(true);
    field.set(eventPublisher, synchronizedBus);
 
    dispatchDao = injector.getInstance(AlertDispatchDAO.class);
    definitionDao = injector.getInstance(AlertDefinitionDAO.class);
    clusters = injector.getInstance(Clusters.class);