Interface ViewStateManager
- All Known Implementing Classes:
ViewStateManagerImpl
public interface ViewStateManager
The ViewStateManager is at the core of managing TopologyEventListeners,
the 'view state' (changing vs changed) and sending out the appropriate
and according TopologyEvents to the registered listeners - depending
on the implementation it also supports the ClusterSyncService, which is
invoked on handleNewView.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
bind
(TopologyEventListener eventListener) Binds the given eventListener, sending it an INIT event if applicable.void
Handles activation - ie marks this manager as activated thus the TOPOLOGY_INIT event can be sent to already bound listeners and subsequent calls to handleChanging/handleNewView will result in according/appropriate TOPOLOGY_CHANGING/ TOPOLOGY_CHANGED events.void
Handles the fact that some (possibly early) indicator of a change in a topology has been detected and that a new view is being agreed upon (whatever that means, be it voting or similar).void
Must be called when the corresponding service (typically a DiscoveryService implementation) is deactivated.void
handleNewView
(BaseTopologyView newView) Handles the fact that a new view became true/established and sends out TOPOLOGY_INIT to uninitialized listeners and TOPOLOGY_CHANGED to already initialized listeners (in the latter case, also sends a TOPOLOGY_CHANGING if that has not yet been done)void
installMinEventDelayHandler
(DiscoveryService discoveryService, Scheduler scheduler, long minEventDelaySecs) Installs an optional 'min event delay handler' which, using the given scheduler, delays sending TOPOLOGY_CHANGED event after receiving a handleNewView - with the idea as to limit the number of toggling between view states.boolean
unbind
(TopologyEventListener eventListener) Unbinds the given eventListener, returning whether or not it was bound at all.int
waitForAsyncEvents
(long timeout) for testing only: wait for any potentially queued async events to be delivered before returning.
-
Method Details
-
installMinEventDelayHandler
void installMinEventDelayHandler(DiscoveryService discoveryService, Scheduler scheduler, long minEventDelaySecs) Installs an optional 'min event delay handler' which, using the given scheduler, delays sending TOPOLOGY_CHANGED event after receiving a handleNewView - with the idea as to limit the number of toggling between view states. -
bind
Binds the given eventListener, sending it an INIT event if applicable.- Parameters:
eventListener
- the eventListener that is to bind
-
unbind
Unbinds the given eventListener, returning whether or not it was bound at all.- Parameters:
eventListener
- the eventListner that is to unbind- Returns:
- whether or not the listener was added in the first place
-
handleActivated
void handleActivated()Handles activation - ie marks this manager as activated thus the TOPOLOGY_INIT event can be sent to already bound listeners and subsequent calls to handleChanging/handleNewView will result in according/appropriate TOPOLOGY_CHANGING/ TOPOLOGY_CHANGED events. -
handleDeactivated
void handleDeactivated()Must be called when the corresponding service (typically a DiscoveryService implementation) is deactivated.Will mark this manager as deactivated and flags the last available view as not current.
-
handleChanging
void handleChanging()Handles the fact that some (possibly early) indicator of a change in a topology has been detected and that a new view is being agreed upon (whatever that means, be it voting or similar).Will send out TOPOLOGY_CHANGING to all initialized listeners.
-
handleNewView
Handles the fact that a new view became true/established and sends out TOPOLOGY_INIT to uninitialized listeners and TOPOLOGY_CHANGED to already initialized listeners (in the latter case, also sends a TOPOLOGY_CHANGING if that has not yet been done)- Parameters:
newView
- the new, established view true if we were either in changing mode or the newView was different from the previous one.
-
waitForAsyncEvents
int waitForAsyncEvents(long timeout) for testing only: wait for any potentially queued async events to be delivered before returning.- Parameters:
timeout
- time in millis to wait for at max - 0 to not wait at all - -1 to wait indefinitely- Returns:
- 0 if no more async events exist, or the number of queued or in-flight (being sent) events if the timeout hit early
-