-
-
Save remeniuk/9427490 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 com.typesafe.config._ | |
import akka.actor._ | |
import scala.concurrent.Await | |
import scala.concurrent.duration._ | |
object Storage { | |
val id = "storage" | |
} | |
trait Storage { | |
def store(id: String) | |
} | |
trait StorageActorProvider { | |
val storage: Storage | |
} | |
class StorageActorImpl extends Storage { | |
def store(id: String) = println(s"Stored: ${id}") | |
} | |
trait ProdStorageActorProvider extends StorageActorProvider { | |
val system = TypedActor.context.system | |
val storage = TypedActor(TypedActor.context.system).typedActorOf(TypedProps[Storage], | |
Await.result(TypedActor.context.system.actorSelection(system / Storage.id) | |
.resolveOne()(5.seconds), 5.seconds) | |
) | |
} | |
object TCPFrontend { | |
val id = "tcp-frontend" | |
} | |
trait TCPFrontend { | |
def event(id: String) | |
} | |
trait TCPFrontendImpl extends TCPFrontend { | |
self: StorageActorProvider => | |
def event(id: String) = storage.store(id) | |
} | |
class TCPFrontendProdImpl extends TCPFrontendImpl with ProdStorageActorProvider | |
object ProdShowCase { | |
def main(args: Array[String]): Unit = { | |
val system = ActorSystem("system", ConfigFactory.parseString("akka {}")) | |
TypedActor(system).typedActorOf(TypedProps[StorageActorImpl], Storage.id) | |
val ref: TCPFrontend = TypedActor(system).typedActorOf(TypedProps[TCPFrontendProdImpl], | |
TCPFrontend.id) | |
ref.event("1") | |
} | |
} | |
object TestShowCase { | |
def main(args: Array[String]): Unit = { | |
val ref = new TCPFrontendImpl with StorageActorProvider { | |
val storage = new StorageActorImpl | |
} | |
ref.event("1") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment