Added TypedActor and TypedTransactor base classes.

Renamed ActiveObject factory object to TypedActor.
Improved network protocol for TypedActor.
Remote TypedActors now identified by UUID.
This commit is contained in:
Jonas Bonér 2010-07-26 18:47:25 +02:00
parent 20464a3d20
commit e48572f32e
84 changed files with 2278 additions and 1445 deletions

View file

@ -4,11 +4,11 @@
package sample.rest.java;
import se.scalablesolutions.akka.config.ActiveObjectConfigurator;
import se.scalablesolutions.akka.config.TypedActorConfigurator;
import static se.scalablesolutions.akka.config.JavaConfig.*;
public class Boot {
public final static ActiveObjectConfigurator configurator = new ActiveObjectConfigurator();
public final static TypedActorConfigurator configurator = new TypedActorConfigurator();
static {
configurator.configure(
new RestartStrategy(new OneForOne(), 3, 5000, new Class[]{Exception.class}),

View file

@ -4,42 +4,6 @@
package sample.rest.java;
import se.scalablesolutions.akka.actor.annotation.transactionrequired;
import se.scalablesolutions.akka.actor.annotation.prerestart;
import se.scalablesolutions.akka.actor.annotation.postrestart;
import se.scalablesolutions.akka.persistence.common.PersistentMap;
import se.scalablesolutions.akka.persistence.cassandra.CassandraStorage;
import java.nio.ByteBuffer;
@transactionrequired
public class PersistentSimpleService {
private String KEY = "COUNTER";
private boolean hasStartedTicking = false;
private PersistentMap<byte[], byte[]> storage;
public String count() {
if (storage == null) storage = CassandraStorage.newMap();
if (!hasStartedTicking) {
storage.put(KEY.getBytes(), ByteBuffer.allocate(4).putInt(0).array());
hasStartedTicking = true;
return "Tick: 0\n";
} else {
byte[] bytes = (byte[])storage.get(KEY.getBytes()).get();
int counter = ByteBuffer.wrap(bytes).getInt();
storage.put(KEY.getBytes(), ByteBuffer.allocate(4).putInt(counter + 1).array());
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");
}
public interface PersistentSimpleService {
public String count();
}

View file

@ -0,0 +1,42 @@
/**
* Copyright (C) 2009-2010 Scalable Solutions AB <http://scalablesolutions.se>
*/
package sample.rest.java;
import se.scalablesolutions.akka.actor.TypedTransactor;
import se.scalablesolutions.akka.persistence.common.PersistentMap;
import se.scalablesolutions.akka.persistence.cassandra.CassandraStorage;
import java.nio.ByteBuffer;
public class PersistentSimpleServiceImpl extends TypedTransactor implements PersistentSimpleService {
private String KEY = "COUNTER";
private boolean hasStartedTicking = false;
private PersistentMap<byte[], byte[]> storage;
public String count() {
if (storage == null) storage = CassandraStorage.newMap();
if (!hasStartedTicking) {
storage.put(KEY.getBytes(), ByteBuffer.allocate(4).putInt(0).array());
hasStartedTicking = true;
return "Tick: 0\n";
} else {
byte[] bytes = (byte[])storage.get(KEY.getBytes()).get();
int counter = ByteBuffer.wrap(bytes).getInt();
storage.put(KEY.getBytes(), ByteBuffer.allocate(4).putInt(counter + 1).array());
return "Tick: " + counter + "\n";
}
}
@Override
public void preRestart(Throwable cause) {
System.out.println("Prepare for restart by supervisor");
}
@Override
public void postRestart(Throwable cause) {
System.out.println("Reinitialize after restart by supervisor");
}
}

View file

@ -4,17 +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;
public class Receiver {
private ActiveObjectContext context = null;
public SimpleService receive() {
System.out.println("------ RECEIVE");
return (SimpleService) context.getSender();
}
public interface Receiver {
SimpleService receive();
}

View file

@ -0,0 +1,14 @@
/**
* Copyright (C) 2009-2010 Scalable Solutions AB <http://scalablesolutions.se>
*/
package sample.rest.java;
import se.scalablesolutions.akka.actor.TypedActorContext;
import se.scalablesolutions.akka.actor.TypedActor;
public class ReceiverImpl extends TypedActor implements Receiver {
public SimpleService receive() {
return (SimpleService) getContext().getSender();
}
}

View file

@ -4,43 +4,6 @@
package sample.rest.java;
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;
import se.scalablesolutions.akka.stm.TransactionalMap;
@transactionrequired
public class SimpleService {
private String KEY = "COUNTER";
private boolean hasStartedTicking = false;
private TransactionalMap<String, Integer> storage;
private Receiver receiver = ActiveObject.newInstance(Receiver.class);
public String count() {
if (storage == null) storage = new TransactionalMap<String, Integer>();
if (!hasStartedTicking) {
storage.put(KEY, 0);
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";
}
}
@prerestart
public void preRestart() {
System.out.println("Prepare for restart by supervisor");
}
@postrestart
public void postRestart() {
System.out.println("Reinitialize after restart by supervisor");
}
public interface SimpleService {
public String count();
}

View file

@ -0,0 +1,43 @@
/**
* Copyright (C) 2009-2010 Scalable Solutions AB <http://scalablesolutions.se>
*/
package sample.rest.java;
import se.scalablesolutions.akka.actor.TypedActor;
import se.scalablesolutions.akka.actor.TypedTransactor;
import se.scalablesolutions.akka.actor.TypedActorContext;
import se.scalablesolutions.akka.stm.TransactionalMap;
public class SimpleServiceImpl extends TypedTransactor implements SimpleService {
private String KEY = "COUNTER";
private boolean hasStartedTicking = false;
private TransactionalMap<String, Integer> storage;
private Receiver receiver = TypedActor.newInstance(Receiver.class, ReceiverImpl.class);
public String count() {
if (storage == null) storage = new TransactionalMap<String, Integer>();
if (!hasStartedTicking) {
storage.put(KEY, 0);
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";
}
}
@Override
public void preRestart(Throwable cause) {
System.out.println("Prepare for restart by supervisor");
}
@Override
public void postRestart(Throwable cause) {
System.out.println("Reinitialize after restart by supervisor");
}
}