Last active
December 16, 2015 13:03
-
-
Save Bombe/c3ef716ec835a9b8e717 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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