Update to new Java API for Scala STM
This commit is contained in:
parent
158bbabb58
commit
2757869c62
12 changed files with 61 additions and 129 deletions
|
|
@ -6,21 +6,21 @@ package akka.docs.transactor;
|
|||
|
||||
//#class
|
||||
import akka.transactor.*;
|
||||
import scala.concurrent.stm.*;
|
||||
import scala.concurrent.stm.Ref;
|
||||
import static scala.concurrent.stm.JavaAPI.*;
|
||||
|
||||
public class Counter extends UntypedTransactor {
|
||||
Ref<Integer> count = Stm.ref(0);
|
||||
Ref.View<Integer> count = newRef(0);
|
||||
|
||||
public void atomically(InTxn txn, Object message) {
|
||||
public void atomically(Object message) {
|
||||
if (message instanceof Increment) {
|
||||
Integer newValue = count.get(txn) + 1;
|
||||
count.set(newValue, txn);
|
||||
increment(count, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public boolean normally(Object message) {
|
||||
if ("GetCount".equals(message)) {
|
||||
getSender().tell(count.single().get());
|
||||
getSender().tell(count.get());
|
||||
return true;
|
||||
} else return false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue