Created
November 28, 2011 19:30
-
-
Save kevinwright/1401655 to your computer and use it in GitHub Desktop.
Scalate in Akka
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
... | |
lazy val engine: TemplateEngine = { | |
val ctx = CaptureContext.context.get | |
val srcDirectories = ctx.getRealPath("/") match { | |
case path: String => List(new File(path)) | |
case null => List() | |
} | |
println("Scalate got src directories " + srcDirectories) | |
new TemplateEngine(srcDirectories) | |
} | |
... |
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
package web.listeners | |
import akka.dispatch.{DefaultCompletableFuture, Future} | |
import javax.servlet.{ServletContext, ServletContextEvent, ServletContextListener} | |
import org.slf4j.LoggerFactory | |
object CaptureContext { | |
private[listeners] val completableContext = new DefaultCompletableFuture[ServletContext] | |
def context: Future[ServletContext] = completableContext | |
} | |
class CaptureContext extends ServletContextListener { | |
val log = LoggerFactory.getLogger(this.getClass) | |
import CaptureContext.completableContext.{isCompleted, complete} | |
def contextInitialized(evt: ServletContextEvent) { | |
if (!isCompleted) { | |
try { | |
val ctx = evt.getServletContext | |
log.info("Captured context " + ctx) | |
complete(Right(ctx)) | |
} catch { | |
case x: Exception => complete(Left(x)) | |
} | |
} | |
} | |
def contextDestroyed(e: ServletContextEvent) { } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment