Anfang
This commit is contained in:
parent
0ee16028d7
commit
cfcebd59c9
|
@ -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<Actor.Message> {
|
||||
|
||||
String name;
|
||||
Expression expression;
|
||||
public interface Message{}
|
||||
|
||||
public record StartMessage(Expression expression) implements Message{}
|
||||
|
||||
private Actor(ActorContext<Message> context, String name, Expression expression){
|
||||
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));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Receive<Actor.Message> createReceive(){
|
||||
return newReceiveBuilder()
|
||||
//.onMessage(StartMessage.class, this::onStartMessage)
|
||||
.build();
|
||||
}
|
||||
|
||||
private Behavior<Message> onStartMessage(Expression expression){
|
||||
this.expression = expression;
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -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<AkkaMainSystem.Create> {
|
||||
|
||||
|
@ -26,9 +29,12 @@ public class AkkaMainSystem extends AbstractBehavior<AkkaMainSystem.Create> {
|
|||
//#create-actors
|
||||
ActorRef<ExampleActor.Message> a = this.getContext().spawn(ExampleActor.create("Alice"), "alice");
|
||||
ActorRef<ExampleTimerActor.Message> 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<Actor.Message> test = this.getContext().spawn(Actor.create("Seng", expression), "Sengmann");
|
||||
|
||||
System.out.println(expression.toString()+ " Wert:" +expression.eval());
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import akka.actor.typed.ActorRef;
|
|||
import akka.actor.typed.Behavior;
|
||||
import akka.actor.typed.javadsl.*;
|
||||
|
||||
public class ExampleActor extends AbstractBehavior<ExampleActor.Message> {
|
||||
public class ExampleActor extends AbstractBehavior<ExampleActor.Message>{
|
||||
|
||||
public interface Message {};
|
||||
|
||||
|
|
Loading…
Reference in New Issue