ExceptionHandling und Timer fehlen noch

This commit is contained in:
de1008 2024-05-17 21:58:23 +02:00
parent 149f3e7141
commit 16291e0e11
16 changed files with 33 additions and 8 deletions

View File

@ -26,8 +26,6 @@ public class DeliveryCar extends AbstractBehavior<DeliveryCar.Message> {
public record StartRoute() implements Message {}
public record RestartRoute() implements Message{}
private DeliveryCar(ActorContext<Message> context, ArrayList<ActorRef<Customer.Message>> route) {
super(context);
this.route = route;
@ -40,6 +38,7 @@ public class DeliveryCar extends AbstractBehavior<DeliveryCar.Message> {
@Override
public Receive<Message> createReceive() {
return newReceiveBuilder()
.onMessage(PickupResponse.class, this::onPickupResponse)
.onMessage(LoadMessage.class, this::onLoadMessage)
.onMessage(PickupResponse.class, this::onPickupResponse)
.onMessage(StartRoute.class, msg->{
@ -78,6 +77,9 @@ public class DeliveryCar extends AbstractBehavior<DeliveryCar.Message> {
//Wenn fertig iteriert so geht der Wagen an den Verteilerzentrum
if(globalIndex==4){
DistributionCenter.ArriveMessage antwort = new DistributionCenter.ArriveMessage(pakete,getContext().getSelf());
//ActorRef<DistributionCenter.Message> antwort1;
// antwort1.tell(antwort);
//Fehlende Antwort an den Verteilerzentrum
@ -90,16 +92,20 @@ public class DeliveryCar extends AbstractBehavior<DeliveryCar.Message> {
sendPickupMessage();
}
}
private Behavior<Message> onStartRoute(){
if(globalIndex==0){
public Behavior<Message> onStartRoute(){
/*if(globalIndex==0){
checkNextStop();
return this;
}else{
if(globalIndex==4) {
globalIndex = 0;
onStartRoute();
}
}
return this;*/
globalIndex = 0;
checkNextStop();
return this;
}
@ -120,7 +126,7 @@ public class DeliveryCar extends AbstractBehavior<DeliveryCar.Message> {
if(pakete.get(globalIndex).empfaenger == nextCustomer ) {
nextCustomer.tell(new Customer.DeliveryMessage(paket));
pakete.remove(globalIndex);
globalIndex++;
// globalIndex++;
}
}

View File

@ -14,7 +14,11 @@ import java.util.List;
public class DistributionCenter extends AbstractBehavior<DistributionCenter.Message> {
private final ActorRef<AddressBook.Message> addressBook;
public static class StartAllRoutes implements Message {}
private final List<Paket> lagerraum = new ArrayList<>();
private final List<ActorRef<DeliveryCar.Message>> deliveryCars = new ArrayList<>();
private DistributionCenter(ActorContext<Message> context, ActorRef<AddressBook.Message> addressBook) {
super(context);
@ -91,6 +95,7 @@ public class DistributionCenter extends AbstractBehavior<DistributionCenter.Mess
.onMessage(ArriveMessage.class, this::onArriveMessage)
.onMessage(LoadMessage.class, this::onLoadMessage)
.onMessage(GenerateRoutes.class, this::onGenerateRoutes)
.onMessage(StartAllRoutes.class, this::onStartAllRoutes)
.build();
}
@ -136,10 +141,24 @@ public class DistributionCenter extends AbstractBehavior<DistributionCenter.Mess
// Erstelle vier Lastwagen mit zufälligen Routen
for (int i = 0; i < 4; i++) {
List<ActorRef<Customer.Message>> route = generateRandomRoute(customers);
/*List<ActorRef<Customer.Message>> route = generateRandomRoute(customers);
getContext().spawn(DeliveryCar.create(route), "deliveryCar" + i+1);
getContext().getLog().info("Lieferwagen {} erstellt mit Route: {}", i+1, route.toString());
getContext().getLog().info("Lieferwagen {} erstellt mit Route: {}", i+1, route.toString());*/
List<ActorRef<Customer.Message>> route = generateRandomRoute(customers);
ActorRef<DeliveryCar.Message> deliveryCar = getContext().spawn(DeliveryCar.create(route), "deliveryCar" + (i + 1));
getContext().getLog().info("Lieferwagen {} erstellt mit Route: {}", i + 1, route.toString());
deliveryCar.tell(new DeliveryCar.StartRoute());
}
}
private Behavior<Message> onStartAllRoutes(StartAllRoutes msg) {
for (ActorRef<DeliveryCar.Message> deliveryCar : deliveryCars) {
deliveryCar.tell(new DeliveryCar.StartRoute());
}
return this;
}
// Dummy-Methode zum Generieren einer zufälligen Route