Compare commits
12 Commits
Author | SHA1 | Date |
---|---|---|
olhag | 95333b0ef1 | |
egor.rutkowski | 6a5c08f743 | |
egor.rutkowski | a5ce806086 | |
egor.rutkowski | e9d4dab71f | |
olhag | d37262eadc | |
Egor Rutkowski | af1ead1b50 | |
Egor Rutkowski | 028dd290e6 | |
egor.rutkowski | 4366a22761 | |
egor.rutkowski | f9c07cebd9 | |
egor.rutkowski | 599aab4d04 | |
egor.rutkowski | a633559cc3 | |
egor.rutkowski | fb249b94a9 |
|
@ -1,5 +1,8 @@
|
|||
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.Behavior;
|
||||
import akka.actor.typed.javadsl.*;
|
||||
|
@ -156,15 +159,15 @@ public class Actor extends AbstractBehavior<Actor.Message> {
|
|||
private Behavior<Message> onLeftStringResponse(LeftStringResponse response){
|
||||
this.leftString = response.string;
|
||||
if(this.rightString != null){
|
||||
if(this.initial != null){
|
||||
initial.tell(new PrintAndEvaluate.StringResponse("(" + leftString + operationString + rightString +")"));
|
||||
}else {
|
||||
if(side == true){
|
||||
oberActor.tell(new Actor.LeftStringResponse("(" + leftString + operationString + rightString +")"));
|
||||
}else {
|
||||
oberActor.tell(new Actor.RightStringResponse("(" + leftString + operationString + rightString +")"));
|
||||
}
|
||||
}
|
||||
if(this.initial != null){
|
||||
initial.tell(new PrintAndEvaluate.StringResponse("(" + leftString + operationString + rightString +")"));
|
||||
}else {
|
||||
if(side == true){
|
||||
oberActor.tell(new Actor.LeftStringResponse("(" + leftString + operationString + rightString +")"));
|
||||
}else {
|
||||
oberActor.tell(new Actor.RightStringResponse("(" + leftString + operationString + rightString +")"));
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
@ -300,13 +303,13 @@ public class Actor extends AbstractBehavior<Actor.Message> {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
if (operationString.equals("+")) {
|
||||
initial.tell(new PrintAndEvaluate.IntResponse(leftInt + rightInt));
|
||||
} else if (operationString.equals("-")) {
|
||||
initial.tell(new PrintAndEvaluate.IntResponse(leftInt - rightInt));
|
||||
} else {
|
||||
initial.tell(new PrintAndEvaluate.IntResponse(leftInt * rightInt));
|
||||
}
|
||||
if (operationString.equals("+")) {
|
||||
initial.tell(new PrintAndEvaluate.IntResponse(leftInt + rightInt));
|
||||
} else if (operationString.equals("-")) {
|
||||
initial.tell(new PrintAndEvaluate.IntResponse(leftInt - rightInt));
|
||||
} else {
|
||||
initial.tell(new PrintAndEvaluate.IntResponse(leftInt * rightInt));
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
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.Behavior;
|
||||
import akka.actor.typed.javadsl.AbstractBehavior;
|
||||
|
|
|
@ -3,6 +3,9 @@ package com.example;
|
|||
import akka.actor.typed.ActorSystem;
|
||||
|
||||
import java.io.IOException;
|
||||
/*
|
||||
Martrikelnummer der Gruppenmitglieder: Olha Grubryn (235122), Egor Rutkowski(225064), Nikola Kramaric (238498), Dennis Ruppel (238503)
|
||||
*/
|
||||
public class AkkaStart {
|
||||
public static void main(String[] args) {
|
||||
final ActorSystem<AkkaMainSystem.Create> messageMain = ActorSystem.create(AkkaMainSystem.create(), "akkaMainSystem");
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
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;
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
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;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,9 @@
|
|||
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.Behavior;
|
||||
import akka.actor.typed.javadsl.AbstractBehavior;
|
||||
|
@ -7,9 +11,14 @@ import akka.actor.typed.javadsl.ActorContext;
|
|||
import akka.actor.typed.javadsl.Behaviors;
|
||||
import akka.actor.typed.javadsl.Receive;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
|
||||
public class PrintAndEvaluate extends AbstractBehavior<PrintAndEvaluate.Message> {
|
||||
|
||||
String name;
|
||||
Instant startTime; // Startzeit für die Zeitmessung der Berechnung
|
||||
|
||||
public interface Message{}
|
||||
|
||||
public record StringResponse(String string) implements Message{}
|
||||
|
@ -36,29 +45,35 @@ public class PrintAndEvaluate extends AbstractBehavior<PrintAndEvaluate.Message>
|
|||
.build();
|
||||
}
|
||||
|
||||
//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){
|
||||
//Starten des Formatierungsvorganges
|
||||
this.getContext().getLog().info("\n Beginn der Ausdrucksformatierung");
|
||||
ActorRef<Actor.Message> printActor = getContext().spawnAnonymous(Actor.create());
|
||||
printActor.tell(new Actor.PrintMessage(getContext().getSelf(),message.expression));
|
||||
// Startzeit für die Zeitmessung setzen
|
||||
this.startTime = Instant.now();
|
||||
|
||||
//Starten des Berechnungsvorganges
|
||||
// Starten des Formatierungsvorganges
|
||||
this.getContext().getLog().info("\n Beginn der Ausdrucksformatierung");
|
||||
|
||||
ActorRef<Actor.Message> printActor = getContext().spawnAnonymous(Actor.create());
|
||||
printActor.tell(new Actor.PrintMessage(getContext().getSelf(), message.expression));
|
||||
|
||||
// Starten des Berechnungsvorganges
|
||||
this.getContext().getLog().info("\n Beginn der Berechnung");
|
||||
ActorRef<Actor.Message> computeActor = getContext().spawnAnonymous(Actor.create());
|
||||
computeActor.tell(new Actor.EvaluateMessage(getContext().getSelf(), message.expression));
|
||||
return this;
|
||||
}
|
||||
|
||||
//Ausgeben des Ausdruckes als String
|
||||
// Ausgeben des Ausdruckes als String
|
||||
private Behavior<Message> onStringResponse(StringResponse response){
|
||||
this.getContext().getLog().info("\n Formatierter Ausdruck: " + response.string);
|
||||
return this;
|
||||
}
|
||||
|
||||
//Ausgeben des berechneten Wertes von dem Ausdruck
|
||||
// Ausgeben des berechneten Wertes von dem Ausdruck und der Berechnungsdauer
|
||||
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 Berechnungsdauer: " + duration.toSeconds() + " Sekunden");
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue