diff --git a/akka-amqp/src/main/scala/AMQP.scala b/akka-amqp/src/main/scala/AMQP.scala index a45472ea12..faf271059c 100644 --- a/akka-amqp/src/main/scala/AMQP.scala +++ b/akka-amqp/src/main/scala/AMQP.scala @@ -102,6 +102,13 @@ object ExampleAMQPSession { val PORT = 8787 val SERIALIZER = Serializer.Java + val messageConsumer = new Actor() { + def receive: PartialFunction[Any, Unit] = { + case Message(payload) => println("Received message: " + payload) + } + } + messageConsumer.start + val endpoint = new Endpoint(new ConnectionFactory(CONFIG), HOSTNAME, PORT) { override def init(channel: Channel) = { channel.exchangeDeclare(EXCHANGE, "direct") @@ -117,13 +124,6 @@ object ExampleAMQPSession { } endpoint.start - val messageConsumer = new Actor() { - def receive: PartialFunction[Any, Unit] = { - case Message(payload) => println("Received message: " + payload) - } - } - messageConsumer.start - endpoint ! MessageConsumer(messageConsumer) val client = new Client(new ConnectionFactory(CONFIG), HOSTNAME, PORT, EXCHANGE, ROUTING_KEY, SERIALIZER) diff --git a/akka.ipr b/akka.ipr index b5b5f4d0bd..175d776ea3 100644 --- a/akka.ipr +++ b/akka.ipr @@ -1648,116 +1648,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1769,15 +1659,37 @@ - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + diff --git a/akka.iws b/akka.iws index 40e04b3073..9fc47e8b25 100644 --- a/akka.iws +++ b/akka.iws @@ -2,8 +2,19 @@ - + + + + + + + + + + + + @@ -59,24 +70,6 @@ - - - - - - - - - - - - - - - - - - @@ -86,6 +79,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -103,8 +168,14 @@ - + + + + + + + @@ -135,6 +206,230 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -428,20 +723,6 @@ - - - - - - - - - - - - - - @@ -449,6 +730,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/fun-test-java/akka-fun-test-java.iml b/fun-test-java/akka-fun-test-java.iml index 2a4b679a7a..e09beb736b 100644 --- a/fun-test-java/akka-fun-test-java.iml +++ b/fun-test-java/akka-fun-test-java.iml @@ -28,6 +28,11 @@ + + + + + @@ -35,6 +40,9 @@ + + + @@ -55,10 +63,6 @@ - - - - diff --git a/kernel/akka-kernel.iml b/kernel/akka-kernel.iml index 0202664266..807760933a 100644 --- a/kernel/akka-kernel.iml +++ b/kernel/akka-kernel.iml @@ -44,6 +44,11 @@ + + + + + @@ -51,6 +56,9 @@ + + + @@ -72,10 +80,6 @@ - - - - diff --git a/samples-java/akka-samples-java.iml b/samples-java/akka-samples-java.iml index f9e50d1342..97ec95ec37 100644 --- a/samples-java/akka-samples-java.iml +++ b/samples-java/akka-samples-java.iml @@ -28,6 +28,11 @@ + + + + + @@ -35,6 +40,9 @@ + + + @@ -56,10 +64,6 @@ - - - - diff --git a/samples-java/src/main/java/sample/java/Boot.java b/samples-java/src/main/java/sample/java/Boot.java index 9c21f31faf..c4e25e381f 100644 --- a/samples-java/src/main/java/sample/java/Boot.java +++ b/samples-java/src/main/java/sample/java/Boot.java @@ -13,6 +13,10 @@ public class Boot { new Component( sample.java.SimpleService.class, new LifeCycle(new Permanent(), 1000), + 1000), + new Component( + sample.java.PersistentSimpleService.class, + new LifeCycle(new Permanent(), 1000), 1000) }).supervise(); } diff --git a/samples-java/src/main/java/sample/java/PersistentSimpleService.java b/samples-java/src/main/java/sample/java/PersistentSimpleService.java new file mode 100644 index 0000000000..a00b1ab60a --- /dev/null +++ b/samples-java/src/main/java/sample/java/PersistentSimpleService.java @@ -0,0 +1,57 @@ +/** + * Copyright (C) 2009 Scalable Solutions. + */ + +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/persistentjavacount + * + * Or browse to the URL from a web browser. + */ +@Path("/persistentjavacount") +@transactionrequired +public class PersistentSimpleService { + private String KEY = "COUNTER"; + + private boolean hasStartedTicking = false; + private TransactionalState factory = new TransactionalState(); + private TransactionalMap storage = factory.newPersistentMap(new CassandraStorageConfig()); + + @GET + @Produces({"application/html"}) + 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-java/src/main/java/sample/java/SimpleService.java b/samples-java/src/main/java/sample/java/SimpleService.java index 212ca61027..604d3d301d 100644 --- a/samples-java/src/main/java/sample/java/SimpleService.java +++ b/samples-java/src/main/java/sample/java/SimpleService.java @@ -29,7 +29,7 @@ public class SimpleService { private boolean hasStartedTicking = false; private TransactionalState factory = new TransactionalState(); - private TransactionalMap storage = factory.newPersistentMap(new CassandraStorageConfig()); + private TransactionalMap storage = factory.newInMemoryMap(); @GET @Produces({"application/json"}) diff --git a/samples-lift/akka-samples-lift.iml b/samples-lift/akka-samples-lift.iml index bcdecef91a..5b3e6a796f 100644 --- a/samples-lift/akka-samples-lift.iml +++ b/samples-lift/akka-samples-lift.iml @@ -35,6 +35,11 @@ + + + + + @@ -42,6 +47,9 @@ + + + @@ -63,10 +71,6 @@ - - - - diff --git a/samples-lift/src/main/scala/akka/SimpleService.scala b/samples-lift/src/main/scala/akka/SimpleService.scala index f7af8a6ef7..1e951d5c2f 100644 --- a/samples-lift/src/main/scala/akka/SimpleService.scala +++ b/samples-lift/src/main/scala/akka/SimpleService.scala @@ -19,6 +19,39 @@ import javax.ws.rs.{GET, POST, Path, Produces, WebApplicationException, Consumes class SimpleService extends Actor { makeTransactionRequired + case object Tick + private val KEY = "COUNTER"; + private var hasStartedTicking = false; + private val storage = TransactionalState.newInMemoryMap[String, Integer] + + @GET + @Produces(Array("text/html")) + 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}) + } else { + storage.put(KEY, new Integer(0)) + hasStartedTicking = true + reply(Tick: 0) + } + } +} + +/** + * Try service out by invoking (multiple times): + * + * curl http://localhost:9998/persistentliftcount + * + * Or browse to the URL from a web browser. + */ +@Path("/persistentliftcount") +class PersistentSimpleService extends Actor { + makeTransactionRequired + case object Tick private val KEY = "COUNTER"; private var hasStartedTicking = false; diff --git a/samples-lift/src/main/scala/bootstrap/liftweb/Boot.scala b/samples-lift/src/main/scala/bootstrap/liftweb/Boot.scala index 0cf98c8af4..1df1143d38 100644 --- a/samples-lift/src/main/scala/bootstrap/liftweb/Boot.scala +++ b/samples-lift/src/main/scala/bootstrap/liftweb/Boot.scala @@ -40,11 +40,13 @@ class Boot { override def getSupervisorConfig: SupervisorConfig = { SupervisorConfig( RestartStrategy(OneForOne, 3, 100), - Supervise( - new SimpleService, - LifeCycle(Permanent, 100) - ) - :: Nil) + Supervise( + new SimpleService, + LifeCycle(Permanent, 100)) :: + Supervise( + new SimpleService, + LifeCycle(Permanent, 100)) :: + Nil) } } val supervisor = factory.newSupervisor diff --git a/samples-scala/akka-samples-scala.iml b/samples-scala/akka-samples-scala.iml index cea303267e..f88fe93371 100644 --- a/samples-scala/akka-samples-scala.iml +++ b/samples-scala/akka-samples-scala.iml @@ -33,6 +33,11 @@ + + + + + @@ -40,6 +45,9 @@ + + + @@ -61,10 +69,6 @@ - - - - diff --git a/samples-scala/src/main/scala/SimpleService.scala b/samples-scala/src/main/scala/SimpleService.scala index 59d28e52e6..d95bfd7bb7 100644 --- a/samples-scala/src/main/scala/SimpleService.scala +++ b/samples-scala/src/main/scala/SimpleService.scala @@ -24,10 +24,13 @@ class Boot { Supervise( new SimpleService, LifeCycle(Permanent, 100)) :: - Supervise( - new Chat, - LifeCycle(Permanent, 100)) - :: Nil) + Supervise( + new Chat, + LifeCycle(Permanent, 100)) :: + Supervise( + new PersistentSimpleService, + LifeCycle(Permanent, 100)) + :: Nil) } } val supervisor = factory.newSupervisor @@ -45,6 +48,39 @@ class Boot { class SimpleService extends Actor { makeTransactionRequired + case object Tick + private val KEY = "COUNTER"; + private var hasStartedTicking = false; + private val storage = TransactionalState.newInMemoryMap[String, Integer] + + @GET + @Produces(Array("text/html")) + 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}) + } else { + storage.put(KEY, new Integer(0)) + hasStartedTicking = true + reply(Tick: 0) + } + } +} + +/** + * Try service out by invoking (multiple times): + * + * curl http://localhost:9998/persistentscalacount + * + * Or browse to the URL from a web browser. + */ +@Path("/persistentscalacount") +class PersistentSimpleService extends Actor { + makeTransactionRequired + case object Tick private val KEY = "COUNTER"; private var hasStartedTicking = false;
+ * curl http://localhost:9998/persistentjavacount + *
+ * curl http://localhost:9998/persistentliftcount + *
+ * curl http://localhost:9998/persistentscalacount + *