Skip to content

Instantly share code, notes, and snippets.

@volgar1x
Created October 19, 2013 21:16
Show Gist options
  • Save volgar1x/7061702 to your computer and use it in GitHub Desktop.
Save volgar1x/7061702 to your computer and use it in GitHub Desktop.
trait ConfigComponent {
trait Config {
def get[T](key: String): T
}
val config: Config
}
trait ConfigComponentImpl extends ConfigComponent {
class ConfigImpl extends Config {
val values = Map[String, Any]("some.key" -> 42)
def get[T](key: String) = values(key).asInstanceOf[T]
}
val config = new ConfigImpl
}
trait NetServiceComponent {
type NetSession <: NetSessionInterface
val netService: NetServiceInterface
trait NetServiceInterface {
type TFut = Future[this.type]
def connected: Seq[NetSession]
def boot(): TFut
def kill(): TFut
}
trait NetSessionInterface {
type TFut = Future[this.type]
def service: NetService
def write(o: Any): TFut
def flush(): TFut
def close(): TFut
}
}
trait NetServiceComponentImpl { self: ConfigurationComponent =>
private val port = config.get("port"): Int
type NetSession = NetSessionImpl
val netService = new NetServiceImpl
class NetServiceImpl extends NetService {
val connected = mutable.ArrayBuffer.empty[NetSession]
def boot(): TFut = ???
def kill(): TFut = ???
}
class NetSessionImpl extends NetSessionInterface {
def service = netService
def write(o: Any) = ???
def flush() = ???
def close() = ???
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment