Fixed issue with sender reference in Active Objects
This commit is contained in:
parent
87276a4938
commit
61a7cdf9d5
16 changed files with 127 additions and 91 deletions
|
|
@ -0,0 +1,20 @@
|
|||
/**
|
||||
* 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;
|
||||
|
||||
import se.scalablesolutions.akka.actor.ActiveObject;
|
||||
import se.scalablesolutions.akka.actor.ActiveObjectContext;
|
||||
|
||||
public class Receiver {
|
||||
private ActiveObjectContext context = null;
|
||||
public SimpleService receive() {
|
||||
System.out.println("------ RECEIVE");
|
||||
return (SimpleService) context.getSender();
|
||||
}
|
||||
}
|
||||
|
|
@ -8,6 +8,8 @@ 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;
|
||||
import se.scalablesolutions.akka.actor.annotation.prerestart;
|
||||
import se.scalablesolutions.akka.actor.annotation.postrestart;
|
||||
|
|
@ -28,7 +30,8 @@ public class SimpleService {
|
|||
|
||||
private boolean hasStartedTicking = false;
|
||||
private TransactionalMap<String, Integer> storage;
|
||||
|
||||
private Receiver receiver = ActiveObject.newInstance(Receiver.class);
|
||||
|
||||
@GET
|
||||
@Produces({"application/json"})
|
||||
public String count() {
|
||||
|
|
@ -38,6 +41,8 @@ public class SimpleService {
|
|||
hasStartedTicking = true;
|
||||
return "Tick: 0\n";
|
||||
} else {
|
||||
// Grabs the sender address and returns it
|
||||
//SimpleService sender = receiver.receive();
|
||||
int counter = (Integer)storage.get(KEY).get() + 1;
|
||||
storage.put(KEY, counter);
|
||||
return "Tick: " + counter + "\n";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue