Compare commits

..

2 Commits

Author SHA1 Message Date
Egor Rutkowski 19913c8444 Print und Evaluate aufgeteilt (Das war schmerzhaft). V1.0 2024-07-02 21:36:49 +02:00
Egor Rutkowski 808d952198 Print und Evaluate aufgeteilt (Das war schmerzhaft). V1.0 2024-07-02 21:26:20 +02:00
6 changed files with 102 additions and 47 deletions

View File

@ -1,8 +1,5 @@
package com.example; package com.example;
/*
Martrikelnummer der Gruppenmitglieder: Olha Grubryn (235122), Egor Rutkowski(225064), Nikola Kramaric (238498), Dennis Ruppel (238503)
*/
import akka.actor.typed.ActorRef; import akka.actor.typed.ActorRef;
import akka.actor.typed.Behavior; import akka.actor.typed.Behavior;
import akka.actor.typed.javadsl.*; import akka.actor.typed.javadsl.*;

View File

@ -1,9 +1,5 @@
package com.example; package com.example;
/*
Martrikelnummer der Gruppenmitglieder: Olha Grubryn (235122), Egor Rutkowski(225064), Nikola Kramaric (238498), Dennis Ruppel (238503)
*/
import akka.actor.typed.ActorRef; import akka.actor.typed.ActorRef;
import akka.actor.typed.Behavior; import akka.actor.typed.Behavior;
import akka.actor.typed.javadsl.AbstractBehavior; import akka.actor.typed.javadsl.AbstractBehavior;

View File

@ -3,9 +3,6 @@ package com.example;
import akka.actor.typed.ActorSystem; import akka.actor.typed.ActorSystem;
import java.io.IOException; import java.io.IOException;
/*
Martrikelnummer der Gruppenmitglieder: Olha Grubryn (235122), Egor Rutkowski(225064), Nikola Kramaric (238498), Dennis Ruppel (238503)
*/
public class AkkaStart { public class AkkaStart {
public static void main(String[] args) { public static void main(String[] args) {
final ActorSystem<AkkaMainSystem.Create> messageMain = ActorSystem.create(AkkaMainSystem.create(), "akkaMainSystem"); final ActorSystem<AkkaMainSystem.Create> messageMain = ActorSystem.create(AkkaMainSystem.create(), "akkaMainSystem");

View File

@ -0,0 +1,35 @@
package com.example;
import akka.actor.typed.ActorRef;
import akka.actor.typed.Behavior;
import akka.actor.typed.javadsl.*;
public class ExampleActor extends AbstractBehavior<ExampleActor.Message>{
public interface Message {};
public record ExampleMessage(ActorRef<AkkaMainSystem.Create> someReference, String someString) implements Message { }
public static Behavior<Message> create(String name) {
return Behaviors.setup(context -> new ExampleActor(context, name));
}
private final String name;
private ExampleActor(ActorContext<Message> context, String name) {
super(context);
this.name = "test";
}
@Override
public Receive<Message> createReceive() {
return newReceiveBuilder()
.onMessage(ExampleMessage.class, this::onExampleMessage)
.build();
}
private Behavior<Message> onExampleMessage(ExampleMessage msg) {
getContext().getLog().info("I ({}) got a message: ExampleMessage({},{})", this.name, msg.someReference, msg.someString);
return this;
}
}

View File

@ -0,0 +1,45 @@
package com.example;
import akka.actor.typed.javadsl.TimerScheduler;
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;
import java.time.Duration;
public class ExampleTimerActor extends AbstractBehavior<ExampleTimerActor.Message> {
public interface Message {};
public record ExampleMessage(String someString) implements Message { }
public static Behavior<Message> create() {
return Behaviors.setup(context -> Behaviors.withTimers(timers -> new ExampleTimerActor(context, timers)));
}
private final TimerScheduler<ExampleTimerActor.Message> timers;
private ExampleTimerActor(ActorContext<Message> context, TimerScheduler<ExampleTimerActor.Message> timers) {
super(context);
this.timers = timers;
Message msg = new ExampleMessage("test123");
this.timers.startSingleTimer(msg, msg, Duration.ofSeconds(10));
}
@Override
public Receive<Message> createReceive() {
return newReceiveBuilder()
.onMessage(ExampleMessage.class, this::onExampleMessage)
.build();
}
private Behavior<Message> onExampleMessage(ExampleMessage msg) {
getContext().getLog().info("I have send myself this message after 10 Seconds: {}", msg.someString);
return this;
}
}

View File

@ -1,9 +1,5 @@
package com.example; package com.example;
/*
Martrikelnummer der Gruppenmitglieder: Olha Grubryn (235122), Egor Rutkowski(225064), Nikola Kramaric (238498), Dennis Ruppel (238503)
*/
import akka.actor.typed.ActorRef; import akka.actor.typed.ActorRef;
import akka.actor.typed.Behavior; import akka.actor.typed.Behavior;
import akka.actor.typed.javadsl.AbstractBehavior; import akka.actor.typed.javadsl.AbstractBehavior;
@ -11,14 +7,9 @@ import akka.actor.typed.javadsl.ActorContext;
import akka.actor.typed.javadsl.Behaviors; import akka.actor.typed.javadsl.Behaviors;
import akka.actor.typed.javadsl.Receive; import akka.actor.typed.javadsl.Receive;
import java.time.Duration;
import java.time.Instant;
public class PrintAndEvaluate extends AbstractBehavior<PrintAndEvaluate.Message> { public class PrintAndEvaluate extends AbstractBehavior<PrintAndEvaluate.Message> {
String name; String name;
Instant startTime; // Startzeit für die Zeitmessung der Berechnung
public interface Message{} public interface Message{}
public record StringResponse(String string) implements Message{} public record StringResponse(String string) implements Message{}
@ -47,12 +38,8 @@ public class PrintAndEvaluate extends AbstractBehavior<PrintAndEvaluate.Message>
//Mit dieser Message wird der PrintAndEvaluate Aktor in Gang gesetzt //Mit dieser Message wird der PrintAndEvaluate Aktor in Gang gesetzt
private Behavior<Message> onStartMessage(StartMessage message){ private Behavior<Message> onStartMessage(StartMessage message){
// Startzeit für die Zeitmessung setzen
this.startTime = Instant.now();
//Starten des Formatierungsvorganges //Starten des Formatierungsvorganges
this.getContext().getLog().info("\n Beginn der Ausdrucksformatierung"); this.getContext().getLog().info("\n Beginn der Ausdrucksformatierung");
ActorRef<Actor.Message> printActor = getContext().spawnAnonymous(Actor.create()); ActorRef<Actor.Message> printActor = getContext().spawnAnonymous(Actor.create());
printActor.tell(new Actor.PrintMessage(getContext().getSelf(),message.expression)); printActor.tell(new Actor.PrintMessage(getContext().getSelf(),message.expression));
@ -69,11 +56,9 @@ public class PrintAndEvaluate extends AbstractBehavior<PrintAndEvaluate.Message>
return this; return this;
} }
// Ausgeben des berechneten Wertes von dem Ausdruck und der Berechnungsdauer //Ausgeben des berechneten Wertes von dem Ausdruck
private Behavior<Message> onIntResponse(IntResponse response){ private Behavior<Message> onIntResponse(IntResponse response){
Duration duration = Duration.between(startTime, Instant.now());
this.getContext().getLog().info("\n Ausgerechneter Wert: " + response.wert); this.getContext().getLog().info("\n Ausgerechneter Wert: " + response.wert);
this.getContext().getLog().info("\n Berechnungsdauer: " + duration.toSeconds() + " Sekunden");
return this; return this;
} }
} }