Skip to content

Instantly share code, notes, and snippets.

@whiter4bbit
Created March 6, 2014 16:31
Show Gist options
  • Save whiter4bbit/9393603 to your computer and use it in GitHub Desktop.
Save whiter4bbit/9393603 to your computer and use it in GitHub Desktop.
import akka.actor._
object TCPFrontend {
case class Event(id: String)
}
trait StorageComponent {
val storage: Storage
trait Storage {
def store(id: String): Unit
}
}
trait StorageComponentImpl extends StorageComponent {
val storage = new StorageImpl
class StorageImpl extends Storage {
def store(id: String): Unit = println(s"Stored")
}
}
trait TCPFrontend extends Actor {
self: StorageComponent =>
def receive = {
case TCPFrontend.Event(id) => storage.store(id)
}
}
class TCPFrontendProd extends IndirectActorProducer {
override def actorClass = classOf[TCPFrontend]
override def produce = new TCPFrontend with StorageComponentImpl
}
object ShowCase {
def main(args: Array[String]): Unit = {
val system = ActorSystem()
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