Created
March 7, 2014 13:53
-
-
Save whiter4bbit/9411873 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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