Container Stop / Reload Event Handling

I have an application launcher application that launches an ssh daemon in Boot.scala. This is the problem: when I start container:restart /in an sbt session, I get an alread in use address exception. Now two questions:

  • Is it right to start the boot in Boot.scala?
  • In any case, how can I handle the container: stop the event?
+5
source share
2 answers

I think Lift-y's way of doing this with LiftRules.unloadHooks.

This is not well documented (AFAIK), but if you look in the Lift source code, you will see that when LiftServletis destroy()ed, the functions defined in are executed LiftRules.unloadHooks.

unloadHooks RulesSeq append prepend, , , . , bootstrap.liftweb.Boot.boot - :

sshDaemon.start()
LiftRules.unloadHooks.append( () => sshDaemon.stop() )

(, SSH-.)

100% , LiftServlet.destroy() , sbt web-plugin container:restart - Jetty, Lift, container:stop .

+10

Lift, - .

ServletContextListener web.xml contextDestroyed. ( contextCreated.)

setAttribute/getAttribute .

:

import javax.servlet.{ServletContextEvent, ServletContextListener}


final class SshListener extends ServletContextListener{
  val attributeKey = "sshServer"

  def contextInitialized(sce: ServletContextEvent) {
    val server = new Server()
    server.start()
    sce.getServletContext.setAttribute(attributeKey, server)
  }

  def contextDestroyed(sce: ServletContextEvent) {
    Option(sce.getServletContext.getAttribute(attributeKey)).foreach(_.asInstanceOf[Server].stop())
  }
}

class Server {
  def start()
  def stop()
}
+4

All Articles