public final class SharedKillSwitch extends java.lang.Object implements KillSwitch
SharedKillSwitch
is a provider for Graph
s of FlowShape
that can be completed or failed from the outside.
A Graph
returned by the switch can be materialized arbitrary amount of times: every newly materialized Graph
belongs to the switch from which it was acquired. Multiple SharedKillSwitch
instances are isolated from each other,
shutting down or aborting on instance does not affect the Graph
s provided by another instance.
After calling shutdown()
all materialized, running instances of all Graph
s provided by the
SharedKillSwitch
will complete their downstreams and cancel their upstreams (unless if finished or failed already in which
case the command is ignored). Subsequent invocations of shutdown()
and SharedKillSwitch#abort()
will be
ignored.
After calling SharedKillSwitch#abort()
all materialized, running instances of all Graph
s provided by the
SharedKillSwitch
will fail their downstreams with the provided exception and cancel their upstreams
(unless it finished or failed already in which case the command is ignored). Subsequent invocations of
shutdown()
and SharedKillSwitch#abort()
will be ignored.
The Graph
s provided by the SharedKillSwitch
do not modify the passed through elements in any way or affect
backpressure in the stream. All provided Graph
s provide the parent SharedKillSwitch
as materialized value.
This class is thread-safe, the instance can be passed safely among threads and its methods may be invoked concurrently.
Constructor and Description |
---|
SharedKillSwitch(java.lang.String name) |
Modifier and Type | Method and Description |
---|---|
void |
abort(java.lang.Throwable reason)
After calling
SharedKillSwitch#abort() all materialized, running instances of all Graph s provided by the
SharedKillSwitch will fail their downstreams with the provided exception and cancel their upstreams
(unless it finished or failed already in which case the command is ignored). |
<T> Graph<FlowShape<T,T>,SharedKillSwitch> |
flow()
Returns a typed Flow of a requested type that will be linked to this
SharedKillSwitch instance. |
java.lang.String |
name() |
void |
shutdown()
After calling
shutdown() all materialized, running instances of all Graph s provided by the
SharedKillSwitch will complete their downstreams and cancel their upstreams (unless if finished or failed already in which
case the command is ignored). |
java.lang.String |
toString() |
public java.lang.String name()
public void shutdown()
shutdown()
all materialized, running instances of all Graph
s provided by the
SharedKillSwitch
will complete their downstreams and cancel their upstreams (unless if finished or failed already in which
case the command is ignored). Subsequent invocations of shutdown()
and SharedKillSwitch#abort()
will be
ignored.shutdown
in interface KillSwitch
public void abort(java.lang.Throwable reason)
SharedKillSwitch#abort()
all materialized, running instances of all Graph
s provided by the
SharedKillSwitch
will fail their downstreams with the provided exception and cancel their upstreams
(unless it finished or failed already in which case the command is ignored). Subsequent invocations of
shutdown()
and SharedKillSwitch#abort()
will be ignored.
These provided Graph
s materialize to their owning switch. This might make certain integrations simpler than
passing around the switch instance itself.
abort
in interface KillSwitch
reason
- The exception to be used for failing the linked Graph
spublic <T> Graph<FlowShape<T,T>,SharedKillSwitch> flow()
SharedKillSwitch
instance. By invoking
shutdown()
or SharedKillSwitch#abort()
all running instances of all provided Graph
s by this
switch will be stopped normally or failed.
Graph
that is linked with the switch. The materialized value provided is this switch itself.public java.lang.String toString()
toString
in class java.lang.Object