Class Materializer
- java.lang.Object
-
- akka.stream.Materializer
-
- Direct Known Subclasses:
ActorMaterializer
public abstract class Materializer extends java.lang.ObjectThe Materializer is the component responsible for turning a stream blueprint into a running stream. In general the system wide materializer should be preferred over creating instances manually.Not for user extension
-
-
Constructor Summary
Constructors Constructor Description Materializer()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static Materializerapply(ClassicActorContextProvider contextProvider)Scala API: Create a materializer whose lifecycle will be tied to the one of the passed actor context.static Materializerapply(ClassicActorContextProvider contextProvider, Attributes defaultAttributes)Scala API: Create a materializer whose lifecycle will be tied to the one of the passed actor context.static Materializerapply(ClassicActorSystemProvider systemProvider)Scala API: Create a new materializer that will stay alive as long as the system does or until it is explicitly stopped.static Materializerapply(ClassicActorSystemProvider systemProvider, Attributes defaultAttributes)Scala API: Create a new materializer that will stay alive as long as the system does or until it is explicitly stopped.static MaterializercreateMaterializer(ClassicActorContextProvider contextProvider)Java API: Create a materializer whose lifecycle will be tied to the one of the passed actor context.static MaterializercreateMaterializer(ClassicActorContextProvider contextProvider, Attributes defaultAttributes)Java API: Create a materializer whose lifecycle will be tied to the one of the passed actor context.static MaterializercreateMaterializer(ClassicActorSystemProvider systemProvider)Java API: Create a new materializer that will stay alive as long as the system does or until it is explicitly stopped.static MaterializercreateMaterializer(ClassicActorSystemProvider systemProvider, Attributes defaultAttributes)Java API: Create a new materializer that will stay alive as long as the system does or until it is explicitly stopped.abstract scala.concurrent.ExecutionContextExecutorexecutionContext()Running a flow graph will require execution resources, as will computations within Sources, Sinks, etc.abstract booleanisShutdown()Indicates if the materializer has been shut down.abstract <Mat> Matmaterialize(Graph<ClosedShape,Mat> runnable)This method interprets the given Flow description and creates the running stream.abstract <Mat> Matmaterialize(Graph<ClosedShape,Mat> runnable, Attributes defaultAttributes)This method interprets the given Flow description and creates the running stream using an explicitly providedAttributesas top level (least specific) attributes that will be defaults for the materialized stream.static MaterializermatFromSystem(ClassicActorSystemProvider provider)Implicitly provides the system wide materializer from a classic or typedActorSystemabstract CancellablescheduleAtFixedRate(scala.concurrent.duration.FiniteDuration initialDelay, scala.concurrent.duration.FiniteDuration interval, java.lang.Runnable task)Interface for operators that need timer services for their functionality.abstract CancellablescheduleOnce(scala.concurrent.duration.FiniteDuration delay, java.lang.Runnable task)Interface for operators that need timer services for their functionality.abstract CancellableschedulePeriodically(scala.concurrent.duration.FiniteDuration initialDelay, scala.concurrent.duration.FiniteDuration interval, java.lang.Runnable task)Deprecated.Use scheduleWithFixedDelay or scheduleAtFixedRate instead.abstract CancellablescheduleWithFixedDelay(scala.concurrent.duration.FiniteDuration initialDelay, scala.concurrent.duration.FiniteDuration delay, java.lang.Runnable task)Interface for operators that need timer services for their functionality.abstract ActorMaterializerSettingssettings()Deprecated.Use attributes to access settings from stages.abstract voidshutdown()Shuts down this materializer and all the operators that have been materialized through this materializer.abstract ActorSystemsystem()The classic actor system this materializer is backed by (and in which the streams materialized with the materializer will run)abstract MaterializerwithNamePrefix(java.lang.String name)ThenamePrefixshall be used for deriving the names of processing entities that are created during materialization.
-
-
-
Method Detail
-
matFromSystem
public static Materializer matFromSystem(ClassicActorSystemProvider provider)
Implicitly provides the system wide materializer from a classic or typedActorSystem
-
apply
public static Materializer apply(ClassicActorContextProvider contextProvider)
Scala API: Create a materializer whose lifecycle will be tied to the one of the passed actor context. When the actor stops the materializer will stop and all streams created with it will be failed with anAbruptTerminationExeptionYou can pass either a classic actor context or a typed actor context.
-
createMaterializer
public static Materializer createMaterializer(ClassicActorContextProvider contextProvider)
Java API: Create a materializer whose lifecycle will be tied to the one of the passed actor context. When the actor stops the materializer will stop and all streams created with it will be failed with anAbruptTerminationExeptionYou can pass either a classic actor context or a typed actor context.
-
apply
public static Materializer apply(ClassicActorContextProvider contextProvider, Attributes defaultAttributes)
Scala API: Create a materializer whose lifecycle will be tied to the one of the passed actor context. When the actor stops the materializer will stop and all streams created with it will be failed with anAbruptTerminationExeptionYou can pass either a classic actor context or a typed actor context.
-
createMaterializer
public static Materializer createMaterializer(ClassicActorContextProvider contextProvider, Attributes defaultAttributes)
Java API: Create a materializer whose lifecycle will be tied to the one of the passed actor context. When the actor stops the materializer will stop and all streams created with it will be failed with anAbruptTerminationExeptionYou can pass either a classic actor context or a typed actor context.
-
apply
public static Materializer apply(ClassicActorSystemProvider systemProvider)
Scala API: Create a new materializer that will stay alive as long as the system does or until it is explicitly stopped.*Note* prefer using the default
SystemMaterializerthat is implicitly available if you have an implicitActorSystemin scope. Only create new system level materializers if you have specific needs or want to test abrupt termination of a custom graph stage. If you want to tie the lifecycle of the materializer to an actor, use the factory that takes anActorContextinstead.
-
createMaterializer
public static Materializer createMaterializer(ClassicActorSystemProvider systemProvider)
Java API: Create a new materializer that will stay alive as long as the system does or until it is explicitly stopped.*Note* prefer using the default
SystemMaterializerby passing theActorSystemto the variousrunmethods on the streams. Only create new system level materializers if you have specific needs or want to test abrupt termination of a custom graph stage. If you want to tie the lifecycle of the materializer to an actor, use the factory that takes anActorContextinstead.
-
apply
public static Materializer apply(ClassicActorSystemProvider systemProvider, Attributes defaultAttributes)
Scala API: Create a new materializer that will stay alive as long as the system does or until it is explicitly stopped.It is generally advised to limit the number of system level materializers created.
-
createMaterializer
public static Materializer createMaterializer(ClassicActorSystemProvider systemProvider, Attributes defaultAttributes)
Java API: Create a new materializer that will stay alive as long as the system does or until it is explicitly stopped.It is generally advised to limit the number of system level materializers created.
-
withNamePrefix
public abstract Materializer withNamePrefix(java.lang.String name)
ThenamePrefixshall be used for deriving the names of processing entities that are created during materialization. This is meant to aid logging and failure reporting both during materialization and while the stream is running.
-
materialize
public abstract <Mat> Mat materialize(Graph<ClosedShape,Mat> runnable)
This method interprets the given Flow description and creates the running stream. The result can be highly implementation specific, ranging from local actor chains to remote-deployed processing networks.
-
materialize
public abstract <Mat> Mat materialize(Graph<ClosedShape,Mat> runnable, Attributes defaultAttributes)
This method interprets the given Flow description and creates the running stream using an explicitly providedAttributesas top level (least specific) attributes that will be defaults for the materialized stream. The result can be highly implementation specific, ranging from local actor chains to remote-deployed processing networks.
-
executionContext
public abstract scala.concurrent.ExecutionContextExecutor executionContext()
Running a flow graph will require execution resources, as will computations within Sources, Sinks, etc. ThisExecutionContextExecutorcan be used by parts of the flow to submit processing jobs for execution, run Future callbacks, etc.Note that this is not necessarily the same execution context the stream operator itself is running on.
-
scheduleOnce
public abstract Cancellable scheduleOnce(scala.concurrent.duration.FiniteDuration delay, java.lang.Runnable task)
Interface for operators that need timer services for their functionality. Schedules a single task with the given delay.- Returns:
- A
Cancellablethat allows cancelling the timer. Cancelling is best effort, if the event has been already enqueued it will not have an effect.
-
scheduleWithFixedDelay
public abstract Cancellable scheduleWithFixedDelay(scala.concurrent.duration.FiniteDuration initialDelay, scala.concurrent.duration.FiniteDuration delay, java.lang.Runnable task)
Interface for operators that need timer services for their functionality.Schedules a
Runnableto be run repeatedly with an initial delay and a fixeddelaybetween subsequent executions.It will not compensate the delay between tasks if the execution takes a long time or if scheduling is delayed longer than specified for some reason. The delay between subsequent execution will always be (at least) the given
delay. In the long run, the frequency of execution will generally be slightly lower than the reciprocal of the specifieddelay.If the
Runnablethrows an exception the repeated scheduling is aborted, i.e. the function will not be invoked any more.- Returns:
- A
Cancellablethat allows cancelling the timer. Cancelling is best effort, if the event has been already enqueued it will not have an effect. - Throws:
java.lang.IllegalArgumentException- if the given delays exceed the maximum supported by theScheduler.
-
scheduleAtFixedRate
public abstract Cancellable scheduleAtFixedRate(scala.concurrent.duration.FiniteDuration initialDelay, scala.concurrent.duration.FiniteDuration interval, java.lang.Runnable task)
Interface for operators that need timer services for their functionality.Schedules a
Runnableto be run repeatedly with an initial delay and a frequency. E.g. if you would like the function to be run after 2 seconds and thereafter every 100ms you would setdelay=Duration(2, TimeUnit.SECONDS)andinterval=Duration(100, TimeUnit.MILLISECONDS).It will compensate the delay for a subsequent task if the previous tasks took too long to execute. In such cases, the actual execution interval will differ from the interval passed to the method.
If the execution of the tasks takes longer than the
interval, the subsequent execution will start immediately after the prior one completes (there will be no overlap of executions). This also has the consequence that after long garbage collection pauses or other reasons when the JVM was suspended all "missed" tasks will execute when the process wakes up again.In the long run, the frequency of execution will be exactly the reciprocal of the specified
interval.Warning:
scheduleAtFixedRatecan result in bursts of scheduled tasks after long garbage collection pauses, which may in worst case cause undesired load on the system. ThereforescheduleWithFixedDelayis often preferred.If the
Runnablethrows an exception the repeated scheduling is aborted, i.e. the function will not be invoked any more.- Returns:
- A
Cancellablethat allows cancelling the timer. Cancelling is best effort, if the event has been already enqueued it will not have an effect. - Throws:
java.lang.IllegalArgumentException- if the given delays exceed the maximum supported by theScheduler.
-
schedulePeriodically
public abstract Cancellable schedulePeriodically(scala.concurrent.duration.FiniteDuration initialDelay, scala.concurrent.duration.FiniteDuration interval, java.lang.Runnable task)
Deprecated.Use scheduleWithFixedDelay or scheduleAtFixedRate instead. This has the same semantics as scheduleAtFixedRate, but scheduleWithFixedDelay is often preferred. Since 2.6.0.Interface for operators that need timer services for their functionality. Schedules a repeated task with the given interval between invocations.- Returns:
- A
Cancellablethat allows cancelling the timer. Cancelling is best effort, if the event has been already enqueued it will not have an effect.
-
shutdown
public abstract void shutdown()
Shuts down this materializer and all the operators that have been materialized through this materializer. After having shut down, this materializer cannot be used again. Any attempt to materialize operators after having shut down will result in an IllegalStateException being thrown at materialization time.
-
isShutdown
public abstract boolean isShutdown()
Indicates if the materializer has been shut down.
-
system
public abstract ActorSystem system()
The classic actor system this materializer is backed by (and in which the streams materialized with the materializer will run)
-
settings
public abstract ActorMaterializerSettings settings()
Deprecated.Use attributes to access settings from stages. Since 2.6.0.
-
-