Class SharedKillSwitch
- java.lang.Object
-
- akka.stream.SharedKillSwitch
-
- All Implemented Interfaces:
KillSwitch
public final class SharedKillSwitch extends java.lang.Object implements KillSwitch
ASharedKillSwitch
is a provider forGraph
s ofFlowShape
that can be completed or failed from the outside. AGraph
returned by the switch can be materialized arbitrary amount of times: every newly materializedGraph
belongs to the switch from which it was acquired. MultipleSharedKillSwitch
instances are isolated from each other, shutting down or aborting on instance does not affect theGraph
s provided by another instance.After calling
shutdown()
all materialized, running instances of allGraph
s provided by theSharedKillSwitch
will complete their downstreams and cancel their upstreams (unless if finished or failed already in which case the command is ignored). Subsequent invocations ofshutdown()
andabort(java.lang.Throwable)
will be ignored.After calling
abort(java.lang.Throwable)
all materialized, running instances of allGraph
s provided by theSharedKillSwitch
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 ofshutdown()
andabort(java.lang.Throwable)
will be ignored.The
Graph
s provided by theSharedKillSwitch
do not modify the passed through elements in any way or affect backpressure in the stream. All providedGraph
s provide the parentSharedKillSwitch
as materialized value.This class is thread-safe, the instance can be passed safely among threads and its methods may be invoked concurrently.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
abort(java.lang.Throwable reason)
After callingabort(java.lang.Throwable)
all materialized, running instances of allGraph
s provided by theSharedKillSwitch
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 thisSharedKillSwitch
instance.java.lang.String
name()
void
shutdown()
After callingshutdown()
all materialized, running instances of allGraph
s provided by theSharedKillSwitch
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()
-
-
-
Method Detail
-
abort
public void abort(java.lang.Throwable reason)
After callingabort(java.lang.Throwable)
all materialized, running instances of allGraph
s provided by theSharedKillSwitch
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 ofshutdown()
andabort(java.lang.Throwable)
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.- Specified by:
abort
in interfaceKillSwitch
- Parameters:
reason
- The exception to be used for failing the linkedGraph
s
-
flow
public <T> Graph<FlowShape<T,T>,SharedKillSwitch> flow()
Returns a typed Flow of a requested type that will be linked to thisSharedKillSwitch
instance. By invokingshutdown()
orabort(java.lang.Throwable)
all running instances of all providedGraph
s by this switch will be stopped normally or failed.- Returns:
- A reusable
Graph
that is linked with the switch. The materialized value provided is this switch itself.
-
name
public java.lang.String name()
-
shutdown
public void shutdown()
After callingshutdown()
all materialized, running instances of allGraph
s provided by theSharedKillSwitch
will complete their downstreams and cancel their upstreams (unless if finished or failed already in which case the command is ignored). Subsequent invocations ofshutdown()
andabort(java.lang.Throwable)
will be ignored.- Specified by:
shutdown
in interfaceKillSwitch
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-