Skip to content

Instantly share code, notes, and snippets.

@whiter4bbit
Created March 7, 2014 13:53
Show Gist options
  • Save whiter4bbit/9411873 to your computer and use it in GitHub Desktop.
Save whiter4bbit/9411873 to your computer and use it in GitHub Desktop.
import akka.actor._
import com.typesafe.config._
object Storage {
case class Store(id: String)
}
trait StorageActorProvider {
val storageActor: Props
}
class StorageActorImpl extends Actor {
def receive = {
case Storage.Store(id) => println(s"Stored: ${id}")
}
}
trait ProdStorageActorProvider extends StorageActorProvider {
val storageActor = Props(classOf[StorageActorImpl])
}
object TCPFrontend {
case class Event(id: String)
}
trait TCPFrontend extends Actor {
self: StorageActorProvider =>
lazy val storageRef = context.actorOf(storageActor)
def receive = {
case TCPFrontend.Event(id) => storageRef ! Storage.Store(id)
}
}
class TCPFrontendProd extends IndirectActorProducer {
override def actorClass = classOf[TCPFrontend]
override def produce = new TCPFrontend with ProdStorageActorProvider
}
object ShowCase {
def main(args: Array[String]): Unit = {
val system = ActorSystem("system", ConfigFactory.parseString("akka {}"))
val ref = system.actorOf(Props(classOf[TCPFrontendProd]))
ref ! TCPFrontend.Event("1")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment