casualjim
10/24/2011 - 9:33 PM

dsl proposal for embedded servers

dsl proposal for embedded servers

object Main {
  def main(args: Array[String]) {
    MySquerylScheme.initialize()

    WebServer("src/main/webapp", Config.webServerPort) { server =>
      server.inContext("/api") { context => 
        context.mount("validate", new ValidateApp)
        context.mount("channels", new MessageChannelApp)
        
        context.mount("streams", new StreamsApp)
        context.mount("", new AccountApp)
      }
      server.mount("plans", new PlanApp)  //mounts in root context
    }

  }
}

@WebListener class Bootstrap extends ServletContextListenerBootstrap {

  def initialize(context: Context) {
    MySquerylScheme.initialize()

    context.mount("validate", new ValidateApp)
    context.mount("channels", new MessageChannelApp)
        
    context.mount("streams", new StreamsApp)
    context.mount("", new AccountApp)
  }

  def destroy(context: Context) { }
}

trait Context {
  def mount[App <: ScalatraKernel](path: String, app: App): Configurator[App]
}

trait Configurator {
  def addListener(fn: () => Unit): this.type
  def set(kv: (String, Any)): this.type
  def purge(kv: (String, Any)): this.type
}