Skip to content

Instantly share code, notes, and snippets.

@diggzhang
Created September 13, 2017 04:17
Show Gist options
  • Save diggzhang/6edfe3a5197e6e0384f2e729c6902771 to your computer and use it in GitHub Desktop.
Save diggzhang/6edfe3a5197e6e0384f2e729c6902771 to your computer and use it in GitHub Desktop.
PriorityMailBox code snip
package com.packt.chapter1
import akka.actor.{Props, ActorSystem, Actor}
import akka.dispatch.{PriorityGenerator, UnboundedPriorityMailbox}
import com.typesafe.config.Config
/**
* Created by user
*/
object PriorityMailBoxApp extends App {
val actorSystem = ActorSystem("HelloAkka")
val myPriorityActor = actorSystem.actorOf(Props[MyPriorityActor].withDispatcher("prio-dispatcher"))
myPriorityActor ! 6.0
myPriorityActor ! 1
myPriorityActor ! 5.0
myPriorityActor ! 3
myPriorityActor ! "Hello"
myPriorityActor ! 5
myPriorityActor ! "I am priority actor"
myPriorityActor ! "I process string messages first,then integer, long and others"
}
class MyPriorityActor extends Actor {
def receive: PartialFunction[Any, Unit] = {
case x: Int => println(x)
case x: String => println(x)
case x: Long => println(x)
case x => println(x)
}
}
class MyPriorityActorMailbox(settings: ActorSystem.Settings, config: Config) extends UnboundedPriorityMailbox(
PriorityGenerator {
case x: Int => 1
case x: String => 0
case x: Long => 2
case _ => 3
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment