From 52f24e517413f9b39d8335387731280f1968691c Mon Sep 17 00:00:00 2001 From: Patrik Nordwall Date: Mon, 21 May 2018 16:05:09 +0200 Subject: [PATCH] move Typed ActorMaterializer to scaladsl/javadsl, #24868 * add type alias for typed ActorMaterializer * name it ActorMaterializerFactory in javadsl Migration guide: Scala: import akka.stream.typed.ActorMaterializer -> akka.stream.typed.scaladsl.ActorMaterializer Java: import akka.stream.typed.ActorMaterializer -> akka.stream.typed.javadsl.ActorMaterializerFactory --- akka-docs/src/main/paradox/typed/stream.md | 3 +- .../ActorMaterializerFactory.scala} | 31 +++++-------------- .../scala/akka/stream/typed/package.scala | 9 ++++++ .../typed/scaladsl/ActorMaterializer.scala | 28 +++++++++++++++++ .../typed/javadsl/ActorFlowCompileTest.java | 2 +- .../javadsl/ActorSourceSinkCompileTest.java | 2 +- .../stream/typed/scaladsl/ActorFlowSpec.scala | 2 +- .../typed/scaladsl/ActorSourceSinkSpec.scala | 1 - .../CustomGuardianAndMaterializerSpec.scala | 1 - .../stream/typed/ActorSourceSinkExample.scala | 7 +++-- 10 files changed, 55 insertions(+), 31 deletions(-) rename akka-stream-typed/src/main/scala/akka/stream/typed/{ActorMaterializer.scala => javadsl/ActorMaterializerFactory.scala} (53%) create mode 100644 akka-stream-typed/src/main/scala/akka/stream/typed/package.scala create mode 100644 akka-stream-typed/src/main/scala/akka/stream/typed/scaladsl/ActorMaterializer.scala diff --git a/akka-docs/src/main/paradox/typed/stream.md b/akka-docs/src/main/paradox/typed/stream.md index 3824ce078c..0709160d6c 100644 --- a/akka-docs/src/main/paradox/typed/stream.md +++ b/akka-docs/src/main/paradox/typed/stream.md @@ -14,7 +14,8 @@ To use Akka Streams Typed, add the module to your project: @ref:[Akka Streams](../stream/index.md) make it easy to model type-safe message processing pipelines. With typed actors it is possible to connect streams to actors without loosing the type information. -This module contains typed alternatives to the @ref:[already existing `ActorRef` sources and sinks](../stream/stream-integrations.md) together with a factory methods for @scala[@scaladoc[`ActorMaterializer`](akka.stream.typed.ActorMaterializer)]@java[@javadoc[`ActorMaterializer`](akka.stream.typed.ActorMaterializer)] which takes a typed `ActorSystem`. +This module contains typed alternatives to the @ref:[already existing `ActorRef` sources and sinks](../stream/stream-integrations.md) together with a factory methods for +@scala[@scaladoc[`ActorMaterializer`](akka.stream.typed.scaladsl.ActorMaterializer)]@java[@javadoc[`ActorMaterializerFactory`](akka.stream.typed.javadsl.ActorMaterializerFactory)] which takes a typed `ActorSystem`. The materializer created from these factory methods and sources together with sinks contained in this module can be mixed and matched with the original Akka Streams building blocks from the original module. diff --git a/akka-stream-typed/src/main/scala/akka/stream/typed/ActorMaterializer.scala b/akka-stream-typed/src/main/scala/akka/stream/typed/javadsl/ActorMaterializerFactory.scala similarity index 53% rename from akka-stream-typed/src/main/scala/akka/stream/typed/ActorMaterializer.scala rename to akka-stream-typed/src/main/scala/akka/stream/typed/javadsl/ActorMaterializerFactory.scala index 2e676e0265..6c112dc25b 100644 --- a/akka-stream-typed/src/main/scala/akka/stream/typed/ActorMaterializer.scala +++ b/akka-stream-typed/src/main/scala/akka/stream/typed/javadsl/ActorMaterializerFactory.scala @@ -2,31 +2,16 @@ * Copyright (C) 2018 Lightbend Inc. */ -package akka.stream.typed +package akka.stream.typed.javadsl import akka.actor.typed.ActorSystem import akka.stream.ActorMaterializerSettings -object ActorMaterializer { +object ActorMaterializerFactory { import akka.actor.typed.scaladsl.adapter._ /** - * Scala API: Creates an ActorMaterializer which will execute every step of a transformation - * pipeline within its own [[akka.actor.Actor]]. The required [[akka.actor.typed.ActorSystem]] - * will be used to create one actor that in turn creates actors for the transformation steps. - * - * The materializer's [[akka.stream.ActorMaterializerSettings]] will be obtained from the - * configuration of the `context`'s underlying [[akka.actor.typed.ActorSystem]]. - * - * The `namePrefix` is used as the first part of the names of the actors running - * the processing steps. The default `namePrefix` is `"flow"`. The actor names are built up of - * `namePrefix-flowNumber-flowStepNumber-stepName`. - */ - def apply[T](materializerSettings: Option[ActorMaterializerSettings] = None, namePrefix: Option[String] = None)(implicit actorSystem: ActorSystem[T]): akka.stream.ActorMaterializer = - akka.stream.ActorMaterializer(materializerSettings, namePrefix)(actorSystem.toUntyped) - - /** - * Java API: Creates an ActorMaterializer which will execute every step of a transformation + * Creates an `ActorMaterializer` which will execute every step of a transformation * pipeline within its own [[akka.actor.Actor]]. The required [[akka.actor.typed.ActorSystem]] * will be used to create these actors, therefore it is *forbidden* to pass this object * to another actor if the factory is an ActorContext. @@ -35,18 +20,18 @@ object ActorMaterializer { * The actor names are built up of `namePrefix-flowNumber-flowStepNumber-stepName`. */ def create[T](actorSystem: ActorSystem[T]): akka.stream.ActorMaterializer = - apply()(actorSystem) + akka.stream.ActorMaterializer.create(actorSystem.toUntyped) /** - * Java API: Creates an ActorMaterializer which will execute every step of a transformation + * Creates an `ActorMaterializer` which will execute every step of a transformation * pipeline within its own [[akka.actor.Actor]]. The required [[akka.actor.typed.ActorSystem]] * will be used to create one actor that in turn creates actors for the transformation steps. */ def create[T](settings: ActorMaterializerSettings, actorSystem: ActorSystem[T]): akka.stream.ActorMaterializer = - apply(Option(settings), None)(actorSystem) + akka.stream.ActorMaterializer.create(settings, actorSystem.toUntyped) /** - * Java API: Creates an ActorMaterializer which will execute every step of a transformation + * Creates an `ActorMaterializer` which will execute every step of a transformation * pipeline within its own [[akka.actor.Actor]]. The required [[akka.actor.typed.ActorSystem]] * will be used to create these actors, therefore it is *forbidden* to pass this object * to another actor if the factory is an ActorContext. @@ -56,6 +41,6 @@ object ActorMaterializer { * `namePrefix-flowNumber-flowStepNumber-stepName`. */ def create[T](settings: ActorMaterializerSettings, namePrefix: String, actorSystem: ActorSystem[T]): akka.stream.ActorMaterializer = - apply(Option(settings), Option(namePrefix))(actorSystem) + akka.stream.ActorMaterializer.create(settings, actorSystem.toUntyped, namePrefix) } diff --git a/akka-stream-typed/src/main/scala/akka/stream/typed/package.scala b/akka-stream-typed/src/main/scala/akka/stream/typed/package.scala new file mode 100644 index 0000000000..8f530e1011 --- /dev/null +++ b/akka-stream-typed/src/main/scala/akka/stream/typed/package.scala @@ -0,0 +1,9 @@ +/** + * Copyright (C) 2018 Lightbend Inc. + */ + +package akka.stream.typed + +package object scaladsl { + type ActorMaterializer = akka.stream.ActorMaterializer +} diff --git a/akka-stream-typed/src/main/scala/akka/stream/typed/scaladsl/ActorMaterializer.scala b/akka-stream-typed/src/main/scala/akka/stream/typed/scaladsl/ActorMaterializer.scala new file mode 100644 index 0000000000..1b5fb6a42f --- /dev/null +++ b/akka-stream-typed/src/main/scala/akka/stream/typed/scaladsl/ActorMaterializer.scala @@ -0,0 +1,28 @@ +/** + * Copyright (C) 2018 Lightbend Inc. + */ + +package akka.stream.typed.scaladsl + +import akka.actor.typed.ActorSystem +import akka.stream.ActorMaterializerSettings + +object ActorMaterializer { + import akka.actor.typed.scaladsl.adapter._ + + /** + * Creates an `ActorMaterializer` which will execute every step of a transformation + * pipeline within its own [[akka.actor.Actor]]. The required [[akka.actor.typed.ActorSystem]] + * will be used to create one actor that in turn creates actors for the transformation steps. + * + * The materializer's [[akka.stream.ActorMaterializerSettings]] will be obtained from the + * configuration of the `context`'s underlying [[akka.actor.typed.ActorSystem]]. + * + * The `namePrefix` is used as the first part of the names of the actors running + * the processing steps. The default `namePrefix` is `"flow"`. The actor names are built up of + * `namePrefix-flowNumber-flowStepNumber-stepName`. + */ + def apply[T](materializerSettings: Option[ActorMaterializerSettings] = None, namePrefix: Option[String] = None)(implicit actorSystem: ActorSystem[T]): ActorMaterializer = + akka.stream.ActorMaterializer(materializerSettings, namePrefix)(actorSystem.toUntyped) + +} diff --git a/akka-stream-typed/src/test/java/akka/stream/typed/javadsl/ActorFlowCompileTest.java b/akka-stream-typed/src/test/java/akka/stream/typed/javadsl/ActorFlowCompileTest.java index f07f029524..a7a56cfde9 100644 --- a/akka-stream-typed/src/test/java/akka/stream/typed/javadsl/ActorFlowCompileTest.java +++ b/akka-stream-typed/src/test/java/akka/stream/typed/javadsl/ActorFlowCompileTest.java @@ -25,7 +25,7 @@ public class ActorFlowCompileTest { { final ActorSystem system = null; - final ActorMaterializer mat = akka.stream.typed.ActorMaterializer.create(system); + final ActorMaterializer mat = ActorMaterializerFactory.create(system); } static diff --git a/akka-stream-typed/src/test/java/akka/stream/typed/javadsl/ActorSourceSinkCompileTest.java b/akka-stream-typed/src/test/java/akka/stream/typed/javadsl/ActorSourceSinkCompileTest.java index 4af7e00b65..6276b748c8 100644 --- a/akka-stream-typed/src/test/java/akka/stream/typed/javadsl/ActorSourceSinkCompileTest.java +++ b/akka-stream-typed/src/test/java/akka/stream/typed/javadsl/ActorSourceSinkCompileTest.java @@ -24,7 +24,7 @@ public class ActorSourceSinkCompileTest { { final ActorSystem system = null; - final ActorMaterializer mat = akka.stream.typed.ActorMaterializer.create(system); + final ActorMaterializer mat = ActorMaterializerFactory.create(system); } { diff --git a/akka-stream-typed/src/test/scala/akka/stream/typed/scaladsl/ActorFlowSpec.scala b/akka-stream-typed/src/test/scala/akka/stream/typed/scaladsl/ActorFlowSpec.scala index ca2246096f..80b9dcdb7d 100644 --- a/akka-stream-typed/src/test/scala/akka/stream/typed/scaladsl/ActorFlowSpec.scala +++ b/akka-stream-typed/src/test/scala/akka/stream/typed/scaladsl/ActorFlowSpec.scala @@ -5,7 +5,7 @@ package akka.stream.typed.scaladsl //#imports -import akka.stream.typed.ActorMaterializer +import akka.stream.typed.scaladsl.ActorMaterializer import akka.stream.scaladsl._ import akka.actor.typed.ActorRef diff --git a/akka-stream-typed/src/test/scala/akka/stream/typed/scaladsl/ActorSourceSinkSpec.scala b/akka-stream-typed/src/test/scala/akka/stream/typed/scaladsl/ActorSourceSinkSpec.scala index c8f1c5a597..a54b6bf55a 100644 --- a/akka-stream-typed/src/test/scala/akka/stream/typed/scaladsl/ActorSourceSinkSpec.scala +++ b/akka-stream-typed/src/test/scala/akka/stream/typed/scaladsl/ActorSourceSinkSpec.scala @@ -11,7 +11,6 @@ import akka.stream.OverflowStrategy import akka.stream.scaladsl.Keep import akka.stream.scaladsl.Sink import akka.stream.scaladsl.Source -import akka.stream.typed.ActorMaterializer import akka.actor.testkit.typed.scaladsl.{ ActorTestKit, _ } object ActorSourceSinkSpec { diff --git a/akka-stream-typed/src/test/scala/akka/stream/typed/scaladsl/CustomGuardianAndMaterializerSpec.scala b/akka-stream-typed/src/test/scala/akka/stream/typed/scaladsl/CustomGuardianAndMaterializerSpec.scala index a3f32c6d20..898531fa7c 100644 --- a/akka-stream-typed/src/test/scala/akka/stream/typed/scaladsl/CustomGuardianAndMaterializerSpec.scala +++ b/akka-stream-typed/src/test/scala/akka/stream/typed/scaladsl/CustomGuardianAndMaterializerSpec.scala @@ -10,7 +10,6 @@ import akka.actor.typed.TypedAkkaSpecWithShutdown import akka.actor.typed.scaladsl.Behaviors import akka.stream.scaladsl.Sink import akka.stream.scaladsl.Source -import akka.stream.typed.ActorMaterializer import akka.actor.testkit.typed.scaladsl.ActorTestKit object CustomGuardianAndMaterializerSpec { diff --git a/akka-stream-typed/src/test/scala/docs/akka/stream/typed/ActorSourceSinkExample.scala b/akka-stream-typed/src/test/scala/docs/akka/stream/typed/ActorSourceSinkExample.scala index 44d72a4123..4c64f14196 100644 --- a/akka-stream-typed/src/test/scala/docs/akka/stream/typed/ActorSourceSinkExample.scala +++ b/akka-stream-typed/src/test/scala/docs/akka/stream/typed/ActorSourceSinkExample.scala @@ -5,11 +5,14 @@ package docs.akka.stream.typed import akka.NotUsed -import akka.stream.ActorMaterializer +import akka.actor.typed.ActorSystem +import akka.stream.typed.scaladsl.ActorMaterializer object ActorSourceSinkExample { - implicit val mat: ActorMaterializer = ??? + val system: ActorSystem[_] = ??? + + implicit val mat: ActorMaterializer = ActorMaterializer()(system) { // #actor-source-ref