From f5f7cd2e7eacfca0adf23769776f446cd1570f29 Mon Sep 17 00:00:00 2001 From: Egor Rutkowski Date: Mon, 1 Jul 2024 15:42:53 +0200 Subject: [PATCH] =?UTF-8?q?Expression=20aus=20Actor=20Konstruktor=20rausge?= =?UTF-8?q?nommen=20und=20in=20StartMessage=20verlagert.=20Au=C3=9Ferdem?= =?UTF-8?q?=20wird=20Val=20ausgewertet.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/Actor.java | 11 +++++++---- src/main/java/com/example/AkkaMainSystem.java | 7 ++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/example/Actor.java b/src/main/java/com/example/Actor.java index 0cac934..a846e7d 100644 --- a/src/main/java/com/example/Actor.java +++ b/src/main/java/com/example/Actor.java @@ -14,14 +14,13 @@ public class Actor extends AbstractBehavior { public record StartMessage(Expression expression) implements Message{} - private Actor(ActorContext context, String name, Expression expression){ + private Actor(ActorContext context, String name){ super(context); this.name = name; - this.expression = expression; } - public static Behavior create(String name,Expression expression){ - return Behaviors.setup(context -> new Actor(context, name, expression)); + public static Behavior create(String name){ + return Behaviors.setup(context -> new Actor(context, name)); } @Override @@ -33,7 +32,11 @@ public class Actor extends AbstractBehavior { private Behavior 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; } } diff --git a/src/main/java/com/example/AkkaMainSystem.java b/src/main/java/com/example/AkkaMainSystem.java index 946c2f2..d27ef68 100644 --- a/src/main/java/com/example/AkkaMainSystem.java +++ b/src/main/java/com/example/AkkaMainSystem.java @@ -32,9 +32,10 @@ public class AkkaMainSystem extends AbstractBehavior { //#create-actors Expression expression = Expression.generateExpression(6, 9); - ActorRef test = this.getContext().spawn(Actor.create("Seng", expression), "Sengmann"); - - System.out.println(expression.toString()+ " Wert:" +expression.eval()); + Expression testExp = Expression.generateExpression(1,9); + ActorRef test = this.getContext().spawn(Actor.create("Seng"), "Sengmann"); + test.tell(new Actor.StartMessage(testExp)); + System.out.println(testExp.toString()+ " Wert:" +expression.eval()); return this; } }