created persistent and in-memory versions of all samples
This commit is contained in:
parent
931b1c75a5
commit
deeaa923d1
14 changed files with 593 additions and 185 deletions
|
|
@ -28,6 +28,11 @@
|
|||
<orderEntry type="library" exported="" name="Maven: asm:asm:3.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="Maven: aopalliance:aopalliance:1.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="Maven: org.apache.camel:camel-core:2.0-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" exported="" name="Maven: commons-logging:commons-logging-api:1.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="Maven: javax.xml.bind:jaxb-api:2.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="Maven: javax.xml.stream:stax-api:1.0-2" level="project" />
|
||||
<orderEntry type="library" exported="" name="Maven: javax.activation:activation:1.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="Maven: com.sun.xml.bind:jaxb-impl:2.1.6" level="project" />
|
||||
<orderEntry type="library" exported="" name="Maven: org.jboss.netty:netty:3.1.0.GA" level="project" />
|
||||
<orderEntry type="library" exported="" name="Maven: org.apache:zookeeper:3.1.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="Maven: org.scala-tools:javautils:2.7.4-0.1" level="project" />
|
||||
|
|
@ -35,6 +40,9 @@
|
|||
<orderEntry type="library" exported="" name="Maven: org.codehaus.jackson:jackson-mapper-asl:1.1.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="Maven: sbinary:sbinary:0.3" level="project" />
|
||||
<orderEntry type="library" exported="" name="Maven: com.twitter:scala-json:1.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="Maven: dispatch.json:dispatch-json:0.5.2" level="project" />
|
||||
<orderEntry type="library" exported="" name="Maven: dispatch.http:dispatch-http:0.5.2" level="project" />
|
||||
<orderEntry type="library" exported="" name="Maven: sjson.json:sjson:0.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="Maven: com.mongodb:mongo:0.6" level="project" />
|
||||
<orderEntry type="library" exported="" name="Maven: org.apache.cassandra:cassandra:0.4.0-trunk" level="project" />
|
||||
<orderEntry type="library" exported="" name="Maven: com.facebook:thrift:1.0" level="project" />
|
||||
|
|
@ -56,10 +64,6 @@
|
|||
<orderEntry type="library" exported="" name="Maven: com.sun.jersey:jersey-json:1.1.1-ea" level="project" />
|
||||
<orderEntry type="library" exported="" name="Maven: org.codehaus.jettison:jettison:1.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="Maven: stax:stax-api:1.0.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="Maven: com.sun.xml.bind:jaxb-impl:2.1.12" level="project" />
|
||||
<orderEntry type="library" exported="" name="Maven: javax.xml.bind:jaxb-api:2.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="Maven: javax.xml.stream:stax-api:1.0-2" level="project" />
|
||||
<orderEntry type="library" exported="" name="Maven: javax.activation:activation:1.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="Maven: org.codehaus.jackson:jackson-asl:0.9.4" level="project" />
|
||||
<orderEntry type="library" exported="" name="Maven: com.sun.jersey.contribs:jersey-scala:1.1.2-ea-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" exported="" name="Maven: org.atmosphere:atmosphere-core:0.3" level="project" />
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
* <pre>
|
||||
* curl http://localhost:9998/persistentjavacount
|
||||
* </pre>
|
||||
* 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<Object, Object> 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");
|
||||
}
|
||||
}
|
||||
|
|
@ -29,7 +29,7 @@ public class SimpleService {
|
|||
|
||||
private boolean hasStartedTicking = false;
|
||||
private TransactionalState factory = new TransactionalState();
|
||||
private TransactionalMap<Object, Object> storage = factory.newPersistentMap(new CassandraStorageConfig());
|
||||
private TransactionalMap storage = factory.newInMemoryMap();
|
||||
|
||||
@GET
|
||||
@Produces({"application/json"})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue