+act,sam,doc #3940 Added receive setter for Java Lambda actors

* Added a setter for Java lambda actors to "hide" the not so nice looking type signature of the "receive" method.
* Updated docs to reflect the changes.
* Converted samples to use the new setter.
This commit is contained in:
Björn Antonsson 2014-03-20 12:05:32 +01:00
parent 30ae25a90c
commit 723c931d16
23 changed files with 683 additions and 570 deletions

View file

@ -61,15 +61,15 @@ class ArithmeticService extends AbstractLoggingActor {
}
}
@Override
public PartialFunction<Object, BoxedUnit> receive() {
return ReceiveBuilder.
ArithmeticService() {
receive(ReceiveBuilder.
match(Expression.class, expr -> {
// We delegate the dangerous task of calculation to a worker, passing the
// expression as a constructor argument to the actor.
ActorRef worker = context().actorOf(FlakyExpressionCalculator.props(expr, Left));
pendingWorkers.put(worker, sender());
}).
match(Result.class, r -> notifyConsumerSuccess(sender(), r.getValue())).build();
match(Result.class, r -> notifyConsumerSuccess(sender(), r.getValue())).build()
);
}
}
}

View file

@ -67,11 +67,6 @@ public class FlakyExpressionCalculator extends AbstractLoggingActor {
private final Expression expr;
private final Position myPosition;
public FlakyExpressionCalculator(Expression expr, Position myPosition) {
this.expr = expr;
this.myPosition = myPosition;
}
private Expression getExpr() {
return expr;
}
@ -107,9 +102,11 @@ public class FlakyExpressionCalculator extends AbstractLoggingActor {
}
}
@Override
public PartialFunction<Object, BoxedUnit> receive() {
return ReceiveBuilder.
public FlakyExpressionCalculator(Expression expr, Position myPosition) {
this.expr = expr;
this.myPosition = myPosition;
receive(ReceiveBuilder.
match(Result.class, r -> expected.contains(r.getPosition()), r -> {
expected.remove(r.getPosition());
results.put(r.getPosition(), r.getValue());
@ -126,7 +123,7 @@ public class FlakyExpressionCalculator extends AbstractLoggingActor {
throw new IllegalStateException("Expected results for positions " +
expected.stream().map(Object::toString).collect(Collectors.joining(", ")) +
" but got position " + r.getPosition());
}).build();
}).build());
}
private Integer evaluate(Expression expr, Integer left, Integer right) {