fix Java8 DiningHakkers sample

This commit is contained in:
Roland Kuhn 2015-06-29 20:56:06 +02:00
parent 33bc502c76
commit 039e8261ff

View file

@ -60,6 +60,12 @@ public class DiningHakkersOnBecome {
this.name = name;
this.left = left;
this.right = right;
//All hakkers start in a non-eating state
receive(ReceiveBuilder.matchEquals(Think, m -> {
System.out.println(String.format("%s starts to think", name));
startThinking(Duration.create(5, SECONDS));
}).build());
}
//When a hakker is eating, he can decide to start to think,
@ -124,14 +130,6 @@ public class DiningHakkersOnBecome {
right.tell(new Take(self()), self());
}).build();
//All hakkers start in a non-eating state
public Hakker() {
receive(ReceiveBuilder.matchEquals(Think, m -> {
System.out.println(String.format("%s starts to think", name));
startThinking(Duration.create(5, SECONDS));
}).build());
}
private void startThinking(FiniteDuration duration) {
context().become(thinking);
context().system().scheduler().scheduleOnce(duration, self(), Eat, context().system().dispatcher(), self());