Created
October 31, 2011 05:22
-
-
Save notyy/1326956 to your computer and use it in GitHub Desktop.
is this efficent?
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
| class Dispatcher { | |
| private List data = new ArrayList(); | |
| private List listeners = new ArrayList(); | |
| public synchronized onNewData(byte[] newData){ | |
| updateData() | |
| notifyListeners(newData) | |
| } | |
| public synchronized register(Listener l) { | |
| //send all current data to l | |
| l.sendAll(data); | |
| listeners.add(l); | |
| } | |
| private notifyListeners(byte[] newData) { | |
| for(l:listeners){ | |
| l.sendData(newData) | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment