scala - Akka intercepting receive with stackable behavior -


Akka and Scala newbie here, please feel free to edit the question as necessary so that the domain of my intent is clearly In Scala and Akka

Before I show the code snippet, here is the problem that I want to solve: I essentially want to develop a common module for the use of my team, While developing your application using I want to allow them to mix a feature which will extend their functionality over runtime, mainly for logging purposes Compilation'm running errors, which I will soon explain.

But first, for example, a simple main:

  object test app {widens system system = actor system ("system") val myActor = System.actorOf (Props (new MyActor), "myActor") myActor! "Hello world!" }  

Here is an example implementation of an actor, which a team member can apply in his application:

  class MyActor extension of actor with ActorLogger Does {Override DIF Received: Receive = {Case Message = & gt; {Log.info ("test ...")} case _ = & gt; Throw new runtime exposition ("runtime execution")}}  

and here's an example of how I will provide a common feature to their mix:

  Attribute Actor Expansion of Logger Actor [Val Log: Diagnostic LaggingEditor = Logging (This) Abstract Override Def Received: Receive = {Case Message: Any = & gt; {If.InstanceOf [string]) {println ("enter") log. Mdc (map [string, anai] ("somewhat" -> 123)) super. Recept (msg) log.clear MDC () println ("exit")}} case _ => As you can see, I am trying to add data to an MDC, if the message happens, then the string (a basic example,  
  error: (29, 16) underwriting method special The type of actor logger type = & gt; MyActor.this.Receive; receives the 'summary override' modifier override def of the requirements of the method: get = {^  

here What's wrong? And is it true to go away to achieve something like this? No, so what's the most idiotic way?

More generally, is another pattern being applied here with the "Interceptor" pattern?

Thanks for all help !

unacquainted without a hack solution with the package:

  Imported akka.actor {Actor, ActorSystem, Props} Specialty MyActorExtension Extends Actor {def receiveExtension: Receive = PartialFunction.empty} {MyActorExtension Protected Def receiveMsg: Receiving Def Received Do: Get = receiveExtension orElse receiveMsg} abstract class MyActor extends override feature MyActorExtension {abstract with ActorLogger1 extends MyActor Diif Praptakteston = {case msg = & gt; Println ("********* logging # 1: $ msg") super.receiveExtension.applyOrElse (message, receiveMsg)}} attribute ActorLogger2 MyActorExtension {summary override def receiveExtension = {MyActor extends message from case = & Gt; Println ("########## Logging # 2: $ msg") super.receiveExtension.applyOrElse (message, receiveMsg)}} Class SpecificActor MyActor ActorLogger1 with ActorLogger2 {def receiveMsg = {case someMsg = Extends with & Gt; Println ("SpecificActor: $ someMsg")}} Object testing application {Val System = ActorSystem ("System") Val mySpecificActor = system.actorOf Expands (Props (New SpecificActor), "SpecificActor") mySpecificActor! "Hello world!" }  
#### Logging # 2: Hello World!

****** Logging # 1: Hello World!

Featured Actor: Hello World!


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -