From cfcebd59c9e2ebc9cb6f8e7e56c20cdcba4c2762 Mon Sep 17 00:00:00 2001 From: Egor Rutkowski Date: Mon, 1 Jul 2024 15:02:13 +0200 Subject: [PATCH] Anfang --- src/main/java/com/example/Actor.java | 39 +++++++++++++++++++ src/main/java/com/example/AkkaMainSystem.java | 12 ++++-- src/main/java/com/example/ExampleActor.java | 2 +- 3 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/example/Actor.java diff --git a/src/main/java/com/example/Actor.java b/src/main/java/com/example/Actor.java new file mode 100644 index 0000000..90abbed --- /dev/null +++ b/src/main/java/com/example/Actor.java @@ -0,0 +1,39 @@ +package com.example; + +import akka.actor.typed.Behavior; +import akka.actor.typed.javadsl.AbstractBehavior; +import akka.actor.typed.javadsl.ActorContext; +import akka.actor.typed.javadsl.Behaviors; +import akka.actor.typed.javadsl.Receive; + +public class Actor extends AbstractBehavior { + + String name; + Expression expression; + public interface Message{} + + public record StartMessage(Expression expression) implements Message{} + + private Actor(ActorContext context, String name, Expression expression){ + 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)); + } + + @Override + public Receive createReceive(){ + return newReceiveBuilder() + //.onMessage(StartMessage.class, this::onStartMessage) + .build(); + } + + private Behavior onStartMessage(Expression expression){ + this.expression = expression; + + return this; + } +} diff --git a/src/main/java/com/example/AkkaMainSystem.java b/src/main/java/com/example/AkkaMainSystem.java index 868351b..946c2f2 100644 --- a/src/main/java/com/example/AkkaMainSystem.java +++ b/src/main/java/com/example/AkkaMainSystem.java @@ -2,7 +2,10 @@ package com.example; import akka.actor.typed.ActorRef; import akka.actor.typed.Behavior; -import akka.actor.typed.javadsl.*; +import akka.actor.typed.javadsl.AbstractBehavior; +import akka.actor.typed.javadsl.ActorContext; +import akka.actor.typed.javadsl.Behaviors; +import akka.actor.typed.javadsl.Receive; public class AkkaMainSystem extends AbstractBehavior { @@ -26,9 +29,12 @@ public class AkkaMainSystem extends AbstractBehavior { //#create-actors ActorRef a = this.getContext().spawn(ExampleActor.create("Alice"), "alice"); ActorRef b = this.getContext().spawn(ExampleTimerActor.create(), "timeractor"); - //#create-actors - a.tell(new ExampleActor.ExampleMessage(this.getContext().getSelf(),"Test123")); + //#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()); return this; } } diff --git a/src/main/java/com/example/ExampleActor.java b/src/main/java/com/example/ExampleActor.java index 8f1d626..5dc4b9a 100644 --- a/src/main/java/com/example/ExampleActor.java +++ b/src/main/java/com/example/ExampleActor.java @@ -4,7 +4,7 @@ import akka.actor.typed.ActorRef; import akka.actor.typed.Behavior; import akka.actor.typed.javadsl.*; -public class ExampleActor extends AbstractBehavior { +public class ExampleActor extends AbstractBehavior{ public interface Message {};