private void changeState ( Service . STATE newState ) { state = newState ; // notify listeners for ( ServiceStateChangeListener l : listeners ) { l . stateChanged ( this ) ; } }
Change to a new state and notify all listeners . This is a private method that is only invoked from synchronized methods which avoid having to clone the listener list . It does imply that the state change listener methods should be short lived as they will delay the state transition .