Last active
February 7, 2017 13:38
-
-
Save antic183/67b9cd43c817fa6cad3774c59f6f661f to your computer and use it in GitHub Desktop.
google guava eventbus example
This file contains hidden or 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
import com.google.common.eventbus.EventBus; | |
public class GoolgeGuavaEventBus | |
{ | |
public static void main(String[] args) { | |
EventBus eventBus = new EventBus(); | |
//register the receiver | |
Listener1 l1 = new Listener1(); | |
Listener2 l2 = new Listener2(); | |
eventBus.register(l1); | |
eventBus.register(l2); | |
// eventBus.unregister(l1); //unregister a receiver | |
eventBus.post("my message for Listener1 and Listener2!"); | |
} | |
} |
This file contains hidden or 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
import com.google.common.eventbus.Subscribe; | |
public class Listener1 | |
{ | |
// identify post by param-signature | |
@Subscribe | |
public void doAnything(String s) { | |
System.out.println("receipt message in Listener1: '" + s + "'"); | |
} | |
} |
This file contains hidden or 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
import com.google.common.eventbus.Subscribe; | |
public class Listener2 | |
{ | |
// identify post by param-signature | |
@Subscribe | |
public void doAlsoAnything(String s) { | |
System.out.println("receipt message in Listener2: '" + s + "'"); | |
} | |
} |
This file contains hidden or 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
<!-- add dependencies --> | |
<dependencies> | |
<dependency> | |
<groupId>com.google.guava</groupId> | |
<artifactId>guava</artifactId> | |
<version>19.0</version> | |
</dependency> | |
</dependencies> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment