PageRenderTime 13ms CodeModel.GetById 10ms app.highlight 1ms RepoModel.GetById 2ms app.codeStats 0ms

/scalate-jrebel/src/main/scala/org/fusesource/scalate/jrebel/ScalateReloader.scala

http://github.com/scalate/scalate
Scala | 32 lines | 18 code | 6 blank | 8 comment | 0 complexity | 7b98b3873dabda9a5965a675211b1c9b MD5 | raw file
 1package org.fusesource.scalate
 2package jrebel
 3
 4import org.zeroturnaround.javarebel.ClassEventListener
 5import org.zeroturnaround.javarebel.ReloaderFactory
 6import util.Logging
 7
 8/**
 9 * A JRebel plugin to reload templates in a Scalate TemplateEngine if dependent classes are modified
10 */
11object ScalateReloader extends TemplateEngineAddOn with Logging {
12
13  /**
14   * Reloads templates in a template engine if the classes are modified
15   */
16  @deprecated("Scalate-jrebel is deprecated", "1.9.6")
17  def apply(engine: TemplateEngine): Unit = {
18    info("Installing JRebel Scalate plugin on instance: " + engine + " " + System.identityHashCode(engine))
19
20    ReloaderFactory.getInstance.addClassReloadListener(new ClassEventListener {
21
22      def priority = ClassEventListener.PRIORITY_DEFAULT
23
24      def onClassEvent(i: Int, clazz: Class[_]) = {
25        // TODO we could be a bit more clever to figure out which templates need to be reloaded
26        // for now lets just flush all templates!
27        info("Flushing Scalate templates on instance: " + engine)
28        engine.invalidateCachedTemplates()
29      }
30    })
31  }
32}