Package com.couchbase.client.core.util
Class CompositeStateful<T,IN,OUT>
java.lang.Object
com.couchbase.client.core.util.CompositeStateful<T,IN,OUT>
- All Implemented Interfaces:
Stateful<OUT>
Represents a stateful component of one or more individual stateful elements.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes the composite permanently and deregisters all elements.static <T,
IN, OUT>
CompositeStateful<T, IN, OUT> create
(OUT initialState, Function<Collection<IN>, OUT> transformer) Creates a new transformer with an initial state and the transform function that should be applied.static <T,
IN, OUT>
CompositeStateful<T, IN, OUT> create
(OUT initialState, Function<Collection<IN>, OUT> transformer, BiConsumer<OUT, OUT> beforeTransitionCallback) Creates a new transformer with an initial state and the transform function that should be applied.void
deregister
(T identifier) Deregisters a stateful element from the composite.void
Registers a stateful element with the composite.state()
Returns the current state of the stateful component.states()
Returns a stream of states for this component as they change.
-
Method Details
-
create
public static <T,IN, CompositeStateful<T,OUT> IN, createOUT> (OUT initialState, Function<Collection<IN>, OUT> transformer, BiConsumer<OUT, OUT> beforeTransitionCallback) Creates a new transformer with an initial state and the transform function that should be applied.- Parameters:
initialState
- the initial state.transformer
- the custom transformer for the states.- Returns:
- a created stateful composite.
-
create
public static <T,IN, CompositeStateful<T,OUT> IN, createOUT> (OUT initialState, Function<Collection<IN>, OUT> transformer) Creates a new transformer with an initial state and the transform function that should be applied.- Parameters:
initialState
- the initial state.transformer
- the custom transformer for the states.- Returns:
- a created stateful composite.
-
register
Registers a stateful element with the composite.- Parameters:
identifier
- the unique identifier to use.upstream
- the upstream flux with the state stream.
-
deregister
Deregisters a stateful element from the composite.Note that it might be possible that the passed in identifier is already deregistered (for example if the upstream flux already completed or failed). In this case, this is essentially a "noop" since the target state, the identifier not being part of the stateful component, is already reached.
- Parameters:
identifier
- the unique identifier to use.
-
close
public void close()Closes the composite permanently and deregisters all elements. -
state
Description copied from interface:Stateful
Returns the current state of the stateful component. -
states
Description copied from interface:Stateful
Returns a stream of states for this component as they change.
-