+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:
parent
30ae25a90c
commit
723c931d16
23 changed files with 683 additions and 570 deletions
|
|
@ -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()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue