diff --git a/config/akka-reference.conf b/config/akka-reference.conf new file mode 100644 index 0000000000..bb819f38b4 --- /dev/null +++ b/config/akka-reference.conf @@ -0,0 +1,67 @@ +################################# +# Akka Actor Kernel Config File # +################################# + +# This file has all the default settings, so all these could be remove with no visible effect. +# Modify as needed. + + + filename = "./logs/akka.log" + roll = "daily" # Options: never, hourly, daily, sunday/monday/... + level = "debug" # Options: fatal, critical, error, warning, info, debug, trace + console = on + # syslog_host = "" + # syslog_server_name = "" + + + + version = "v0.5" + + boot = ["sample.java.Boot", "sample.scala.Boot"] # FQN to the class doing initial active object/actor + # supervisor bootstrap, should be defined in default constructor + + timeout = 5000 # default timeout for future based invocations + concurrent-mode = off # if turned on, then the same actor instance is allowed to execute concurrently - + # e.g. departing from the actor model for better performance + serialize-messages = on # does a deep clone of (non-primitive) messages to ensure immutability + + + + service = on + restart-on-collision = off # (not implemented yet) if 'on' then it reschedules the transaction, + # if 'off' then throws an exception or rollback for user to handle + wait-for-completion = 100 # how long time in millis a transaction should be given time to complete when a collision is detected + wait-nr-of-times = 3 # the number of times it should check for completion of a pending transaction upon collision + distributed = off # not implemented yet + + + + service = on + protocol = "serialization" # Options: serialization (coming: json, avro, thrift, protobuf) + hostname = "localhost" + port = 9999 + connection-timeout = 1000 # in millis + + + + service = on + hostname = "localhost" + port = 9998 + + + + system = "cassandra" # Options: cassandra (coming: terracotta, redis, tokyo-cabinet, tokyo-tyrant, voldemort, memcached, hazelcast) + + + service = on + storage-format = "serialization" # Options: serialization (coming: json, avro, thrift, protobuf) + blocking = false # inserts and queries should be blocking or not + + + service = on + pidfile = "akka.pid" + + + + + diff --git a/config/akka.conf b/config/akka.conf new file mode 100644 index 0000000000..049e60d6d6 --- /dev/null +++ b/config/akka.conf @@ -0,0 +1,5 @@ +include "akka-reference.conf" + +# This config import the Akka reference configuration. +# In this file you can override any option defined in the 'akka-reference.conf' file. + diff --git a/config/web.xml b/config/web.xml new file mode 100644 index 0000000000..f49e728729 --- /dev/null +++ b/config/web.xml @@ -0,0 +1,10 @@ + + + Akka Servlet + se.scalablesolutions.akka.kernel.jersey.AkkaServlet + + + Akka Servlet + /* + + diff --git a/lib/akka-kernel-0.5.jar b/lib/akka-kernel-0.5.jar new file mode 100644 index 0000000000..bd48a71245 Binary files /dev/null and b/lib/akka-kernel-0.5.jar differ diff --git a/lib/akka-util-java-0.5.jar b/lib/akka-util-java-0.5.jar new file mode 100644 index 0000000000..a13f729b26 Binary files /dev/null and b/lib/akka-util-java-0.5.jar differ diff --git a/lib/jackson-core-asl-1.1.0.jar b/lib/jackson-core-asl-1.1.0.jar new file mode 100644 index 0000000000..6b561dd2be Binary files /dev/null and b/lib/jackson-core-asl-1.1.0.jar differ diff --git a/lib/jackson-mapper-asl-1.1.0.jar b/lib/jackson-mapper-asl-1.1.0.jar new file mode 100644 index 0000000000..1b37ad3772 Binary files /dev/null and b/lib/jackson-mapper-asl-1.1.0.jar differ diff --git a/lib/jersey-core-1.0.3.jar b/lib/jersey-core-1.0.3.jar new file mode 100644 index 0000000000..bd6bedeb2e Binary files /dev/null and b/lib/jersey-core-1.0.3.jar differ diff --git a/lib/jersey-json-1.0.3.jar b/lib/jersey-json-1.0.3.jar new file mode 100644 index 0000000000..c9af8ec7b4 Binary files /dev/null and b/lib/jersey-json-1.0.3.jar differ diff --git a/lib/jersey-server-1.0.3.jar b/lib/jersey-server-1.0.3.jar new file mode 100644 index 0000000000..d5d41a18d6 Binary files /dev/null and b/lib/jersey-server-1.0.3.jar differ diff --git a/samples-java/akka-samples-java.iml b/samples-java/akka-samples-java.iml new file mode 100644 index 0000000000..70346dd5b7 --- /dev/null +++ b/samples-java/akka-samples-java.iml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/samples-java/pom.xml b/samples-java/pom.xml new file mode 100644 index 0000000000..7c6186db3e --- /dev/null +++ b/samples-java/pom.xml @@ -0,0 +1,67 @@ + + 4.0.0 + + akka-samples-java + Akka Java Samples Module + + jar + + + akka + ${akka.groupId} + ${akka.version} + + + + + ${akka.groupId} + akka-kernel + ${akka.version} + + + ${akka.groupId} + akka-util-java + ${akka.version} + + + javax.ws.rs + jsr311-api + 1.0 + + + + + src/main/java + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.5 + 1.5 + + **/* + + + + + maven-antrun-plugin + + + install + + + + + + + run + + + + + + + diff --git a/samples-java/src/main/java/sample/java/SimpleService.java b/samples-java/src/main/java/sample/java/SimpleService.java new file mode 100644 index 0000000000..55b14938e3 --- /dev/null +++ b/samples-java/src/main/java/sample/java/SimpleService.java @@ -0,0 +1,53 @@ +package sample.java; + +import javax.ws.rs.Path; +import javax.ws.rs.GET; +import javax.ws.rs.Produces; + +import se.scalablesolutions.akka.annotation.transactionrequired; +import se.scalablesolutions.akka.annotation.prerestart; +import se.scalablesolutions.akka.annotation.postrestart; +import se.scalablesolutions.akka.kernel.state.TransactionalState; +import se.scalablesolutions.akka.kernel.state.TransactionalMap; +import se.scalablesolutions.akka.kernel.state.CassandraStorageConfig; + +/** + * Try service out by invoking (multiple times): + *
+ * curl http://localhost:9998/javacount
+ * 
+ * Or browse to the URL from a web browser. + */ +@Path("/javacount") +@transactionrequired +public class SimpleService { + private String KEY = "COUNTER"; + + private boolean hasStartedTicking = false; + private TransactionalState factory = new TransactionalState(); + private TransactionalMap storage = factory.newPersistentMap(new CassandraStorageConfig()); + + @GET + @Produces({"application/json"}) + public String count() { + if (!hasStartedTicking) { + storage.put(KEY, 0); + hasStartedTicking = true; + return "Tick: 0\n"; + } else { + int counter = (Integer)storage.get(KEY).get() + 1; + storage.put(KEY, counter); + return "Tick: " + counter + "\n"; + } + } + + @prerestart + public void preRestart() { + System.out.println("Prepare for restart by supervisor"); + } + + @postrestart + public void postRestart() { + System.out.println("Reinitialize after restart by supervisor"); + } +} \ No newline at end of file diff --git a/samples-scala/akka-samples-scala.iml b/samples-scala/akka-samples-scala.iml new file mode 100644 index 0000000000..fa56a89054 --- /dev/null +++ b/samples-scala/akka-samples-scala.iml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/samples-scala/pom.xml b/samples-scala/pom.xml new file mode 100644 index 0000000000..d6e6813bbe --- /dev/null +++ b/samples-scala/pom.xml @@ -0,0 +1,118 @@ + + 4.0.0 + + akka-samples-scala + Akka Scala Samples Module + + jar + + + akka + ${akka.groupId} + ${akka.version} + + + + + ${akka.groupId} + akka-kernel + ${akka.version} + + + ${akka.groupId} + akka-util-java + ${akka.version} + + + javax.ws.rs + jsr311-api + 1.0 + + + + + src/main/scala + src/test/scala + + + org.scala-tools + maven-scala-plugin + + + + compile + testCompile + + + + + + -target:jvm-1.5 + -unchecked + + ${scala.version} + 1.1 + + + + org.apache.maven.plugins + maven-eclipse-plugin + + true + + + ch.epfl.lamp.sdt.core.scalabuilder + + + + + ch.epfl.lamp.sdt.core.scalanature + + + + + org.eclipse.jdt.launching.JRE_CONTAINER + + + ch.epfl.lamp.sdt.launching.SCALA_CONTAINER + + + + + + maven-antrun-plugin + + + install + + + + + + + run + + + + + + + + false + src/main/resources + + + false + src/main/scala + + ** + + + **/*.scala + + + + + diff --git a/samples-scala/src/main/scala/SimpleService.scala b/samples-scala/src/main/scala/SimpleService.scala new file mode 100644 index 0000000000..b29dbef6ec --- /dev/null +++ b/samples-scala/src/main/scala/SimpleService.scala @@ -0,0 +1,61 @@ +package sample.scala + +import javax.ws.rs.{Path, GET, Produces} +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._ + +class Boot { + object factory extends SupervisorFactory { + override def getSupervisorConfig: SupervisorConfig = { + SupervisorConfig( + RestartStrategy(OneForOne, 3, 100), + Supervise( + new SimpleService, + LifeCycle(Permanent, 100)) + :: Nil) + } + } + val supervisor = factory.newSupervisor + supervisor.startSupervisor +} + +/** + * Try service out by invoking (multiple times): + *
+ * curl http://localhost:9998/scalacount
+ * 
+ * Or browse to the URL from a web browser. + */ +@Path("/scalacount") +class SimpleService extends Actor { + uuid = "SimpleService" + makeTransactionRequired + + 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(

Tick: { counter + 1 }

) + reply("Tick: " + (counter + 1) + "\n") + } else { + storage.put(KEY, new Integer(0)) + hasStartedTicking = true + //reply(

Tick: 0

) + reply("Tick: 0\n") + } + } + + override protected def postRestart(reason: AnyRef, config: Option[AnyRef]) = { + println("Restarting due to: " + reason.asInstanceOf[Exception].getMessage) + } +} \ No newline at end of file