Update java-friendly api for scala stm
- move to japi.Stm - add newMap, newSet, newList methods with java conversions - add afterCompletion lifecycle callback
This commit is contained in:
parent
2058765485
commit
27da7c4d12
7 changed files with 75 additions and 47 deletions
|
|
@ -8,10 +8,10 @@ package akka.docs.transactor;
|
|||
import akka.actor.*;
|
||||
import akka.transactor.*;
|
||||
import scala.concurrent.stm.Ref;
|
||||
import static scala.concurrent.stm.JavaAPI.*;
|
||||
import scala.concurrent.stm.japi.Stm;
|
||||
|
||||
public class CoordinatedCounter extends UntypedActor {
|
||||
private Ref.View<Integer> count = newRef(0);
|
||||
private Ref.View<Integer> count = Stm.newRef(0);
|
||||
|
||||
public void onReceive(Object incoming) throws Exception {
|
||||
if (incoming instanceof Coordinated) {
|
||||
|
|
@ -24,7 +24,7 @@ public class CoordinatedCounter extends UntypedActor {
|
|||
}
|
||||
coordinated.atomic(new Runnable() {
|
||||
public void run() {
|
||||
increment(count, 1);
|
||||
Stm.increment(count, 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,14 +7,14 @@ package akka.docs.transactor;
|
|||
//#class
|
||||
import akka.transactor.*;
|
||||
import scala.concurrent.stm.Ref;
|
||||
import static scala.concurrent.stm.JavaAPI.*;
|
||||
import scala.concurrent.stm.japi.Stm;
|
||||
|
||||
public class Counter extends UntypedTransactor {
|
||||
Ref.View<Integer> count = newRef(0);
|
||||
Ref.View<Integer> count = Stm.newRef(0);
|
||||
|
||||
public void atomically(Object message) {
|
||||
if (message instanceof Increment) {
|
||||
increment(count, 1);
|
||||
Stm.increment(count, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,10 +9,10 @@ import akka.actor.*;
|
|||
import akka.transactor.*;
|
||||
import java.util.Set;
|
||||
import scala.concurrent.stm.Ref;
|
||||
import static scala.concurrent.stm.JavaAPI.*;
|
||||
import scala.concurrent.stm.japi.Stm;
|
||||
|
||||
public class FriendlyCounter extends UntypedTransactor {
|
||||
Ref.View<Integer> count = newRef(0);
|
||||
Ref.View<Integer> count = Stm.newRef(0);
|
||||
|
||||
@Override public Set<SendTo> coordinate(Object message) {
|
||||
if (message instanceof Increment) {
|
||||
|
|
@ -25,7 +25,7 @@ public class FriendlyCounter extends UntypedTransactor {
|
|||
|
||||
public void atomically(Object message) {
|
||||
if (message instanceof Increment) {
|
||||
increment(count, 1);
|
||||
Stm.increment(count, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue