Skip to content

Instantly share code, notes, and snippets.

@Bombe
Last active December 16, 2015 13:03
Show Gist options
  • Save Bombe/c3ef716ec835a9b8e717 to your computer and use it in GitHub Desktop.
Save Bombe/c3ef716ec835a9b8e717 to your computer and use it in GitHub Desktop.
package de.xplosion.adp.servlet.filter;
import javax.inject.Inject;
import javax.inject.Singleton;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
public class EventBusTest {
private final EventBus eventBus;
@Inject
public EventBusTest(EventBus eventBus) {
this.eventBus = eventBus;
eventBus.register(this);
}
@Subscribe
public void handle(Event event) {
System.out.println("got event");
}
public static void main(String[] args) {
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(EventBus.class).in(Singleton.class);
}
});
injector.getInstance(EventBusTest.class);
OtherClass.fireEvent(injector.getInstance(EventBus.class));
}
}
class Event {
}
class OtherClass {
public static void fireEvent(EventBus eventBus) {
eventBus.post(new Event());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment