* All default values removed from code and loaded from akka-actor-reference.conf, located in src/main/resources (included in jar) * Default test configuration included in AkkaSpec instead of using akka.test.conf, avoids problems when running test (in IDE) and forgetting to use -Dakka.mode=test. * System.properties used first, if availble * Next step will be to split akka-actor-reference.conf in separate -reference for each module
This commit is contained in:
parent
80d766b07b
commit
4b8f11ea92
137 changed files with 8689 additions and 1411 deletions
|
|
@ -3,48 +3,49 @@ package akka.stm.example;
|
|||
import akka.actor.ActorSystem;
|
||||
import akka.stm.*;
|
||||
import akka.actor.*;
|
||||
import akka.testkit.AkkaSpec;
|
||||
|
||||
public class RetryExample {
|
||||
public static void main(String[] args) {
|
||||
System.out.println();
|
||||
System.out.println("Retry example");
|
||||
System.out.println();
|
||||
public static void main(String[] args) {
|
||||
System.out.println();
|
||||
System.out.println("Retry example");
|
||||
System.out.println();
|
||||
|
||||
ActorSystem application = ActorSystem.create("RetryExample");
|
||||
ActorSystem application = ActorSystem.create("RetryExample", AkkaSpec.testConf());
|
||||
|
||||
final Ref<Double> account1 = new Ref<Double>(100.0);
|
||||
final Ref<Double> account2 = new Ref<Double>(100.0);
|
||||
final Ref<Double> account1 = new Ref<Double>(100.0);
|
||||
final Ref<Double> account2 = new Ref<Double>(100.0);
|
||||
|
||||
ActorRef transferer = application.actorOf(new Props().withCreator(Transferer.class));
|
||||
ActorRef transferer = application.actorOf(new Props().withCreator(Transferer.class));
|
||||
|
||||
transferer.tell(new Transfer(account1, account2, 500.0));
|
||||
// Transferer: not enough money - retrying
|
||||
transferer.tell(new Transfer(account1, account2, 500.0));
|
||||
// Transferer: not enough money - retrying
|
||||
|
||||
new Atomic() {
|
||||
public Object atomically() {
|
||||
return account1.set(account1.get() + 2000);
|
||||
}
|
||||
}.execute();
|
||||
// Transferer: transferring
|
||||
new Atomic() {
|
||||
public Object atomically() {
|
||||
return account1.set(account1.get() + 2000);
|
||||
}
|
||||
}.execute();
|
||||
// Transferer: transferring
|
||||
|
||||
Double acc1 = new Atomic<Double>() {
|
||||
public Double atomically() {
|
||||
return account1.get();
|
||||
}
|
||||
}.execute();
|
||||
Double acc1 = new Atomic<Double>() {
|
||||
public Double atomically() {
|
||||
return account1.get();
|
||||
}
|
||||
}.execute();
|
||||
|
||||
Double acc2 = new Atomic<Double>() {
|
||||
public Double atomically() {
|
||||
return account2.get();
|
||||
}
|
||||
}.execute();
|
||||
Double acc2 = new Atomic<Double>() {
|
||||
public Double atomically() {
|
||||
return account2.get();
|
||||
}
|
||||
}.execute();
|
||||
|
||||
System.out.println("Account 1: " + acc1);
|
||||
// Account 1: 1600.0
|
||||
System.out.println("Account 1: " + acc1);
|
||||
// Account 1: 1600.0
|
||||
|
||||
System.out.println("Account 2: " + acc2);
|
||||
// Account 2: 600.0
|
||||
System.out.println("Account 2: " + acc2);
|
||||
// Account 2: 600.0
|
||||
|
||||
transferer.stop();
|
||||
}
|
||||
transferer.stop();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue