Expression aus Actor Konstruktor rausgenommen und in StartMessage verlagert. Außerdem wird Val ausgewertet.
This commit is contained in:
parent
1da49a5d57
commit
f5f7cd2e7e
|
@ -14,14 +14,13 @@ public class Actor extends AbstractBehavior<Actor.Message> {
|
|||
|
||||
public record StartMessage(Expression expression) implements Message{}
|
||||
|
||||
private Actor(ActorContext<Message> context, String name, Expression expression){
|
||||
private Actor(ActorContext<Message> context, String name){
|
||||
super(context);
|
||||
this.name = name;
|
||||
this.expression = expression;
|
||||
}
|
||||
|
||||
public static Behavior<Actor.Message> create(String name,Expression expression){
|
||||
return Behaviors.setup(context -> new Actor(context, name, expression));
|
||||
public static Behavior<Actor.Message> create(String name){
|
||||
return Behaviors.setup(context -> new Actor(context, name));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -33,7 +32,11 @@ public class Actor extends AbstractBehavior<Actor.Message> {
|
|||
|
||||
private Behavior<Message> onStartMessage(StartMessage message){
|
||||
this.expression = message.expression;
|
||||
//Wenn initial nur Val übergeben wird -> einfach ausgeben
|
||||
if(expression instanceof Expression.Val){
|
||||
System.out.println(((Expression.Val) expression).inner());
|
||||
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,9 +32,10 @@ public class AkkaMainSystem extends AbstractBehavior<AkkaMainSystem.Create> {
|
|||
|
||||
//#create-actors
|
||||
Expression expression = Expression.generateExpression(6, 9);
|
||||
ActorRef<Actor.Message> test = this.getContext().spawn(Actor.create("Seng", expression), "Sengmann");
|
||||
|
||||
System.out.println(expression.toString()+ " Wert:" +expression.eval());
|
||||
Expression testExp = Expression.generateExpression(1,9);
|
||||
ActorRef<Actor.Message> test = this.getContext().spawn(Actor.create("Seng"), "Sengmann");
|
||||
test.tell(new Actor.StartMessage(testExp));
|
||||
System.out.println(testExp.toString()+ " Wert:" +expression.eval());
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue