/** * Change to a new state and notify all listeners. * This method will block until all notifications have been issued. * It caches the list of listeners before the notification begins, * so additions or removal of listeners will not be visible. * @param service the service that has changed state */ public void notifyListeners(Service service) { //take a very fast snapshot of the callback list //very much like CopyOnWriteArrayList, only more minimal ServiceStateChangeListener[] callbacks; synchronized (this) { callbacks = listeners.toArray(new ServiceStateChangeListener[listeners.size()]); } //iterate through the listeners outside the synchronized method, //ensuring that listener registration/unregistration doesn't break anything for (ServiceStateChangeListener l : callbacks) { l.stateChanged(service); } } }
/** * Change to a new state and notify all listeners. * This method will block until all notifications have been issued. * It caches the list of listeners before the notification begins, * so additions or removal of listeners will not be visible. * @param service the service that has changed state */ public void notifyListeners(Service service) { //take a very fast snapshot of the callback list //very much like CopyOnWriteArrayList, only more minimal ServiceStateChangeListener[] callbacks; synchronized (this) { callbacks = listeners.toArray(new ServiceStateChangeListener[listeners.size()]); } //iterate through the listeners outside the synchronized method, //ensuring that listener registration/unregistration doesn't break anything for (ServiceStateChangeListener l : callbacks) { l.stateChanged(service); } } }
/** * Change to a new state and notify all listeners. * This method will block until all notifications have been issued. * It caches the list of listeners before the notification begins, * so additions or removal of listeners will not be visible. * @param service the service that has changed state */ public void notifyListeners(Service service) { //take a very fast snapshot of the callback list //very much like CopyOnWriteArrayList, only more minimal ServiceStateChangeListener[] callbacks; synchronized (this) { callbacks = listeners.toArray(new ServiceStateChangeListener[listeners.size()]); } //iterate through the listeners outside the synchronized method, //ensuring that listener registration/unregistration doesn't break anything for (ServiceStateChangeListener l : callbacks) { l.stateChanged(service); } } }
/** * Change to a new state and notify all listeners. * This method will block until all notifications have been issued. * It caches the list of listeners before the notification begins, * so additions or removal of listeners will not be visible. * @param service the service that has changed state */ public void notifyListeners(Service service) { //take a very fast snapshot of the callback list //very much like CopyOnWriteArrayList, only more minimal ServiceStateChangeListener[] callbacks; synchronized (this) { callbacks = listeners.toArray(new ServiceStateChangeListener[listeners.size()]); } //iterate through the listeners outside the synchronized method, //ensuring that listener registration/unregistration doesn't break anything for (ServiceStateChangeListener l : callbacks) { l.stateChanged(service); } } }
/** * Change to a new state and notify all listeners. * This method will block until all notifications have been issued. * It caches the list of listeners before the notification begins, * so additions or removal of listeners will not be visible. * @param service the service that has changed state */ public void notifyListeners(Service service) { //take a very fast snapshot of the callback list //very much like CopyOnWriteArrayList, only more minimal ServiceStateChangeListener[] callbacks; synchronized (this) { callbacks = listeners.toArray(new ServiceStateChangeListener[listeners.size()]); } //iterate through the listeners outside the synchronized method, //ensuring that listener registration/unregistration doesn't break anything for (ServiceStateChangeListener l : callbacks) { l.stateChanged(service); } } }