format source with scalafmt

This commit is contained in:
Auto Format 2019-03-11 10:38:24 +01:00 committed by Patrik Nordwall
parent 0f40491d42
commit ce404e4f53
1669 changed files with 43208 additions and 35404 deletions

View file

@ -55,8 +55,12 @@ object ActorFlow {
* @tparam Q Question message type that is spoken by the target actor
* @tparam A Answer type that the Actor is expected to reply with, it will become the Output type of this Flow
*/
def ask[I, Q, A](ref: ActorRef[Q], timeout: java.time.Duration, makeMessage: BiFunction[I, ActorRef[A], Q]): Flow[I, A, NotUsed] =
akka.stream.typed.scaladsl.ActorFlow.ask[I, Q, A](parallelism = 2)(ref)((i, ref) => makeMessage(i, ref))(JavaDurationConverters.asFiniteDuration(timeout))
def ask[I, Q, A](ref: ActorRef[Q],
timeout: java.time.Duration,
makeMessage: BiFunction[I, ActorRef[A], Q]): Flow[I, A, NotUsed] =
akka.stream.typed.scaladsl.ActorFlow
.ask[I, Q, A](parallelism = 2)(ref)((i, ref) => makeMessage(i, ref))(
JavaDurationConverters.asFiniteDuration(timeout))
.asJava
/**
@ -92,8 +96,12 @@ object ActorFlow {
* @tparam Q Question message type that is spoken by the target actor
* @tparam A Answer type that the Actor is expected to reply with, it will become the Output type of this Flow
*/
def ask[I, Q, A](parallelism: Int, ref: ActorRef[Q], timeout: java.time.Duration, makeMessage: (I, ActorRef[A]) => Q): Flow[I, A, NotUsed] =
akka.stream.typed.scaladsl.ActorFlow.ask[I, Q, A](parallelism)(ref)((i, ref) => makeMessage(i, ref))(timeout.toMillis.millis)
def ask[I, Q, A](parallelism: Int,
ref: ActorRef[Q],
timeout: java.time.Duration,
makeMessage: (I, ActorRef[A]) => Q): Flow[I, A, NotUsed] =
akka.stream.typed.scaladsl.ActorFlow
.ask[I, Q, A](parallelism)(ref)((i, ref) => makeMessage(i, ref))(timeout.toMillis.millis)
.asJava
}

View file

@ -41,7 +41,9 @@ object ActorMaterializerFactory {
* the processing steps. The default `namePrefix` is `"flow"`. The actor names are built up of
* `namePrefix-flowNumber-flowStepNumber-stepName`.
*/
def create[T](settings: ActorMaterializerSettings, namePrefix: String, actorSystem: ActorSystem[T]): akka.stream.ActorMaterializer =
def create[T](settings: ActorMaterializerSettings,
namePrefix: String,
actorSystem: ActorSystem[T]): akka.stream.ActorMaterializer =
akka.stream.ActorMaterializer.create(settings, actorSystem.toUntyped, namePrefix)
/**
@ -72,6 +74,8 @@ object ActorMaterializerFactory {
* the processing steps. The default `namePrefix` is `"flow"`. The actor names are built up of
* `namePrefix-flowNumber-flowStepNumber-stepName`.
*/
def create[T](settings: ActorMaterializerSettings, namePrefix: String, ctx: ActorContext[T]): akka.stream.ActorMaterializer =
def create[T](settings: ActorMaterializerSettings,
namePrefix: String,
ctx: ActorContext[T]): akka.stream.ActorMaterializer =
akka.stream.ActorMaterializer.create(settings, Adapter.toUntyped(ctx), namePrefix)
}

View file

@ -13,6 +13,7 @@ import akka.stream.typed
* Collection of Sinks aimed at integrating with typed Actors.
*/
object ActorSink {
/**
* Sends the elements of the stream to the given `ActorRef`.
* If the target actor terminates the stream will be canceled.
@ -29,7 +30,9 @@ object ActorSink {
* to use a bounded mailbox with zero `mailbox-push-timeout-time` or use a rate
* limiting operator in front of this `Sink`.
*/
def actorRef[T](ref: ActorRef[T], onCompleteMessage: T, onFailureMessage: akka.japi.function.Function[Throwable, T]): Sink[T, NotUsed] =
def actorRef[T](ref: ActorRef[T],
onCompleteMessage: T,
onFailureMessage: akka.japi.function.Function[Throwable, T]): Sink[T, NotUsed] =
typed.scaladsl.ActorSink.actorRef(ref, onCompleteMessage, onFailureMessage.apply).asJava
/**
@ -45,14 +48,19 @@ object ActorSink {
* When the stream is completed with failure - result of `onFailureMessage(throwable)`
* function will be sent to the destination actor.
*/
def actorRefWithAck[T, M, A](
ref: ActorRef[M],
messageAdapter: akka.japi.function.Function2[ActorRef[A], T, M],
onInitMessage: akka.japi.function.Function[ActorRef[A], M],
ackMessage: A,
onCompleteMessage: M,
onFailureMessage: akka.japi.function.Function[Throwable, M]): Sink[T, NotUsed] =
typed.scaladsl.ActorSink.actorRefWithAck(
ref, messageAdapter.apply, onInitMessage.apply, ackMessage, onCompleteMessage, onFailureMessage.apply).asJava
def actorRefWithAck[T, M, A](ref: ActorRef[M],
messageAdapter: akka.japi.function.Function2[ActorRef[A], T, M],
onInitMessage: akka.japi.function.Function[ActorRef[A], M],
ackMessage: A,
onCompleteMessage: M,
onFailureMessage: akka.japi.function.Function[Throwable, M]): Sink[T, NotUsed] =
typed.scaladsl.ActorSink
.actorRefWithAck(ref,
messageAdapter.apply,
onInitMessage.apply,
ackMessage,
onCompleteMessage,
onFailureMessage.apply)
.asJava
}

View file

@ -47,12 +47,15 @@ object ActorSource {
* @param bufferSize The size of the buffer in element count
* @param overflowStrategy Strategy that is used when incoming elements cannot fit inside the buffer
*/
def actorRef[T](
completionMatcher: Predicate[T],
failureMatcher: PartialFunction[T, Throwable],
bufferSize: Int, overflowStrategy: OverflowStrategy): Source[T, ActorRef[T]] = {
akka.stream.typed.scaladsl.ActorSource.actorRef(
{ case m if completionMatcher.test(m) => }: PartialFunction[T, Unit],
failureMatcher, bufferSize, overflowStrategy).asJava
def actorRef[T](completionMatcher: Predicate[T],
failureMatcher: PartialFunction[T, Throwable],
bufferSize: Int,
overflowStrategy: OverflowStrategy): Source[T, ActorRef[T]] = {
akka.stream.typed.scaladsl.ActorSource
.actorRef({ case m if completionMatcher.test(m) => }: PartialFunction[T, Unit],
failureMatcher,
bufferSize,
overflowStrategy)
.asJava
}
}

View file

@ -60,7 +60,8 @@ object ActorFlow {
* @tparam A Answer type that the Actor is expected to reply with, it will become the Output type of this Flow
*/
@implicitNotFound("Missing an implicit akka.util.Timeout for the ask() stage")
def ask[I, Q, A](ref: ActorRef[Q])(makeMessage: (I, ActorRef[A]) => Q)(implicit timeout: Timeout): Flow[I, A, NotUsed] =
def ask[I, Q, A](ref: ActorRef[Q])(makeMessage: (I, ActorRef[A]) => Q)(
implicit timeout: Timeout): Flow[I, A, NotUsed] =
ask(parallelism = 2)(ref)(makeMessage)(timeout)
/**
@ -98,7 +99,8 @@ object ActorFlow {
* @tparam A answer type that the Actor is expected to reply with, it will become the Output type of this Flow
*/
@implicitNotFound("Missing an implicit akka.util.Timeout for the ask() stage")
def ask[I, Q, A](parallelism: Int)(ref: ActorRef[Q])(makeMessage: (I, ActorRef[A]) => Q)(implicit timeout: Timeout): Flow[I, A, NotUsed] = {
def ask[I, Q, A](parallelism: Int)(ref: ActorRef[Q])(makeMessage: (I, ActorRef[A]) => Q)(
implicit timeout: Timeout): Flow[I, A, NotUsed] = {
import akka.actor.typed.scaladsl.adapter._
val untypedRef = ref.toUntyped

View file

@ -23,7 +23,8 @@ object ActorMaterializer {
* 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 =
def apply[T](materializerSettings: Option[ActorMaterializerSettings] = None, namePrefix: Option[String] = None)(
implicit actorSystem: ActorSystem[T]): ActorMaterializer =
akka.stream.ActorMaterializer(materializerSettings, namePrefix)(actorSystem.toUntyped)
/**
@ -38,7 +39,9 @@ object ActorMaterializer {
* the processing steps. The default `namePrefix` is `"flow"`. The actor names are built up of
* `namePrefix-flowNumber-flowStepNumber-stepName`.
*/
def boundToActor[T](ctx: ActorContext[T], materializerSettings: Option[ActorMaterializerSettings] = None, namePrefix: Option[String] = None): ActorMaterializer =
def boundToActor[T](ctx: ActorContext[T],
materializerSettings: Option[ActorMaterializerSettings] = None,
namePrefix: Option[String] = None): ActorMaterializer =
akka.stream.ActorMaterializer(materializerSettings, namePrefix)(ctx.toUntyped)
}

View file

@ -46,17 +46,17 @@ object ActorSink {
* When the stream is completed with failure - result of `onFailureMessage(throwable)`
* function will be sent to the destination actor.
*/
def actorRefWithAck[T, M, A](
ref: ActorRef[M],
messageAdapter: (ActorRef[A], T) => M,
onInitMessage: ActorRef[A] => M,
ackMessage: A,
onCompleteMessage: M,
onFailureMessage: Throwable => M): Sink[T, NotUsed] =
Sink.actorRefWithAck(
ref.toUntyped,
messageAdapter.curried.compose(actorRefAdapter),
onInitMessage.compose(actorRefAdapter),
ackMessage, onCompleteMessage, onFailureMessage)
def actorRefWithAck[T, M, A](ref: ActorRef[M],
messageAdapter: (ActorRef[A], T) => M,
onInitMessage: ActorRef[A] => M,
ackMessage: A,
onCompleteMessage: M,
onFailureMessage: Throwable => M): Sink[T, NotUsed] =
Sink.actorRefWithAck(ref.toUntyped,
messageAdapter.curried.compose(actorRefAdapter),
onInitMessage.compose(actorRefAdapter),
ackMessage,
onCompleteMessage,
onFailureMessage)
}

View file

@ -47,12 +47,14 @@ object ActorSource {
* @param bufferSize The size of the buffer in element count
* @param overflowStrategy Strategy that is used when incoming elements cannot fit inside the buffer
*/
def actorRef[T](
completionMatcher: PartialFunction[T, Unit],
failureMatcher: PartialFunction[T, Throwable],
bufferSize: Int, overflowStrategy: OverflowStrategy): Source[T, ActorRef[T]] =
Source.actorRef[T](
completionMatcher.asInstanceOf[PartialFunction[Any, Unit]],
failureMatcher.asInstanceOf[PartialFunction[Any, Throwable]],
bufferSize, overflowStrategy).mapMaterializedValue(actorRefAdapter)
def actorRef[T](completionMatcher: PartialFunction[T, Unit],
failureMatcher: PartialFunction[T, Throwable],
bufferSize: Int,
overflowStrategy: OverflowStrategy): Source[T, ActorRef[T]] =
Source
.actorRef[T](completionMatcher.asInstanceOf[PartialFunction[Any, Unit]],
failureMatcher.asInstanceOf[PartialFunction[Any, Throwable]],
bufferSize,
overflowStrategy)
.mapMaterializedValue(actorRefAdapter)
}

View file

@ -43,7 +43,8 @@ class ActorFlowSpec extends ScalaTestWithActorTestKit with WordSpecLike {
"produce asked elements" in {
val in: Future[immutable.Seq[Reply]] =
Source.repeat("hello")
Source
.repeat("hello")
.via(ActorFlow.ask(replier)((el, replyTo: ActorRef[Reply]) => Asking(el, replyTo)))
.take(3)
.runWith(Sink.seq)
@ -62,7 +63,8 @@ class ActorFlowSpec extends ScalaTestWithActorTestKit with WordSpecLike {
//#ask
val in: Future[immutable.Seq[Reply]] =
Source(1 to 50).map(_.toString)
Source(1 to 50)
.map(_.toString)
.via(ActorFlow.ask(ref)((el, replyTo: ActorRef[Reply]) => Asking(el, replyTo)))
.runWith(Sink.seq)
//#ask
@ -78,16 +80,19 @@ class ActorFlowSpec extends ScalaTestWithActorTestKit with WordSpecLike {
implicit val ec = system.dispatchers.lookup(DispatcherSelector.default())
implicit val timeout = akka.util.Timeout(10.millis)
Source(1 to 5).map(_ + " nope")
Source(1 to 5)
.map(_ + " nope")
.via(ActorFlow.ask[String, Asking, Reply](4)(dontReply)(Asking(_, _)))
.to(Sink.fromSubscriber(c)).run()
.to(Sink.fromSubscriber(c))
.run()
c.expectSubscription().request(10)
c.expectError().getMessage should startWith("Ask timed out on [Actor")
}
"signal failure when target actor is terminated" in {
val done = Source.maybe[String]
val done = Source
.maybe[String]
.via(ActorFlow.ask(replier)((el, replyTo: ActorRef[Reply]) => Asking(el, replyTo)))
.runWith(Sink.ignore)

View file

@ -33,7 +33,8 @@ class ActorSourceSinkSpec extends ScalaTestWithActorTestKit with WordSpecLike {
val p = TestProbe[String]()
val in =
Source.queue[String](10, OverflowStrategy.dropBuffer)
Source
.queue[String](10, OverflowStrategy.dropBuffer)
.map(_ + "!")
.to(ActorSink.actorRef(p.ref, "DONE", ex => "FAILED: " + ex.getMessage))
.run()
@ -47,27 +48,27 @@ class ActorSourceSinkSpec extends ScalaTestWithActorTestKit with WordSpecLike {
"obey protocol" in {
val p = TestProbe[AckProto]()
val autoPilot = Behaviors.receive[AckProto] {
(ctx, msg) =>
msg match {
case m @ Init(sender) =>
p.ref ! m
sender ! "ACK"
Behaviors.same
case m @ Msg(sender, _) =>
p.ref ! m
sender ! "ACK"
Behaviors.same
case m =>
p.ref ! m
Behaviors.same
}
val autoPilot = Behaviors.receive[AckProto] { (ctx, msg) =>
msg match {
case m @ Init(sender) =>
p.ref ! m
sender ! "ACK"
Behaviors.same
case m @ Msg(sender, _) =>
p.ref ! m
sender ! "ACK"
Behaviors.same
case m =>
p.ref ! m
Behaviors.same
}
}
val pilotRef: ActorRef[AckProto] = spawn(autoPilot)
val in =
Source.queue[String](10, OverflowStrategy.dropBuffer)
Source
.queue[String](10, OverflowStrategy.dropBuffer)
.to(ActorSink.actorRefWithAck(pilotRef, Msg.apply, Init.apply, "ACK", Complete, _ => Failed))
.run()
@ -86,7 +87,8 @@ class ActorSourceSinkSpec extends ScalaTestWithActorTestKit with WordSpecLike {
"ActorSource" should {
"send messages and complete" in {
val (in, out) = ActorSource.actorRef[String]({ case "complete" => }, PartialFunction.empty, 10, OverflowStrategy.dropBuffer)
val (in, out) = ActorSource
.actorRef[String]({ case "complete" => }, PartialFunction.empty, 10, OverflowStrategy.dropBuffer)
.toMat(Sink.seq)(Keep.both)
.run()
@ -98,7 +100,8 @@ class ActorSourceSinkSpec extends ScalaTestWithActorTestKit with WordSpecLike {
}
"fail the stream" in {
val (in, out) = ActorSource.actorRef[String](PartialFunction.empty, { case msg => new Error(msg) }, 10, OverflowStrategy.dropBuffer)
val (in, out) = ActorSource
.actorRef[String](PartialFunction.empty, { case msg => new Error(msg) }, 10, OverflowStrategy.dropBuffer)
.toMat(Sink.seq)(Keep.both)
.run()

View file

@ -26,8 +26,8 @@ object CustomGuardianAndMaterializerSpec {
class CustomGuardianAndMaterializerSpec extends ScalaTestWithActorTestKit with WordSpecLike {
import CustomGuardianAndMaterializerSpec._
val guardian = Behaviors.receive[GuardianProtocol] {
(_, msg) => Behaviors.same
val guardian = Behaviors.receive[GuardianProtocol] { (_, msg) =>
Behaviors.same
}
implicit val mat = ActorMaterializer()

View file

@ -26,20 +26,18 @@ object ActorSourceSinkExample {
case object Complete extends Protocol
case class Fail(ex: Exception) extends Protocol
val source: Source[Protocol, ActorRef[Protocol]] = ActorSource.actorRef[Protocol](
completionMatcher = {
case Complete =>
},
failureMatcher = {
case Fail(ex) => ex
},
bufferSize = 8,
overflowStrategy = OverflowStrategy.fail
)
val source: Source[Protocol, ActorRef[Protocol]] = ActorSource.actorRef[Protocol](completionMatcher = {
case Complete =>
}, failureMatcher = {
case Fail(ex) => ex
}, bufferSize = 8, overflowStrategy = OverflowStrategy.fail)
val ref = source.collect {
case Message(msg) => msg
}.to(Sink.foreach(println)).run()
val ref = source
.collect {
case Message(msg) => msg
}
.to(Sink.foreach(println))
.run()
ref ! Message("msg1")
// ref ! "msg2" Does not compile
@ -59,11 +57,8 @@ object ActorSourceSinkExample {
val actor: ActorRef[Protocol] = ???
val sink: Sink[Protocol, NotUsed] = ActorSink.actorRef[Protocol](
ref = actor,
onCompleteMessage = Complete,
onFailureMessage = Fail.apply
)
val sink: Sink[Protocol, NotUsed] =
ActorSink.actorRef[Protocol](ref = actor, onCompleteMessage = Complete, onFailureMessage = Fail.apply)
Source.single(Message("msg1")).runWith(sink)
// #actor-sink-ref
@ -86,14 +81,12 @@ object ActorSourceSinkExample {
val actor: ActorRef[Protocol] = ???
val sink: Sink[String, NotUsed] = ActorSink.actorRefWithAck(
ref = actor,
onCompleteMessage = Complete,
onFailureMessage = Fail.apply,
messageAdapter = Message.apply,
onInitMessage = Init.apply,
ackMessage = Ack
)
val sink: Sink[String, NotUsed] = ActorSink.actorRefWithAck(ref = actor,
onCompleteMessage = Complete,
onFailureMessage = Fail.apply,
messageAdapter = Message.apply,
onInitMessage = Init.apply,
ackMessage = Ack)
Source.single("msg1").runWith(sink)
// #actor-sink-ref-with-ack