merged in jersey-scala and atmosphere support

This commit is contained in:
jboner 2009-07-31 20:29:01 +02:00
commit 4958166e1f
24 changed files with 461 additions and 276 deletions

View file

@ -15,55 +15,68 @@ mkdir $BASE_DIR/storage/commitlog
mkdir $BASE_DIR/storage/data
mkdir $BASE_DIR/storage/system
CLASSPATH=$CLASSPATH:$BASE_DIR/config
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/akka-kernel-0.5.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/akka-util-java-0.5.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/akka-util-java.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/antlr-3.1.3.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/aopalliance-1.0.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/asm-3.1.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/aspectwerkz-nodeps-jdk5-2.1.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/camel-core-2.0-SNAPSHOT.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/cassandra-0.4.0-dev.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/cglib-2.2.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/commons-cli-1.1.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/commons-collections-3.2.1.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/commons-io-1.3.2.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/commons-javaflow-1.0-SNAPSHOT.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/commons-lang-2.4.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/commons-logging-1.0.4.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/commons-math-1.1.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/configgy-1.3.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/google-collect-snapshot-20090211.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/grizzly-framework-1.8.6.3.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/grizzly-http-1.8.6.3.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/grizzly-http-servlet-1.8.6.3.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/grizzly-http-utils-1.8.6.3.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/grizzly-servlet-webserver-1.8.6.3.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/guice-core-2.0-SNAPSHOT.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/guice-jsr250-2.0-SNAPSHOT.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/high-scale-lib.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/jackson-core-asl-1.1.0.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/jackson-mapper-asl-1.1.0.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/jersey-client-1.1.0-ea.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/jersey-core-1.0.3.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/jersey-json-1.0.3.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/jersey-server-1.0.3.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/JSAP-2.1.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/jsr250-api-1.0.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/jsr311-api-1.0.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/libfb303.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/libthrift.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/log4j-1.2.15.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/lucene-core-2.2.0.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/netty-3.1.0.CR1.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/protobuf-java-2.1.0.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/scala-library-2.7.5.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/servlet-api-2.5.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/slf4j-api-1.4.3.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/slf4j-log4j12-1.4.3.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/stringtemplate-3.0.jar
CLASSPATH=$CLASSPATH:$BASE_DIR/lib/zookeeper-3.1.0.jar
LIB_DIR=$BASE_DIR/lib
CLASSPATH=$BASE_DIR/config
CLASSPATH=$CLASSPATH:$LIB_DIR/fscontext.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/providerutil.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/akka-kernel-0.5.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/akka-util-java-0.5.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/akka-util-java.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/antlr-3.1.3.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/aopalliance-1.0.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/asm-3.1.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/aspectwerkz-nodeps-jdk5-2.1.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/camel-core-2.0-SNAPSHOT.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/cassandra-0.4.0-dev.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/cglib-2.2.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/commons-cli-1.1.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/commons-collections-3.2.1.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/commons-io-1.3.2.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/commons-javaflow-1.0-SNAPSHOT.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/commons-lang-2.4.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/commons-logging-1.0.4.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/commons-math-1.1.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/configgy-1.3.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/google-collect-snapshot-20090211.jar
#CLASSPATH=$CLASSPATH:$LIB_DIR/grizzly-framework-1.8.6.3.jar
#CLASSPATH=$CLASSPATH:$LIB_DIR/grizzly-http-1.8.6.3.jar
#CLASSPATH=$CLASSPATH:$LIB_DIR/grizzly-http-servlet-1.8.6.3.jar
#CLASSPATH=$CLASSPATH:$LIB_DIR/grizzly-http-utils-1.9.1.jar
#CLASSPATH=$CLASSPATH:$LIB_DIR/grizzly-servlet-webserver-1.8.6.3.jar
#CLASSPATH=$CLASSPATH:$LIB_DIR/grizzly-comet-1.8.6.3.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/grizzly-comet-webserver-1.8.6.3.jar
#CLASSPATH=$CLASSPATH:$LIB_DIR/grizzly-comet-webserver-1.9.17-RC2.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/guice-core-2.0-SNAPSHOT.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/guice-jsr250-2.0-SNAPSHOT.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/high-scale-lib.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/jackson-core-asl-1.1.0.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/jackson-mapper-asl-1.1.0.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/jersey-client-1.1.0-ea.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/jersey-core-1.0.3.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/jersey-json-1.0.3.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/jersey-server-1.0.3.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/jersey-scala-1.1.2-ea-SNAPSHOT.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/atmosphere-core-0.3-SNAPSHOT.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/atmosphere-portable-runtime-0.3-SNAPSHOT.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/atmosphere-compat-0.3-SNAPSHOT.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/JSAP-2.1.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/jsr250-api-1.0.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/jsr311-api-1.0.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/libfb303.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/libthrift.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/lift-webkit-1.1-M3.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/lift-util-1.1-M3.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/log4j-1.2.15.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/lucene-core-2.2.0.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/netty-3.1.0.CR1.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/protobuf-java-2.0.3.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/scala-library-2.7.5.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/servlet-api-2.5.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/slf4j-api-1.4.3.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/slf4j-log4j12-1.4.3.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/stringtemplate-3.0.jar
CLASSPATH=$CLASSPATH:$LIB_DIR/zookeeper-3.1.0.jar
# Add for debugging: -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005 \
# To have Akka dump the generated classes, add the '-Daspectwerkz.transform.dump=*' option and it will dump classes to $BASE_DIR/_dump
@ -81,7 +94,10 @@ JVM_OPTS=" \
-XX:+HeapDumpOnOutOfMemoryError \
-Dcom.sun.management.jmxremote.port=8080 \
-Dcom.sun.management.jmxremote.ssl=false \
-Djava.naming.factory.initial=com.sun.jndi.fscontext.RefFSContextFactory \
-Dcom.sun.grizzly.cometSupport=true \
-Dcom.sun.management.jmxremote.authenticate=false"
#$JAVA_HOME/bin/java $JVM_OPTS -cp $CLASSPATH se.scalablesolutions.akka.Boot se.scalablesolutions.akka.kernel.Kernel ${1}
$JAVA_HOME/bin/java $JVM_OPTS -cp $CLASSPATH se.scalablesolutions.akka.kernel.Kernel ${1}

