private synchronized boolean removeWrapperFromList ( EventListenerWrapper < K , V > wrapper , List < EventListenerWrapper < K , V > > listenersList ) { int index = listenersList . indexOf ( wrapper ) ; if ( index != - 1 ) { EventListenerWrapper < K , V > containedWrapper = listenersList . remove ( index ) ; if ( containedWrapper . isOrdered ( ) && -- orderedListenerCount == 0 ) { storeEventSource . setEventOrdering ( false ) ; } if ( -- listenersCount == 0 ) { storeEventSource . removeEventListener ( eventListener ) ; } return true ; } return false ; }
Synchronized to make sure listener removal is atomic