System wide materializer (#27491)

Introduces a materializer started through an extension and then an implicit
conversion for Scala turning an implicitly available ActorSystem into a
materializer. The Java APIs has been ammended with run-methods accepting
an ActorSystem.
This commit is contained in:
Johan Andrén 2019-08-23 18:19:27 +02:00 committed by GitHub
parent 77d1d33dbc
commit 45c826a218
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
196 changed files with 1148 additions and 1129 deletions

View file

@ -148,8 +148,6 @@ object BidiFlowDocSpec {
class BidiFlowDocSpec extends AkkaSpec {
import BidiFlowDocSpec._
implicit val materializer = ActorMaterializer()
"A BidiFlow" must {
"compose" in {

View file

@ -16,7 +16,6 @@ import scala.concurrent.{ Future, Promise }
class CompositionDocSpec extends AkkaSpec {
implicit val ec = system.dispatcher
implicit val materializer = ActorMaterializer()
"nonnested flow" in {
//#non-nested-flow

View file

@ -4,9 +4,11 @@
package docs.stream
import akka.{ Done, NotUsed }
import akka.NotUsed
import akka.actor.{ Actor, ActorSystem, Cancellable }
import akka.stream.{ ActorMaterializer, ClosedShape, FlowShape, Materializer, OverflowStrategy }
import akka.stream.ActorMaterializer
import akka.stream.Materializer
import akka.stream.{ ClosedShape, FlowShape, OverflowStrategy }
import akka.stream.scaladsl._
import akka.testkit.AkkaSpec
import docs.CompileOnlySpec
@ -18,12 +20,6 @@ class FlowDocSpec extends AkkaSpec with CompileOnlySpec {
implicit val ec = system.dispatcher
//#imports
import akka.stream.ActorMaterializer
//#imports
implicit val materializer = ActorMaterializer()
"source is immutable" in {
//#source-immutable
val source = Source(1 to 10)
@ -247,14 +243,6 @@ class FlowDocSpec extends AkkaSpec with CompileOnlySpec {
object FlowDocSpec {
{
//#materializer-from-system
implicit val system = ActorSystem("ExampleSystem")
implicit val mat = ActorMaterializer() // created from `system`
//#materializer-from-system
}
//#materializer-from-actor-context
final class RunWithMyself extends Actor {
implicit val mat = ActorMaterializer()

View file

@ -18,7 +18,6 @@ class FlowErrorDocSpec extends AkkaSpec {
"demonstrate fail stream" in {
//#stop
implicit val materializer = ActorMaterializer()
val source = Source(0 to 5).map(100 / _)
val result = source.runWith(Sink.fold(0)(_ + _))
// division by zero will fail the stream and the
@ -48,7 +47,6 @@ class FlowErrorDocSpec extends AkkaSpec {
"demonstrate resume section" in {
//#resume-section
implicit val materializer = ActorMaterializer()
val decider: Supervision.Decider = {
case _: ArithmeticException => Supervision.Resume
case _ => Supervision.Stop
@ -69,7 +67,6 @@ class FlowErrorDocSpec extends AkkaSpec {
"demonstrate restart section" in {
//#restart-section
implicit val materializer = ActorMaterializer()
val decider: Supervision.Decider = {
case _: IllegalArgumentException => Supervision.Restart
case _ => Supervision.Stop
@ -91,7 +88,6 @@ class FlowErrorDocSpec extends AkkaSpec {
}
"demonstrate recover" in {
implicit val materializer = ActorMaterializer()
//#recover
Source(0 to 6)
.map(n =>
@ -117,7 +113,6 @@ stream truncated
}
"demonstrate recoverWithRetries" in {
implicit val materializer = ActorMaterializer()
//#recoverWithRetries
val planB = Source(List("five", "six", "seven", "eight"))

View file

@ -10,7 +10,6 @@ import akka.stream.ActorMaterializer
import akka.stream.scaladsl._
import akka.testkit.AkkaSpec
import docs.CompileOnlySpec
import scala.concurrent.Future
class FlowStreamRefsDocSpec extends AkkaSpec with CompileOnlySpec {
@ -91,7 +90,6 @@ class FlowStreamRefsDocSpec extends AkkaSpec with CompileOnlySpec {
//#offer-sink
implicit val mat = ActorMaterializer()
def localMetrics(): Source[String, NotUsed] = Source.single("")
//#offer-sink-use
@ -106,8 +104,6 @@ class FlowStreamRefsDocSpec extends AkkaSpec with CompileOnlySpec {
}
"show how to configure timeouts with attrs" in compileOnlySpec {
implicit val mat: ActorMaterializer = null
//#attr-sub-timeout
// configure the timeout for source
import scala.concurrent.duration._

View file

@ -10,8 +10,6 @@ import akka.testkit.AkkaSpec
class GraphCyclesSpec extends AkkaSpec {
implicit val materializer = ActorMaterializer()
"Cycle demonstration" must {
val source = Source.fromIterator(() => Iterator.from(0))

View file

@ -17,8 +17,6 @@ class GraphDSLDocSpec extends AkkaSpec {
implicit val ec = system.dispatcher
implicit val materializer = ActorMaterializer()
"build simple graph" in {
//format: OFF
//#simple-graph-dsl

View file

@ -18,8 +18,6 @@ import scala.collection.immutable.Iterable
class GraphStageDocSpec extends AkkaSpec {
implicit val materializer = ActorMaterializer()
"Demonstrate creation of GraphStage boilerplate" in {
//#boilerplate-example
import akka.stream.SourceShape

View file

@ -12,7 +12,6 @@ import akka.testkit.{ AkkaSpec, EventFilter }
class GraphStageLoggingDocSpec extends AkkaSpec("akka.loglevel = DEBUG") {
implicit val materializer = ActorMaterializer()
implicit val ec = system.dispatcher
//#operator-with-logging

View file

@ -5,7 +5,7 @@
package docs.stream
import akka.NotUsed
import akka.stream.{ ActorMaterializer, KillSwitches, UniqueKillSwitch }
import akka.stream.{ KillSwitches, UniqueKillSwitch }
import akka.stream.scaladsl._
import akka.testkit.AkkaSpec
import docs.CompileOnlySpec
@ -14,7 +14,6 @@ import scala.concurrent.duration._
import akka.stream.ThrottleMode
class HubsDocSpec extends AkkaSpec with CompileOnlySpec {
implicit val materializer = ActorMaterializer()
"Hubs" must {

View file

@ -13,7 +13,7 @@ import akka.stream._
import scala.concurrent.Future
import akka.testkit.TestProbe
import akka.actor.{ Actor, ActorLogging, ActorRef, Props, Status }
import akka.actor.{ Actor, ActorLogging, ActorRef, Props }
import com.typesafe.config.ConfigFactory
import akka.util.Timeout
@ -21,9 +21,6 @@ import scala.concurrent.ExecutionContext
import java.util.concurrent.atomic.AtomicInteger
import akka.stream.scaladsl.Flow
import akka.Done
import akka.actor.Status.Status
import akka.stream.QueueOfferResult.{ Dropped, Enqueued }
object IntegrationDocSpec {
import TwitterStreamQuickstartDocSpec._
@ -137,7 +134,6 @@ class IntegrationDocSpec extends AkkaSpec(IntegrationDocSpec.config) {
import TwitterStreamQuickstartDocSpec._
import IntegrationDocSpec._
implicit val materializer = ActorMaterializer()
val ref: ActorRef = system.actorOf(Props[Translator])
"ask" in {

View file

@ -5,7 +5,7 @@
package docs.stream
import akka.stream.scaladsl._
import akka.stream.{ ActorMaterializer, DelayOverflowStrategy, KillSwitches }
import akka.stream.{ DelayOverflowStrategy, KillSwitches }
import akka.testkit.AkkaSpec
import docs.CompileOnlySpec
@ -14,8 +14,6 @@ import scala.concurrent.duration._
class KillSwitchDocSpec extends AkkaSpec with CompileOnlySpec {
implicit val materializer = ActorMaterializer()
"Unique kill switch" must {
"control graph completion with shutdown" in compileOnlySpec {

View file

@ -23,6 +23,7 @@ import org.scalatest.concurrent._
//#main-app
object Main extends App {
implicit val system = ActorSystem("QuickStart")
// Code here
}
//#main-app
@ -33,17 +34,14 @@ class QuickStartDocSpec extends WordSpec with BeforeAndAfterAll with ScalaFuture
def println(any: Any) = () // silence printing stuff
"demonstrate Source" in {
//#create-materializer
implicit val system = ActorSystem("QuickStart")
implicit val materializer = ActorMaterializer()
//#create-materializer
//#create-source
val source: Source[Int, NotUsed] = Source(1 to 100)
//#create-source
//#run-source
source.runForeach(i => println(i))(materializer)
source.runForeach(i => println(i))
//#run-source
//#transform-source
@ -68,7 +66,7 @@ class QuickStartDocSpec extends WordSpec with BeforeAndAfterAll with ScalaFuture
//#add-streams
//#run-source-and-terminate
val done: Future[Done] = source.runForeach(i => println(i))(materializer)
val done: Future[Done] = source.runForeach(i => println(i))
implicit val ec = system.dispatcher
done.onComplete(_ => system.terminate())

View file

@ -4,7 +4,6 @@
package docs.stream
import akka.stream._
import akka.stream.scaladsl._
import akka.stream.testkit.scaladsl._
@ -18,8 +17,6 @@ import scala.concurrent.Await
class RateTransformationDocSpec extends AkkaSpec {
implicit val materializer = ActorMaterializer()
"conflate should summarize" in {
//#conflate-summarize
val statsFlow = Flow[Double].conflateWithSeed(immutable.Seq(_))(_ :+ _).map { s =>

View file

@ -5,7 +5,6 @@
package docs.stream
import akka.NotUsed
import akka.stream.ActorMaterializer
import akka.stream.scaladsl.{ Flow, Sink, Source }
import akka.stream.testkit._
import org.reactivestreams.Processor
@ -14,8 +13,6 @@ import akka.testkit.AkkaSpec
class ReactiveStreamsDocSpec extends AkkaSpec {
import TwitterStreamQuickstartDocSpec._
implicit val materializer = ActorMaterializer()
//#imports
import org.reactivestreams.Publisher
import org.reactivestreams.Subscriber

View file

@ -5,7 +5,7 @@
package docs.stream
import akka.NotUsed
import akka.stream.{ ActorMaterializer, KillSwitches }
import akka.stream.KillSwitches
import akka.stream.scaladsl._
import akka.testkit.AkkaSpec
import docs.CompileOnlySpec
@ -14,7 +14,6 @@ import scala.concurrent.duration._
import scala.concurrent._
class RestartDocSpec extends AkkaSpec with CompileOnlySpec {
implicit val materializer = ActorMaterializer()
import system.dispatcher
// Mock akka-http interfaces

View file

@ -10,7 +10,6 @@ import akka.stream.scaladsl._
import akka.testkit.AkkaSpec
class StreamBuffersRateSpec extends AkkaSpec {
implicit val materializer = ActorMaterializer()
"Demonstrate pipelining" in {
def println(s: Any) = ()

View file

@ -16,8 +16,6 @@ class StreamPartialGraphDSLDocSpec extends AkkaSpec {
implicit val ec = system.dispatcher
implicit val materializer = ActorMaterializer()
"build with open ports" in {
//#simple-partial-graph-dsl
val pickMaxOfThree = GraphDSL.create() { implicit b =>

View file

@ -6,7 +6,6 @@ package docs.stream
import akka.stream._
import akka.stream.scaladsl._
import akka.stream.testkit._
import akka.stream.testkit.scaladsl._
import scala.util._
import scala.concurrent.duration._
@ -16,8 +15,6 @@ import akka.pattern
class StreamTestKitDocSpec extends AkkaSpec {
implicit val materializer = ActorMaterializer()
"strict collection" in {
//#strict-collection
val sinkUnderTest = Flow[Int].map(_ * 2).toMat(Sink.fold(0)(_ + _))(Keep.right)

View file

@ -5,11 +5,10 @@
package docs.stream
import akka.stream.scaladsl.{ Sink, Source }
import akka.stream.{ ActorMaterializer, SubstreamCancelStrategy }
import akka.stream.{ SubstreamCancelStrategy }
import akka.testkit.AkkaSpec
class SubstreamDocSpec extends AkkaSpec {
implicit val materializer = ActorMaterializer()
"generate substreams by groupBy" in {
//#groupBy1

View file

@ -8,7 +8,7 @@ package docs.stream
import akka.{ Done, NotUsed }
import akka.actor.ActorSystem
import akka.stream.{ ActorMaterializer, ClosedShape, OverflowStrategy }
import akka.stream.{ ClosedShape, OverflowStrategy }
import akka.stream.scaladsl._
import scala.concurrent.Await
import scala.concurrent.Future
@ -79,17 +79,14 @@ class TwitterStreamQuickstartDocSpec extends AkkaSpec {
trait Example1 {
//#fiddle_code
//#first-sample
//#materializer-setup
//#system-setup
implicit val system = ActorSystem("reactive-tweets")
implicit val materializer = ActorMaterializer()
//#materializer-setup
//#system-setup
//#first-sample
//#fiddle_code
}
implicit val materializer = ActorMaterializer()
"filter and map" in {
//#first-sample

View file

@ -4,12 +4,10 @@
package docs.stream.cookbook
import akka.stream.ActorMaterializer
import akka.testkit.AkkaSpec
trait RecipeSpec extends AkkaSpec {
implicit val m = ActorMaterializer()
type Message = String
}

View file

@ -17,7 +17,6 @@ import scala.concurrent.Future
class StreamFileDocSpec extends AkkaSpec(UnboundedMailboxConfig) {
implicit val ec = system.dispatcher
implicit val materializer = ActorMaterializer()
// silence sysout
def println(s: String) = ()

View file

@ -6,7 +6,6 @@ package docs.stream.io
import java.util.concurrent.atomic.AtomicReference
import akka.stream._
import akka.stream.scaladsl.Tcp._
import akka.stream.scaladsl._
import akka.testkit.AkkaSpec
@ -19,7 +18,6 @@ import akka.testkit.SocketUtil
class StreamTcpDocSpec extends AkkaSpec {
implicit val ec = system.dispatcher
implicit val materializer = ActorMaterializer()
// silence sysout
def println(s: String) = ()

View file

@ -5,7 +5,6 @@
package docs.stream.operators
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import akka.testkit.TestProbe
object SourceOperators {
@ -21,7 +20,6 @@ object SourceOperators {
import scala.concurrent.Future
implicit val system: ActorSystem = ActorSystem()
implicit val materializer: ActorMaterializer = ActorMaterializer()
val source: Source[Int, NotUsed] = Source.fromFuture(Future.successful(10))
val sink: Sink[Int, Future[Done]] = Sink.foreach((i: Int) => println(i))
@ -40,7 +38,6 @@ object SourceOperators {
import akka.stream.scaladsl._
implicit val system: ActorSystem = ActorSystem()
implicit val materializer: ActorMaterializer = ActorMaterializer()
val bufferSize = 100
val source: Source[Any, ActorRef] = Source.actorRef[Any](bufferSize, OverflowStrategy.dropHead)
@ -63,7 +60,6 @@ object SourceOperators {
import akka.stream.scaladsl._
implicit val system: ActorSystem = ActorSystem()
implicit val materializer: ActorMaterializer = ActorMaterializer()
val probe = TestProbe()
val source: Source[Any, ActorRef] = Source.actorRefWithAck[Any]("ack")

View file

@ -11,7 +11,6 @@ object Scan {
import akka.stream.ActorMaterializer
implicit val system: ActorSystem = ActorSystem()
implicit val materializer: ActorMaterializer = ActorMaterializer()
//#scan
val source = Source(1 to 5)