diff --git a/akka-jxee/src/main/scala/AkkaLoader.scala b/akka-jxee/src/main/scala/AkkaLoader.scala new file mode 100644 index 0000000000..de0c2d8e16 --- /dev/null +++ b/akka-jxee/src/main/scala/AkkaLoader.scala @@ -0,0 +1,61 @@ +/** + * Copyright (C) 2009-2010 Scalable Solutions AB + */ + +package se.scalablesolutions.akka.jxee + +import se.scalablesolutions.akka.config.Config +import se.scalablesolutions.akka.util.{Logging, Bootable} + +/* + * This class is responsible for booting up a stack of bundles and then shutting them down + */ +class AkkaLoader extends Logging { + @volatile private var hasBooted = false + + @volatile private var _bundles: Option[Bootable] = None + + def bundles = _bundles; + + /* + * Boot initializes the specified bundles + */ + def boot(withBanner: Boolean, b : Bootable): Unit = synchronized { + if (!hasBooted) { + if (withBanner) printBanner + log.info("Starting Akka...") + b.onLoad + Thread.currentThread.setContextClassLoader(getClass.getClassLoader) + log.info("Akka started successfully") + hasBooted = true + _bundles = Some(b) + } + } + + /* + * Shutdown, well, shuts down the bundles used in boot + */ + def shutdown = synchronized { + if (hasBooted) { + log.info("Shutting down Akka...") + _bundles.foreach(_.onUnload) + _bundles = None + log.info("Akka succesfully shut down") + } + } + + private def printBanner = { + log.info( +""" +============================== + __ __ + _____ | | _| | _______ + \__ \ | |/ / |/ /\__ \ + / __ \| <| < / __ \_ + (____ /__|_ \__|_ \(____ / + \/ \/ \/ \/ +""") + log.info(" Running version %s", Config.VERSION) + log.info("==============================") + } +} \ No newline at end of file diff --git a/akka-jxee/src/main/scala/Jxee.scala b/akka-jxee/src/main/scala/Jxee.scala new file mode 100644 index 0000000000..f3c110d13e --- /dev/null +++ b/akka-jxee/src/main/scala/Jxee.scala @@ -0,0 +1,26 @@ +/** + * Copyright (C) 2009-2010 Scalable Solutions AB + */ + +package se.scalablesolutions.akka.jxee + +import se.scalablesolutions.akka.remote.BootableRemoteActorService +import se.scalablesolutions.akka.actor.BootableActorLoaderService +import se.scalablesolutions.akka.camel.service.CamelService +import se.scalablesolutions.akka.config.Config +import se.scalablesolutions.akka.util.{Logging, Bootable} + +import javax.servlet.{ServletContextListener, ServletContextEvent} + + /** + * This class can be added to web.xml mappings as a listener to start and shutdown Akka. + */ +class AkkaJxEELifecycle extends ServletContextListener { + lazy val loader = new AkkaLoader + + def contextDestroyed(e: ServletContextEvent): Unit = + loader.shutdown + + def contextInitialized(e: ServletContextEvent): Unit = + loader.boot(true, new BootableActorLoaderService with BootableRemoteActorService with CamelService) + } \ No newline at end of file diff --git a/akka-kernel/src/main/scala/Kernel.scala b/akka-kernel/src/main/scala/Kernel.scala index 6c0cd87058..a4aa898088 100644 --- a/akka-kernel/src/main/scala/Kernel.scala +++ b/akka-kernel/src/main/scala/Kernel.scala @@ -4,34 +4,23 @@ package se.scalablesolutions.akka.kernel +import se.scalablesolutions.akka.jxee.AkkaLoader import se.scalablesolutions.akka.remote.BootableRemoteActorService import se.scalablesolutions.akka.comet.BootableCometActorService import se.scalablesolutions.akka.actor.BootableActorLoaderService import se.scalablesolutions.akka.camel.service.CamelService import se.scalablesolutions.akka.config.Config -import se.scalablesolutions.akka.util.{Logging, Bootable} - -import javax.servlet.{ServletContextListener, ServletContextEvent} object Main { def main(args: Array[String]) = Kernel.boot } /** - * The Akka Kernel. + * The Akka Kernel, is used to start And shutdown Akka in standalone/kernel mode. * * @author Jonas Bonér */ -object Kernel extends Logging { - @volatile private var hasBooted = false - - private val startTime = System.currentTimeMillis - - /** - * Holds a reference to the services that has been booted - */ - @volatile private var bundles: Option[Bootable] = None - +object Kernel extends AkkaLoader { /** * Boots up the Kernel with default bootables */ @@ -41,63 +30,9 @@ object Kernel extends Logging { with BootableCometActorService with CamelService) - /** - * Boots up the Kernel. - * If you pass in false as parameter then the Akka banner is not printed out. - */ - def boot(withBanner: Boolean, b : Bootable): Unit = synchronized { - if (!hasBooted) { - if (withBanner) printBanner - log.info("Starting Akka...") - b.onLoad - Thread.currentThread.setContextClassLoader(getClass.getClassLoader) - log.info("Akka started successfully") - hasBooted = true - bundles = Some(b) - } - } - - /** - * Shuts down the kernel, unloads all of the bundles - */ - def shutdown = synchronized { - if (hasBooted) { - log.info("Shutting down Akka...") - bundles.foreach(_.onUnload) - bundles = None - log.info("Akka succesfully shut down") - } - } - //For testing purposes only def startRemoteService: Unit = bundles.foreach( _ match { case x: BootableRemoteActorService => x.startRemoteService case _ => }) - - private def printBanner = { - log.info( -""" -============================== - __ __ - _____ | | _| | _______ - \__ \ | |/ / |/ /\__ \ - / __ \| <| < / __ \_ - (____ /__|_ \__|_ \(____ / - \/ \/ \/ \/ -""") - log.info(" Running version %s", Config.VERSION) - log.info("==============================") - } -} - - /** - * This class can be added to web.xml mappings as a listener to boot and shutdown Akka. - */ -class Kernel extends ServletContextListener { - def contextDestroyed(e: ServletContextEvent): Unit = - Kernel.shutdown - - def contextInitialized(e: ServletContextEvent): Unit = - Kernel.boot(true, new BootableActorLoaderService with BootableRemoteActorService) - } \ No newline at end of file +} \ No newline at end of file diff --git a/project/build/AkkaProject.scala b/project/build/AkkaProject.scala index 65d4479f0b..d602468613 100644 --- a/project/build/AkkaProject.scala +++ b/project/build/AkkaProject.scala @@ -97,9 +97,11 @@ class AkkaParent(info: ProjectInfo) extends DefaultProject(info) { lazy val akka_persistence = project("akka-persistence", "akka-persistence", new AkkaPersistenceParentProject(_)) lazy val akka_cluster = project("akka-cluster", "akka-cluster", new AkkaClusterParentProject(_)) lazy val akka_spring = project("akka-spring", "akka-spring", new AkkaSpringProject(_), akka_core) + lazy val akka_jxee = project("akka-jxee", "akka-jxee", new AkkaJxeeProject(_), + akka_core, akka_rest, akka_camel) lazy val akka_kernel = project("akka-kernel", "akka-kernel", new AkkaKernelProject(_), akka_core, akka_rest, akka_spring, akka_camel, akka_persistence, - akka_cluster, akka_amqp, akka_security, akka_comet, akka_patterns) + akka_cluster, akka_amqp, akka_security, akka_comet, akka_patterns, akka_jxee) // functional tests in java lazy val akka_fun_test = project("akka-fun-test-java", "akka-fun-test-java", new AkkaFunTestProject(_), akka_kernel) @@ -141,6 +143,7 @@ class AkkaParent(info: ProjectInfo) extends DefaultProject(info) { " dist/akka-persistence-redis_%s-%s.jar".format(buildScalaVersion, version) + " dist/akka-persistence-mongo_%s-%s.jar".format(buildScalaVersion, version) + " dist/akka-persistence-cassandra_%s-%s.jar".format(buildScalaVersion, version) + + " dist/akka-jxee_%s-%s.jar".format(buildScalaVersion, version) + " dist/akka-kernel_%s-%s.jar".format(buildScalaVersion, version) + " dist/akka-spring_%s-%s.jar".format(buildScalaVersion, version) ) @@ -322,6 +325,10 @@ class AkkaParent(info: ProjectInfo) extends DefaultProject(info) { new AkkaShoalProject(_), akka_core) } + class AkkaJxeeProject(info: ProjectInfo) extends DefaultProject(info) { + lazy val dist = deployTask(info, distPath, true, true, true) dependsOn(`package`, packageDocs, packageSrc) describedAs("Deploying") + } + class AkkaKernelProject(info: ProjectInfo) extends DefaultProject(info) { lazy val dist = deployTask(info, distPath, true, true, true) dependsOn(`package`, packageDocs, packageSrc) describedAs("Deploying") }