View file

@ -17,3 +17,4 @@ log4j.appender.R.layout.ConversionPattern=%5p [%t] %d{ISO8601} %F (line %L) %m%n
# Edit the next line to point to your logs directory
log4j.appender.R.File=./logs/cassandra.log
log4j.logger.org.atmosphere=DEBUG

View file

@ -1,10 +0,0 @@
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee">
<servlet>
<servlet-name>Akka Servlet</servlet-name>
<servlet-class>se.scalablesolutions.akka.kernel.jersey.AkkaServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Akka Servlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping-->
</web-app>

Binary file not shown.

Binary file not shown.

10
deploy/root/page.html Normal file
View file

@ -0,0 +1,10 @@
<html>
<head><title>blah</title></head>
<body>
<form method="post" enctype="application/x-www-form-urlencoded" action="chat">
<input name="action"/>
<input name="name"/>
<input name="message"/>
<input type="submit" value="submit" name="submit"/>
</form>
</body>

View file

@ -89,59 +89,65 @@
<version>1.0</version>
</dependency>
<!-- For Cassandra -->
<dependency>
<groupId>org.apache.cassandra</groupId>
<artifactId>cassandra</artifactId>
<version>0.4.0-dev</version>
</dependency>
<dependency>
<groupId>com.facebook</groupId>
<artifactId>thrift</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.facebook</groupId>
<artifactId>fb303</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>high-scale-lib</groupId>
<artifactId>high-scale-lib</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.4</version>
</dependency>
<!-- For Jersey -->
<dependency>
<groupId>com.sun.grizzly</groupId>
<artifactId>grizzly-servlet-webserver</artifactId>
<version>1.9.9</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.0</version>
</dependency>
<!-- For Jersey -->
<!--<dependency>
<groupId>com.sun.grizzly</groupId>
<artifactId>grizzly-servlet-webserver</artifactId>
<version>1.9.9</version>
</dependency>-->
<dependency>
<groupId>com.sun.grizzly</groupId>
<artifactId>grizzly-comet-webserver</artifactId>
<!--<version>1.9.15b</version>-->
<version>1.8.6.3</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-scala</artifactId>
<version>1.1.2-ea-SNAPSHOT</version>
</dependency>
<!--<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-lift</artifactId>
<version>1.1.2-ea-SNAPSHOT</version>
</dependency>-->
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-core</artifactId>
<version>0.3-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-portable-runtime</artifactId>
<version>0.3-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-compat</artifactId>
<version>0.3-SNAPSHOT</version>
</dependency>
<!--<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-grizzly-adapter</artifactId>
<version>0.3-SNAPSHOT<</version>
</dependency>-->
<!-- For third-party logging -->
<dependency>
@ -191,100 +197,100 @@
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/scala</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<args>
<arg>-target:jvm-1.5</arg>
<!--arg>-unchecked</arg-->
</args>
<scalaVersion>${scala.version}</scalaVersion>
<vscaladocVersion>1.1</vscaladocVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<downloadSources>true</downloadSources>
<buildcommands>
<buildcommand>
ch.epfl.lamp.sdt.core.scalabuilder
</buildcommand>
</buildcommands>
<additionalProjectnatures>
<projectnature>
ch.epfl.lamp.sdt.core.scalanature
</projectnature>
</additionalProjectnatures>
<classpathContainers>
<classpathContainer>
org.eclipse.jdt.launching.JRE_CONTAINER
</classpathContainer>
<classpathContainer>
ch.epfl.lamp.sdt.launching.SCALA_CONTAINER
</classpathContainer>
</classpathContainers>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<configuration>
<tasks>
<copy file="target/akka-kernel-${akka.version}.jar"
tofile="../lib/akka-kernel-${akka.version}.jar"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<filtering>false</filtering>
<directory>src/main/resources</directory>
</resource>
<resource>
<filtering>false</filtering>
<directory>src/main/scala</directory>
<includes>
<include>**</include>
</includes>
<excludes>
<exclude>**/*.scala</exclude>
</excludes>
</resource>
</resources>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<configuration>
<vscaladocVersion>1.1</vscaladocVersion>
<scalaVersion>${scala.version}</scalaVersion>
</configuration>
</plugin>
</plugins>
</reporting>
<build>
<sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/scala</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<args>
<arg>-target:jvm-1.5</arg>
<!--<arg>-unchecked</arg>-->
</args>
<scalaVersion>${scala.version}</scalaVersion>
<vscaladocVersion>1.1</vscaladocVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<downloadSources>true</downloadSources>
<buildcommands>
<buildcommand>
ch.epfl.lamp.sdt.core.scalabuilder
</buildcommand>
</buildcommands>
<additionalProjectnatures>
<projectnature>
ch.epfl.lamp.sdt.core.scalanature
</projectnature>
</additionalProjectnatures>
<classpathContainers>
<classpathContainer>
org.eclipse.jdt.launching.JRE_CONTAINER
</classpathContainer>
<classpathContainer>
ch.epfl.lamp.sdt.launching.SCALA_CONTAINER
</classpathContainer>
</classpathContainers>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<configuration>
<tasks>
<copy file="target/akka-kernel-${akka.version}.jar"
tofile="../lib/akka-kernel-${akka.version}.jar"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<filtering>false</filtering>
<directory>src/main/resources</directory>
</resource>
<resource>
<filtering>false</filtering>
<directory>src/main/scala</directory>
<includes>
<include>**</include>
</includes>
<excludes>
<exclude>**/*.scala</exclude>
</excludes>
</resource>
</resources>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<configuration>
<vscaladocVersion>1.1</vscaladocVersion>
<scalaVersion>${scala.version}</scalaVersion>
</configuration>
</plugin>
</plugins>
</reporting>
</project>

View file

@ -14,7 +14,7 @@ import java.net.URLClassLoader
import net.lag.configgy.{Config, Configgy, RuntimeEnvironment}
import kernel.jersey.AkkaServlet
import kernel.jersey.{AkkaServlet,AkkaCometServlet}
import kernel.nio.RemoteServer
import kernel.state.CassandraStorage
import kernel.util.Logging
@ -37,7 +37,6 @@ object Kernel extends Logging {
val REST_URL = "http://" + REST_HOSTNAME
val REST_PORT = kernel.Kernel.config.getInt("akka.rest.port", 9998)
// FIXME add API to shut server down gracefully
private var remoteServer: RemoteServer = _
private var jerseySelectorThread: SelectorThread = _
@ -90,8 +89,8 @@ object Kernel extends Logging {
private[akka] def runApplicationBootClasses = {
val HOME = try { System.getenv("AKKA_HOME") } catch { case e: NullPointerException => throw new IllegalStateException("AKKA_HOME system variable needs to be set. Should point to the root of the Akka distribution.") }
val CLASSES = HOME + "/kernel/target/classes" // FIXME remove for dist
val LIB = HOME + "/lib"
//val CLASSES = HOME + "/kernel/target/classes" // FIXME remove for dist
//val LIB = HOME + "/lib"
val CONFIG = HOME + "/config"
val DEPLOY = HOME + "/deploy"
val DEPLOY_DIR = new File(DEPLOY)
@ -123,19 +122,29 @@ object Kernel extends Logging {
private[akka] def startJersey = {
val uri = UriBuilder.fromUri(REST_URL).port(REST_PORT).build()
val adapter = new ServletAdapter
val servlet = new AkkaServlet
adapter.setServletInstance(servlet)
adapter.setContextPath(uri.getPath)
val scheme = uri.getScheme
if (!scheme.equalsIgnoreCase("http")) throw new IllegalArgumentException("The URI scheme, of the URI " + REST_URL + ", must be equal (ignoring case) to 'http'")
val adapter = new ServletAdapter()
adapter.setHandleStaticResources(true)
adapter.setServletInstance(new AkkaCometServlet)
adapter.setContextPath(uri.getPath)
adapter.setRootFolder(System.getenv("AKKA_HOME") + "/deploy/root")
log.info("REST service root path: [" + adapter.getRootFolder + "] and context path [" + adapter.getContextPath + "] ")
val ah = new com.sun.grizzly.arp.DefaultAsyncHandler
ah.addAsyncFilter(new com.sun.grizzly.comet.CometAsyncFilter)
jerseySelectorThread = new SelectorThread
jerseySelectorThread.setAlgorithmClassName(classOf[StaticStreamAlgorithm].getName)
jerseySelectorThread.setPort(REST_PORT)
jerseySelectorThread.setAdapter(adapter)
jerseySelectorThread.setEnableAsyncExecution(true)
jerseySelectorThread.setAsyncHandler(ah)
jerseySelectorThread.listen
log.info("REST service started successfully. Listening to port [" + REST_PORT + "]")
}

View file

@ -4,17 +4,22 @@
package se.scalablesolutions.akka.kernel.jersey
import com.sun.jersey.core.spi.component.ioc.IoCComponentProviderFactory
import com.sun.jersey.core.spi.component.ComponentContext
import kernel.Kernel
import util.Logging
import javax.ws.rs.core.Context
import com.sun.jersey.core.spi.component.ioc.{IoCComponentProvider,IoCComponentProviderFactory}
import com.sun.jersey.core.spi.component.{ComponentContext}
import config.Configurator
class ActorComponentProviderFactory(val configurators: List[Configurator])
extends IoCComponentProviderFactory {
extends IoCComponentProviderFactory with Logging {
override def getComponentProvider(clazz: Class[_]): IoCComponentProvider = getComponentProvider(null, clazz)
override def getComponentProvider(clazz: Class[_]): ActorComponentProvider = getComponentProvider(null, clazz)
override def getComponentProvider(context: ComponentContext, clazz: Class[_]): ActorComponentProvider = {
new ActorComponentProvider(clazz, configurators)
override def getComponentProvider(context: ComponentContext, clazz: Class[_]): IoCComponentProvider = {
//log.info("ProviderFactory: resolve => " + clazz.getName)
configurators.find(_.isDefined(clazz)).map(_ => new ActorComponentProvider(clazz, configurators)).getOrElse(null)
}
}

View file

@ -6,26 +6,101 @@ package se.scalablesolutions.akka.kernel.jersey
import kernel.Kernel
import config.ConfiguratorRepository
import util.Logging
import com.sun.jersey.api.core.{DefaultResourceConfig, ResourceConfig}
import com.sun.jersey.api.core.{DefaultResourceConfig, ResourceConfig,ClasspathResourceConfig}
import com.sun.jersey.spi.container.servlet.ServletContainer
import com.sun.jersey.spi.container.WebApplication
import java.util.HashSet
import com.sun.jersey.server.impl.component.{IoCResourceFactory}
class AkkaServlet extends ServletContainer {
import javax.servlet.{ServletConfig}
import javax.servlet.http.{HttpServletRequest,HttpServletResponse}
import org.atmosphere.cpr.{AtmosphereServlet,AtmosphereServletProcessor,AtmosphereEvent,DefaultBroadcaster}
import org.atmosphere.cpr.AtmosphereServlet.{AtmosphereHandlerWrapper}
import org.atmosphere.container.GrizzlyCometSupport
import org.atmosphere.handler.ReflectorServletProcessor
import org.atmosphere.core.{JerseyBroadcaster}
import java.util.{HashSet, HashMap}
import java.net.{URL,URLClassLoader}
import java.io.{InputStream}
import scala.collection.jcl.Conversions._
class AkkaServlet extends ServletContainer with AtmosphereServletProcessor with Logging {
override def initiate(rc: ResourceConfig, wa: WebApplication) = {
Kernel.boot // will boot if not already booted by 'main'
val configurators = ConfiguratorRepository.getConfiguratorsFor(getServletContext);
val set = new HashSet[Class[_]]
for {
conf <- configurators
clazz <- conf.getComponentInterfaces
} set.add(clazz)
wa.initiate(
new DefaultResourceConfig(set),
new ActorComponentProviderFactory(configurators));
Kernel.boot // will boot if not already booted by 'main'
val configurators = ConfiguratorRepository.getConfiguratorsFor(getServletContext)
rc.getClasses.addAll(configurators.flatMap(_.getComponentInterfaces))
rc.getProperties.put("com.sun.jersey.spi.container.ResourceFilters","org.atmosphere.core.AtmosphereFilter")
//rc.getFeatures.put("com.sun.jersey.config.feature.Redirect", true)
//rc.getFeatures.put("com.sun.jersey.config.feature.ImplicitViewables",true)
wa.initiate(rc,new ActorComponentProviderFactory(configurators))
}
//Borrowed from AbstractReflectorAtmosphereHandler
override def onMessage(event : AtmosphereEvent[HttpServletRequest,HttpServletResponse]) : AtmosphereEvent[_,_] =
{
//log.info("onMessage: " + event.getMessage.toString)
if(event.getMessage ne null)
{
var isUsingStream = false
try {
event.getResponse.getWriter
} catch {
case e: IllegalStateException => isUsingStream = true
}
val data = event.getMessage.toString
if (isUsingStream){
if(data != null)
event.getResponse.getOutputStream.write(data.getBytes)
event.getResponse.getOutputStream.flush
} else {
event.getResponse.getWriter.write(data)
event.getResponse.getWriter.flush
}
}
else
log.info("Null event message :/ req[ " + event.getRequest + "] res[" +event.getResponse + "]")
event
}
override def onEvent(event : AtmosphereEvent[HttpServletRequest,HttpServletResponse]) : AtmosphereEvent[_,_] =
{
//log.info("onEvent: " + event.getMessage)
event.getRequest.setAttribute(ReflectorServletProcessor.ATMOSPHERE_EVENT, event)
event.getRequest.setAttribute(ReflectorServletProcessor.ATMOSPHERE_HANDLER, this)
service(event.getRequest, event.getResponse)
event
}
}
class AkkaCometServlet extends org.atmosphere.cpr.AtmosphereServlet
{
override def init(sconf : ServletConfig) = {
val servlet = new AkkaServlet
this.config = new AtmosphereConfig { ah = servlet }
atmosphereHandlers.put("", new AtmosphereHandlerWrapper(servlet,new JerseyBroadcaster))
setCometSupport(new GrizzlyCometSupport(config))
getCometSupport.init(sconf)
servlet.init(sconf)
}
override def loadAtmosphereDotXml(is : InputStream, urlc :URLClassLoader) = () //Hide it
}

BIN
lib/akka-kernel-0.5.jar Normal file

Binary file not shown.

BIN
lib/akka-util-java-0.5.jar Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
lib/fscontext.jar Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
lib/providerutil.jar Normal file

Binary file not shown.

View file

@ -1,23 +1,33 @@
package sample.scala
import javax.ws.rs.{Path, GET, Produces}
import javax.ws.rs.{GET, POST, Path, Produces, WebApplicationException, Consumes}
import se.scalablesolutions.akka.kernel.state.{TransactionalState, TransactionalMap, CassandraStorageConfig}
import se.scalablesolutions.akka.kernel.actor.{Supervisor, SupervisorFactory, Actor, StartSupervisor}
import se.scalablesolutions.akka.kernel.config.ScalaConfig._
import javax.ws.rs.core.MultivaluedMap
import _root_.scala.xml.{NodeSeq}
import se.scalablesolutions.akka.kernel.util.{Logging}
import org.atmosphere.core.annotation.{Broadcast, BroadcastFilter => FilterBroadcast, Suspend}
import org.atmosphere.util.{XSSHtmlFilter}
import org.atmosphere.cpr.{BroadcastFilter}
class Boot {
object factory extends SupervisorFactory {
override def getSupervisorConfig: SupervisorConfig = {
SupervisorConfig(
RestartStrategy(OneForOne, 3, 100),
Supervise(
new SimpleService,
LifeCycle(Permanent, 100))
:: Nil)
object factory extends SupervisorFactory {
override def getSupervisorConfig: SupervisorConfig = {
SupervisorConfig(
RestartStrategy(OneForOne, 3, 100),
Supervise(
new Chat,
LifeCycle(Permanent, 100))
:: Nil)
}
}
}
val supervisor = factory.newSupervisor
supervisor.startSupervisor
val supervisor = factory.newSupervisor
supervisor.startSupervisor
}
/**
@ -29,33 +39,96 @@ class Boot {
*/
@Path("/scalacount")
class SimpleService extends Actor {
uuid = "SimpleService"
makeTransactionRequired
uuid = "SimpleService"
makeTransactionRequired
case object Tick
private val KEY = "COUNTER";
private var hasStartedTicking = false;
private val storage = TransactionalState.newPersistentMap(CassandraStorageConfig())
case object Tick
private val KEY = "COUNTER";
private var hasStartedTicking = false;
private val storage = TransactionalState.newPersistentMap(CassandraStorageConfig())
@GET
@Produces(Array("application/json"))
def count = (this !! Tick).getOrElse("Error in counter")
override def receive: PartialFunction[Any, Unit] = {
case Tick => if (hasStartedTicking) {
val counter = storage.get(KEY).get.asInstanceOf[Integer].intValue
storage.put(KEY, new Integer(counter + 1))
//reply(<h1>Tick: { counter + 1 } </h1>)
reply("Tick: " + (counter + 1) + "\n")
} else {
storage.put(KEY, new Integer(0))
hasStartedTicking = true
//reply(<h1>Tick: 0</h1>)
reply("Tick: 0\n")
@GET
@Produces(Array("text/html"))
def count() = {
(this !! Tick).getOrElse(<error>Error in counter</error>)
}
}
override protected def postRestart(reason: AnyRef, config: Option[AnyRef]) = {
println("Restarting due to: " + reason.asInstanceOf[Exception].getMessage)
}
override def receive: PartialFunction[Any, Unit] = {
case Tick => if (hasStartedTicking) {
val counter = storage.get(KEY).get.asInstanceOf[Integer].intValue
storage.put(KEY, new Integer(counter + 1))
reply(<success>Tick: {counter + 1}</success>)
} else {
storage.put(KEY, new Integer(0))
hasStartedTicking = true
reply(<success>Tick: 0</success>)
}
}
override protected def postRestart(reason: AnyRef, config: Option[AnyRef]) = {
println("Restarting due to: " + reason.asInstanceOf[Exception].getMessage)
}
}
@Path("/chat")
class Chat extends Actor with Logging{
uuid = "Chat"
makeTransactionRequired
case class Chat(val who : String, val what : String,val msg : String)
override protected def postRestart(reason: AnyRef, config: Option[AnyRef]) = {
println("Restarting due to: " + reason.asInstanceOf[Exception].getMessage)
}
@Suspend
@GET
@Produces(Array("text/html"))
def suspend() = "<!-- Comet is a programming technique that enables web " +
"servers to send data to the client without having any need " +
"for the client to request it. -->\n"
override def receive: PartialFunction[Any, Unit] = {
case Chat(who,what,msg) => {
//log.info("Chat(" + who + ", " + what + ", " + msg + ")")
what match {
case "login" => reply("System Message__"+who+" has joined.")
case "post" => reply("" + who + "__" + msg)
case _ => throw new WebApplicationException(422)
}
}
case x => log.info("recieve unknown: " + x)
}
@Broadcast
@Consumes(Array("application/x-www-form-urlencoded"))
@POST
@Produces(Array("text/html"))
@FilterBroadcast(Array(classOf[XSSHtmlFilter],classOf[JsonpFilter]))
def publishMessage(form: MultivaluedMap[String, String]) = (this !! Chat(form.getFirst("name"),form.getFirst("action"),form.getFirst("message"))).getOrElse("System__error")
}
class JsonpFilter extends BroadcastFilter[String] with Logging
{
val BEGIN_SCRIPT_TAG = "<script type='text/javascript'>\n"
val END_SCRIPT_TAG = "</script>\n"
def filter(m : String) = {
var name = m
var message = ""
if (m.indexOf("__") > 0) {
name = m.substring(0, m.indexOf("__"))
message = m.substring(m.indexOf("__") + 2)
}
(BEGIN_SCRIPT_TAG + "window.parent.app.update({ name: \""
+ name + "\", message: \""
+ message + "\" });\n"
+ END_SCRIPT_TAG)
}
}