Class CompositeStateful<T,IN,OUT>
- All Implemented Interfaces:
Stateful<OUT>
Every change to the composite state is serialized by this object's monitor, whether it is caused by registering or deregistering an element, or by an element changing state.
Elements usually notify the composite while holding their own SingleStateful monitor,
so the lock order is: element, then composite, then the composite's own state.
Code holding this composite's monitor must therefore never wait for an element's monitor.
An element's state change may instead be delivered by the thread registering that element (see
SingleStateful). That thread already holds this composite's monitor, and does not hold the
element's monitor, so this does not violate the lock order.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()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.voidderegister(T identifier) Deregisters a stateful element from the composite.voidRegisters a stateful element with the composite.state()Returns the current state of the stateful component.reactor.core.publisher.Flux<OUT> 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.If an element is already registered with the same identifier, it is replaced. Does nothing if the composite is closed.
The element is deregistered automatically when its state stream terminates.
- 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.Transitions to the initial state (if not already in it), then completes the
states()stream. Subsequent calls toregister(T, com.couchbase.client.core.util.Stateful<IN>)andderegister(T)have no effect. -
state
Description copied from interface:StatefulReturns the current state of the stateful component. -
states
Description copied from interface:StatefulReturns a stream of states for this component as they change.Subscribers may be notified synchronously while the component holds internal locks, so they must not block or do non-trivial work on the notifying thread. See
SingleStatefulfor details.
-