Created jxee module

This commit is contained in:
Viktor Klang 2010-04-05 00:18:58 +02:00
parent 0cfe5e24c8
commit 04c45b28f1
4 changed files with 99 additions and 70 deletions

View file

@ -0,0 +1,61 @@
/**
* Copyright (C) 2009-2010 Scalable Solutions AB <http://scalablesolutions.se>
*/
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("==============================")
}
}

View file

@ -0,0 +1,26 @@
/**
* Copyright (C) 2009-2010 Scalable Solutions AB <http://scalablesolutions.se>
*/
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)
}

View file

@ -4,34 +4,23 @@
package se.scalablesolutions.akka.kernel package se.scalablesolutions.akka.kernel
import se.scalablesolutions.akka.jxee.AkkaLoader
import se.scalablesolutions.akka.remote.BootableRemoteActorService import se.scalablesolutions.akka.remote.BootableRemoteActorService
import se.scalablesolutions.akka.comet.BootableCometActorService import se.scalablesolutions.akka.comet.BootableCometActorService
import se.scalablesolutions.akka.actor.BootableActorLoaderService import se.scalablesolutions.akka.actor.BootableActorLoaderService
import se.scalablesolutions.akka.camel.service.CamelService import se.scalablesolutions.akka.camel.service.CamelService
import se.scalablesolutions.akka.config.Config import se.scalablesolutions.akka.config.Config
import se.scalablesolutions.akka.util.{Logging, Bootable}
import javax.servlet.{ServletContextListener, ServletContextEvent}
object Main { object Main {
def main(args: Array[String]) = Kernel.boot 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 <a href="http://jonasboner.com">Jonas Bon&#233;r</a> * @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
*/ */
object Kernel extends Logging { object Kernel extends AkkaLoader {
@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
/** /**
* Boots up the Kernel with default bootables * Boots up the Kernel with default bootables
*/ */
@ -41,63 +30,9 @@ object Kernel extends Logging {
with BootableCometActorService with BootableCometActorService
with CamelService) 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 //For testing purposes only
def startRemoteService: Unit = bundles.foreach( _ match { def startRemoteService: Unit = bundles.foreach( _ match {
case x: BootableRemoteActorService => x.startRemoteService case x: BootableRemoteActorService => x.startRemoteService
case _ => 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)
} }

View file

@ -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_persistence = project("akka-persistence", "akka-persistence", new AkkaPersistenceParentProject(_))
lazy val akka_cluster = project("akka-cluster", "akka-cluster", new AkkaClusterParentProject(_)) 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_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(_), lazy val akka_kernel = project("akka-kernel", "akka-kernel", new AkkaKernelProject(_),
akka_core, akka_rest, akka_spring, akka_camel, akka_persistence, 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 // functional tests in java
lazy val akka_fun_test = project("akka-fun-test-java", "akka-fun-test-java", new AkkaFunTestProject(_), akka_kernel) 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-redis_%s-%s.jar".format(buildScalaVersion, version) +
" dist/akka-persistence-mongo_%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-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-kernel_%s-%s.jar".format(buildScalaVersion, version) +
" dist/akka-spring_%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) 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) { class AkkaKernelProject(info: ProjectInfo) extends DefaultProject(info) {
lazy val dist = deployTask(info, distPath, true, true, true) dependsOn(`package`, packageDocs, packageSrc) describedAs("Deploying") lazy val dist = deployTask(info, distPath, true, true, true) dependsOn(`package`, packageDocs, packageSrc) describedAs("Deploying")
} }