2023-05-03 12:02:18 +02:00
|
|
|
package com.example;
|
|
|
|
|
|
|
|
import akka.actor.typed.ActorRef;
|
|
|
|
import akka.actor.typed.Behavior;
|
|
|
|
import akka.actor.typed.javadsl.*;
|
|
|
|
|
2024-05-15 01:29:12 +02:00
|
|
|
import java.util.ArrayList;
|
2024-05-17 01:18:02 +02:00
|
|
|
import java.util.List;
|
2024-05-15 01:29:12 +02:00
|
|
|
|
2023-05-03 12:02:18 +02:00
|
|
|
public class AkkaMainSystem extends AbstractBehavior<AkkaMainSystem.Create> {
|
|
|
|
|
2024-05-18 18:19:24 +02:00
|
|
|
public static class Create {}
|
2023-05-03 12:02:18 +02:00
|
|
|
|
|
|
|
public static Behavior<Create> create() {
|
|
|
|
return Behaviors.setup(AkkaMainSystem::new);
|
|
|
|
}
|
|
|
|
|
2024-05-18 18:19:24 +02:00
|
|
|
// Statische Referenz auf das DistributionCenter
|
|
|
|
private static ActorRef<DistributionCenter.Message> distributionCenter;
|
|
|
|
|
|
|
|
// Statische Methode zum Abrufen der DistributionCenter-Referenz
|
|
|
|
public static ActorRef<DistributionCenter.Message> getDistributionCenter() {
|
|
|
|
return distributionCenter;
|
|
|
|
}
|
|
|
|
|
2023-05-03 12:02:18 +02:00
|
|
|
private AkkaMainSystem(ActorContext<Create> context) {
|
|
|
|
super(context);
|
2024-05-18 18:19:24 +02:00
|
|
|
|
|
|
|
// Erstellen des Adressbuchs
|
|
|
|
ArrayList<ActorRef<Customer.Message>> customers = new ArrayList<>();
|
|
|
|
customers.add(getContext().spawn(Customer.create("Alice"), "alice"));
|
|
|
|
customers.add(getContext().spawn(Customer.create("Bob"), "bob"));
|
|
|
|
customers.add(getContext().spawn(Customer.create("Charles"), "charles"));
|
|
|
|
customers.add(getContext().spawn(Customer.create("Derick"), "derick"));
|
|
|
|
ActorRef<AddressBook.Message> addressBook = getContext().spawn(AddressBook.create(customers), "addressBook");
|
|
|
|
|
|
|
|
// Erstellen des Verteilzentrums
|
|
|
|
distributionCenter = getContext().spawn(DistributionCenter.create(addressBook), "distributionCenter");
|
|
|
|
|
2023-05-03 12:02:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Receive<Create> createReceive() {
|
|
|
|
return newReceiveBuilder().onMessage(Create.class, this::onCreate).build();
|
|
|
|
}
|
|
|
|
|
|
|
|
private Behavior<Create> onCreate(Create command) {
|
2024-05-18 18:19:24 +02:00
|
|
|
// Additional setup if needed
|
2023-05-03 12:02:18 +02:00
|
|
|
return this;
|
|
|
|
}
|
2024-05-18 18:19:24 +02:00
|
|
|
}
|