Merge pull request #19558 from drewhk/wip-19333-remove-implicitmaterializer-drewhk
#19333: Remove ImplicitMaterializer
This commit is contained in:
commit
b2ce5da625
5 changed files with 5 additions and 74 deletions
|
|
@ -5,6 +5,7 @@
|
||||||
package docs.http.scaladsl
|
package docs.http.scaladsl
|
||||||
|
|
||||||
import akka.actor.{ ActorLogging, ActorSystem }
|
import akka.actor.{ ActorLogging, ActorSystem }
|
||||||
|
import akka.stream.{ ActorMaterializerSettings }
|
||||||
import akka.util.ByteString
|
import akka.util.ByteString
|
||||||
import org.scalatest.{ Matchers, WordSpec }
|
import org.scalatest.{ Matchers, WordSpec }
|
||||||
|
|
||||||
|
|
@ -78,15 +79,17 @@ class HttpClientExampleSpec extends WordSpec with Matchers {
|
||||||
import akka.actor.Actor
|
import akka.actor.Actor
|
||||||
import akka.http.scaladsl.Http
|
import akka.http.scaladsl.Http
|
||||||
import akka.http.scaladsl.model._
|
import akka.http.scaladsl.model._
|
||||||
import akka.stream.scaladsl.ImplicitMaterializer
|
import akka.stream.ActorMaterializer
|
||||||
|
import akka.stream.ActorMaterializerSettings
|
||||||
|
|
||||||
class Myself extends Actor
|
class Myself extends Actor
|
||||||
with ImplicitMaterializer
|
|
||||||
with ActorLogging {
|
with ActorLogging {
|
||||||
|
|
||||||
import akka.pattern.pipe
|
import akka.pattern.pipe
|
||||||
import context.dispatcher
|
import context.dispatcher
|
||||||
|
|
||||||
|
final implicit val materializer: ActorMaterializer = ActorMaterializer(ActorMaterializerSettings(context.system))
|
||||||
|
|
||||||
val http = Http(context.system)
|
val http = Http(context.system)
|
||||||
|
|
||||||
override def preStart() = {
|
override def preStart() = {
|
||||||
|
|
|
||||||
|
|
@ -54,9 +54,6 @@ to the Actor as a message.
|
||||||
.. includecode:: ../../code/docs/http/scaladsl/HttpClientExampleSpec.scala
|
.. includecode:: ../../code/docs/http/scaladsl/HttpClientExampleSpec.scala
|
||||||
:include: single-request-in-actor-example
|
:include: single-request-in-actor-example
|
||||||
|
|
||||||
An ``ActorMaterializer`` instance needed for Http to perfom its duties can be obtained using the ``ImplicitMaterializer``
|
|
||||||
helper trait.
|
|
||||||
|
|
||||||
Example
|
Example
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,40 +0,0 @@
|
||||||
/**
|
|
||||||
* Copyright (C) 2014 Typesafe Inc. <http://www.typesafe.com>
|
|
||||||
*/
|
|
||||||
package akka.stream.scaladsl
|
|
||||||
|
|
||||||
import akka.actor.{ Actor, Props }
|
|
||||||
import akka.stream.ActorMaterializerSettings
|
|
||||||
import akka.stream.testkit.AkkaSpec
|
|
||||||
import akka.testkit._
|
|
||||||
import akka.pattern.pipe
|
|
||||||
|
|
||||||
object ImplicitMaterializerSpec {
|
|
||||||
class SomeActor(input: List[String]) extends Actor with ImplicitMaterializer {
|
|
||||||
|
|
||||||
override def materializerSettings = ActorMaterializerSettings(context.system)
|
|
||||||
.withInputBuffer(initialSize = 2, maxSize = 16)
|
|
||||||
|
|
||||||
val flow = Source(input).map(_.toUpperCase())
|
|
||||||
|
|
||||||
def receive = {
|
|
||||||
case "run" ⇒
|
|
||||||
// run takes an implicit ActorMaterializer parameter, which is provided by ImplicitMaterializer
|
|
||||||
import context.dispatcher
|
|
||||||
flow.runFold("")(_ + _) pipeTo sender()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ImplicitMaterializerSpec extends AkkaSpec with ImplicitSender {
|
|
||||||
import ImplicitMaterializerSpec._
|
|
||||||
|
|
||||||
"An ImplicitMaterializer" must {
|
|
||||||
|
|
||||||
"provide implicit ActorMaterializer" in {
|
|
||||||
val actor = system.actorOf(Props(classOf[SomeActor], List("a", "b", "c")).withDispatcher("akka.test.stream-dispatcher"))
|
|
||||||
actor ! "run"
|
|
||||||
expectMsg("ABC")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
/**
|
|
||||||
* Copyright (C) 2014 Typesafe Inc. <http://www.typesafe.com>
|
|
||||||
*/
|
|
||||||
package akka.stream.scaladsl
|
|
||||||
|
|
||||||
import akka.actor.Actor
|
|
||||||
import akka.stream.ActorMaterializerSettings
|
|
||||||
import akka.stream.ActorMaterializer
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mix this trait into your [[akka.actor.Actor]] if you need an implicit
|
|
||||||
* [[akka.stream.Materializer]] in scope.
|
|
||||||
*
|
|
||||||
* Subclass may override [[#materializerSettings]] to define custom
|
|
||||||
* [[akka.stream.ActorMaterializerSettings]] for the `Materializer`.
|
|
||||||
*/
|
|
||||||
trait ImplicitMaterializer { this: Actor ⇒
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Subclass may override this to define custom
|
|
||||||
* [[akka.stream.ActorMaterializerSettings]] for the `Materializer`.
|
|
||||||
*/
|
|
||||||
def materializerSettings: ActorMaterializerSettings = ActorMaterializerSettings(context.system)
|
|
||||||
|
|
||||||
final implicit val materializer: ActorMaterializer = ActorMaterializer(Some(materializerSettings))
|
|
||||||
}
|
|
||||||
|
|
@ -47,9 +47,6 @@ package akka.stream
|
||||||
* by those methods that materialize the Flow into a series of
|
* by those methods that materialize the Flow into a series of
|
||||||
* [[org.reactivestreams.Processor]] instances. The returned reactive stream
|
* [[org.reactivestreams.Processor]] instances. The returned reactive stream
|
||||||
* is fully started and active.
|
* is fully started and active.
|
||||||
*
|
|
||||||
* Use [[ImplicitMaterializer]] to define an implicit [[akka.stream.Materializer]]
|
|
||||||
* inside an [[akka.actor.Actor]].
|
|
||||||
*/
|
*/
|
||||||
package object scaladsl {
|
package object scaladsl {
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue