Created
October 9, 2015 19:46
-
-
Save lwoodson/b43cfeb8ff6a6f4b44a4 to your computer and use it in GitHub Desktop.
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 java.util.ArrayList; | |
| import java.util.List; | |
| import java.util.function.Consumer; | |
| public class Test { | |
| private List<Consumer<Object>> callbacks; | |
| public Test() { | |
| callbacks = new ArrayList<Consumer<Object>>(); | |
| } | |
| public void register(Consumer<Object> callback) { | |
| callbacks.add(callback); | |
| } | |
| public void doSomething() { | |
| callbacks.forEach(callback -> { | |
| callback.accept("Here is your event notification"); | |
| }); | |
| } | |
| public static void main(String[] args) { | |
| Test test = new Test(); | |
| test.register(event -> { | |
| System.out.println("Sending to datadog " + event); | |
| }); | |
| test.register(event -> { | |
| System.out.println("Sending SNS: " + event); | |
| }); | |
| test.doSomething(); | |
| test.doSomething(); | |
| test.doSomething(); | |
| test.doSomething(); | |
| test.doSomething(); | |
| test.doSomething(); | |
| test.doSomething(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment