Extensions
To help the process of making OverTransportLayer and all it's internal components, OverLayer come with a couple extensions.
AskPattern Extensions#
Information
Method extensions for RecipientRef for handling AskPattern.
io.github.dexclaimation.overlayer.implicits.ActorExtensions
call#
Ask and await a request response from an Askable
Blocking operation
This method is blocking using Await.
Example
import io.github.dexclaimation.overlayer.implicits.ActorExtensions._
case class Req(message: String, replyTo: ActorRef[String])
val myBehavior = Behavior.receiveMessage[Req] { case Req(msg, replyTo) => replyTo ! msg Behaviors.same}
val system = ActorSystem(myBehavior, "...")
val res0 = system.call[String](Req("Hello World", _))// -> "Hello World"Returns the result from the askable.
| Name | Type | Description |
|---|---|---|
replyTo | ActorRef[Res] => Req | ActorRef for the Actor to complete the request. |
to | Timeout | Timeout for the ask pattern. |
sch | Scheduler | Scheduler for ask pattern. |
?:
An operator alias for .call
Blocking operation
This method is blocking using Await.
Example
import io.github.dexclaimation.overlayer.implicits.ActorExtensions._
case class Req(message: String, replyTo: ActorRef[String])
val myBehavior = Behavior.receiveMessage[Req] { case Req(msg, replyTo) => replyTo ! msg Behaviors.same}
val system = ActorSystem(myBehavior, "...")val request = (r: String) => Req("Hello World", r)val res0 = system ?: request// -> "Hello World"Returns the result from the askable.
| Name | Type | Description |
|---|---|---|
replyTo | ActorRef[Res] => Req | ActorRef for the Actor to complete the request. |
to | Timeout | Timeout for the ask pattern. |
sch | Scheduler | Scheduler for ask pattern. |
SpawnProtocol Extensions#
Information
Method extensions for RecipientRef for handling SpawnProtocol.
io.github.dexclaimation.overlayer.implicits.ActorExtensions
spawn#
Utilising ask-pattern and spawn-protocol to spawn Actor outside the ActorSystem
Blocking operation
This method is blocking using Await.
Example
import io.github.dexclaimation.overlayer.implicits.ActorExtensions._
val system = ActorSystem(OverTransportLayer.behavior, "...")
val myBehavior = Behavior.receiveMessage[String] { msg => println(msg)}
val actorRef = system.spawn(myBehavior, "my-actor")// ActorRef[String]Returns a new ActorRef for the spawned Behavior.
| Name | Type | Description |
|---|---|---|
behavior | Behavior[T] | Behavior for the Actor. |
name | String | Name of the Actor. |
props | Props | Props for the Actor. Default: Props.empty |
to | Timeout | Timeout for the ask pattern. |
sch | Scheduler | Scheduler for ask pattern. |
launch#
Asynchronously utilising ask-pattern and spawn-protocol to spawn Actor outside the ActorSystem
Blocking operation
Example
import io.github.dexclaimation.overlayer.implicits.ActorExtensions._
val system = ActorSystem(OverTransportLayer.behavior, "...")
val myBehavior = Behavior.receiveMessage[String] { msg => println(msg)}
val actorFut = system.spawn(myBehavior, "my-actor")// Future[ActorRef[String]]Returns a Future of a new ActorRef for the spawned Behavior.
| Name | Type | Description |
|---|---|---|
behavior | Behavior[T] | Behavior for the Actor. |
name | String | Name of the Actor. |
props | Props | Props for the Actor. Default: Props.empty |
to | Timeout | Timeout for the ask pattern. |
sch | Scheduler | Scheduler for ask pattern. |
GraphQL JsObject Extensions#
Information
Method extensions for spray-json's JsObject for extracting request information about GraphQL operation.
io.github.dexclaimation.overlayer.implicits.JsValueExtensions
operationName#
A getter / computed properties for accessing the operationName from a JsObject.
Returns an Option of String.
variables#
A getter / computed properties for accessing the variables from a JsObject.
Returns a JsObject for the variables.
queryAst#
A getter / computed properties for accessing the query from a JsObject and parse it to a GraphQL AST in a exception safe way.
Returns a Try of sangria.ast.Document.
graphql#
A shorthand for all the previos properties (queryAst, operationName, and variables)
Returns a Try of sangria.ast.Document, Option[String], and JsObject.
Source Extensions#
Information
Method extensions for Source.
io.github.dexclaimation.overlayer.implicits.StreamExtensions
also#
Combine the current Source with an additional Source of the same type and merge their stream data.
Example
import io.github.dexclaimation.overlayer.implicits.StreamExtensions._
val singleMessage = Source.single("Hello..")val tickedMessage = Source.tick(1.second, 1.second, "World!!")
val combinedMessage: Source[String, NotUsed] = singleMessage.also(tickedMessage)
combinedMessage .runForEach { out => println(out) }
// > "Hello.."// > "World!!"// > "World!!"// ...Returns a combined Source of the same type and materialized value of NotUsed.
| Name | Type | Description |
|---|---|---|
secondSource | Source[Out, _] | Additional Source for the same output type. |
idleIfFinite#
Apply an idleTimeout to a Source with the given duration if that duration is a FiniteDuration.
Returns a Source that have the idleTimeout applied if met condition.
| Name | Type | Description |
|---|---|---|
duration | Duration | Timeout duration. |
Sink Extensions#
Information
Method extensions for Sink.
io.github.dexclaimation.overlayer.implicits.StreamExtensions
withBefore#
Basically, similar to Source.map but applied in reverse order / backwards.
Example
import io.github.dexclaimation.overlayer.implicits.StreamExtensions._
val source = Source.tick(1.second, 1.second, "World!!")
val sink: Sink[String, NotUsed] = Sink .foreach[Int](println) .withBefore[String](_.length)
source.to(sink).run()// > 7// > 7// ...Returns a Sink of the second type In2.
| Name | Type | Description |
|---|---|---|
f | In2 => In | Additional transform effect before first sink of type In. |