Package com.couchbase.client.core.state
Class AbstractStateZipper<T,S extends Enum>
- java.lang.Object
-
- com.couchbase.client.core.state.AbstractStateMachine<S>
-
- com.couchbase.client.core.state.AbstractStateZipper<T,S>
-
- All Implemented Interfaces:
Stateful<S>
,StateZipper<T,S>
- Direct Known Subclasses:
EndpointStateZipper
,ServiceStateZipper
public abstract class AbstractStateZipper<T,S extends Enum> extends AbstractStateMachine<S> implements StateZipper<T,S>
The default implementation of aStateZipper
. The implementing class only needs to provide the zip function, as well as a initial state that is always used when no source stream is registered.- Since:
- 1.1.0
- Author:
- Michael Nitschinger
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractStateZipper(S initialState)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected Map<T,S>
currentStates()
Helper method to export the current internal states.protected Map<T,rx.Subscription>
currentSubscriptions()
Helper method to export the current internal subscriptions.void
deregister(T identifier)
Deregisters a stream identified by the identifier from the state computation.void
register(T identifier, Stateful<S> upstream)
Register the given stream to be zipped into the state computation.void
terminate()
Terminate the zipper and deregister all registered streams.protected abstract S
zipWith(Collection<S> states)
The zip function to map from N states to one that represents the state of the zipper.-
Methods inherited from class com.couchbase.client.core.state.AbstractStateMachine
hasSubscribers, isState, state, states, transitionState
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.couchbase.client.core.state.Stateful
hasSubscribers, isState, state, states
-
-
-
-
Constructor Detail
-
AbstractStateZipper
protected AbstractStateZipper(S initialState)
-
-
Method Detail
-
zipWith
protected abstract S zipWith(Collection<S> states)
The zip function to map from N states to one that represents the state of the zipper.- Parameters:
states
- all subscribed states.- Returns:
- the zipped state which represents the zipper state.
-
register
public void register(T identifier, Stateful<S> upstream)
Description copied from interface:StateZipper
Register the given stream to be zipped into the state computation.- Specified by:
register
in interfaceStateZipper<T,S extends Enum>
- Parameters:
identifier
- the identifier used to uniquely identify the stream.upstream
- the stateful compontent to be registered.
-
deregister
public void deregister(T identifier)
Description copied from interface:StateZipper
Deregisters a stream identified by the identifier from the state computation.- Specified by:
deregister
in interfaceStateZipper<T,S extends Enum>
- Parameters:
identifier
- the identifier used to uniquely identify the stream.
-
terminate
public void terminate()
Description copied from interface:StateZipper
Terminate the zipper and deregister all registered streams.- Specified by:
terminate
in interfaceStateZipper<T,S extends Enum>
-
currentSubscriptions
protected Map<T,rx.Subscription> currentSubscriptions()
Helper method to export the current internal subscriptions.- Returns:
- the internally stored subscriptions.
-
-