Refactored Java REST example to work with the new way of doing REST in Akka
This commit is contained in:
parent
a6edff9375
commit
3ad111876a
6 changed files with 63 additions and 34 deletions
|
|
@ -1,13 +1,16 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2010 Scalable Solutions AB <http://scalablesolutions.se>
|
||||
*/
|
||||
|
||||
package sample.rest.java;
|
||||
|
||||
import se.scalablesolutions.akka.config.ActiveObjectConfigurator;
|
||||
import static se.scalablesolutions.akka.config.JavaConfig.*;
|
||||
|
||||
public class Boot {
|
||||
final private ActiveObjectConfigurator manager = new ActiveObjectConfigurator();
|
||||
|
||||
public Boot() throws Exception {
|
||||
manager.configure(
|
||||
public final static ActiveObjectConfigurator configurator = new ActiveObjectConfigurator();
|
||||
static {
|
||||
configurator.configure(
|
||||
new RestartStrategy(new OneForOne(), 3, 5000, new Class[]{Exception.class}),
|
||||
new Component[] {
|
||||
new Component(
|
||||
|
|
@ -19,5 +22,5 @@ public class Boot {
|
|||
new LifeCycle(new Permanent()),
|
||||
1000)
|
||||
}).supervise();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,10 +4,6 @@
|
|||
|
||||
package sample.rest.java;
|
||||
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Produces;
|
||||
|
||||
import se.scalablesolutions.akka.actor.annotation.transactionrequired;
|
||||
import se.scalablesolutions.akka.actor.annotation.prerestart;
|
||||
import se.scalablesolutions.akka.actor.annotation.postrestart;
|
||||
|
|
@ -16,14 +12,6 @@ import se.scalablesolutions.akka.persistence.cassandra.CassandraStorage;
|
|||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* 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";
|
||||
|
|
@ -31,8 +19,6 @@ public class PersistentSimpleService {
|
|||
private boolean hasStartedTicking = false;
|
||||
private PersistentMap<byte[], byte[]> storage;
|
||||
|
||||
@GET
|
||||
@Produces({"application/html"})
|
||||
public String count() {
|
||||
if (storage == null) storage = CassandraStorage.newMap();
|
||||
if (!hasStartedTicking) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2010 Scalable Solutions AB <http://scalablesolutions.se>
|
||||
*/
|
||||
|
||||
package sample.rest.java;
|
||||
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Produces;
|
||||
|
||||
/**
|
||||
* 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")
|
||||
public class PersistentSimpleServiceRest {
|
||||
private PersistentSimpleService service = (PersistentSimpleService) Boot.configurator.getInstance(PersistentSimpleService.class);
|
||||
|
||||
@GET
|
||||
@Produces({"application/json"})
|
||||
public String count() {
|
||||
return service.count();
|
||||
}
|
||||
}
|
||||
|
|
@ -4,10 +4,6 @@
|
|||
|
||||
package sample.rest.java;
|
||||
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Produces;
|
||||
|
||||
import se.scalablesolutions.akka.actor.ActiveObject;
|
||||
import se.scalablesolutions.akka.actor.ActiveObjectContext;
|
||||
import se.scalablesolutions.akka.actor.annotation.transactionrequired;
|
||||
|
|
@ -16,14 +12,6 @@ import se.scalablesolutions.akka.actor.annotation.postrestart;
|
|||
import se.scalablesolutions.akka.stm.TransactionalState;
|
||||
import se.scalablesolutions.akka.stm.TransactionalMap;
|
||||
|
||||
/**
|
||||
* Try service out by invoking (multiple times):
|
||||
* <pre>
|
||||
* curl http://localhost:9998/javacount
|
||||
* </pre>
|
||||
* Or browse to the URL from a web browser.
|
||||
*/
|
||||
@Path("/javacount")
|
||||
@transactionrequired
|
||||
public class SimpleService {
|
||||
private String KEY = "COUNTER";
|
||||
|
|
@ -32,8 +20,6 @@ public class SimpleService {
|
|||
private TransactionalMap<String, Integer> storage;
|
||||
private Receiver receiver = ActiveObject.newInstance(Receiver.class);
|
||||
|
||||
@GET
|
||||
@Produces({"application/json"})
|
||||
public String count() {
|
||||
if (storage == null) storage = TransactionalState.newMap();
|
||||
if (!hasStartedTicking) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2010 Scalable Solutions AB <http://scalablesolutions.se>
|
||||
*/
|
||||
|
||||
package sample.rest.java;
|
||||
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Produces;
|
||||
|
||||
/**
|
||||
* Try service out by invoking (multiple times):
|
||||
* <pre>
|
||||
* curl http://localhost:9998/javacount
|
||||
* </pre>
|
||||
* Or browse to the URL from a web browser.
|
||||
*/
|
||||
@Path("/javacount")
|
||||
public class SimpleServiceRest {
|
||||
private SimpleService service = (SimpleService) Boot.configurator.getInstance(SimpleService.class);
|
||||
|
||||
@GET
|
||||
@Produces({"application/json"})
|
||||
public String count() {
|
||||
return service.count();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue