Skip to content

Instantly share code, notes, and snippets.

@lwoodson
Created October 9, 2015 19:46
Show Gist options
  • Select an option

  • Save lwoodson/b43cfeb8ff6a6f4b44a4 to your computer and use it in GitHub Desktop.

Select an option

Save lwoodson/b43cfeb8ff6a6f4b44a4 to your computer and use it in GitHub Desktop.
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