ExceptionHandling und Timer fehlen noch
This commit is contained in:
parent
149f3e7141
commit
16291e0e11
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -26,8 +26,6 @@ public class DeliveryCar extends AbstractBehavior<DeliveryCar.Message> {
|
||||||
|
|
||||||
public record StartRoute() implements Message {}
|
public record StartRoute() implements Message {}
|
||||||
|
|
||||||
public record RestartRoute() implements Message{}
|
|
||||||
|
|
||||||
private DeliveryCar(ActorContext<Message> context, ArrayList<ActorRef<Customer.Message>> route) {
|
private DeliveryCar(ActorContext<Message> context, ArrayList<ActorRef<Customer.Message>> route) {
|
||||||
super(context);
|
super(context);
|
||||||
this.route = route;
|
this.route = route;
|
||||||
|
@ -40,6 +38,7 @@ public class DeliveryCar extends AbstractBehavior<DeliveryCar.Message> {
|
||||||
@Override
|
@Override
|
||||||
public Receive<Message> createReceive() {
|
public Receive<Message> createReceive() {
|
||||||
return newReceiveBuilder()
|
return newReceiveBuilder()
|
||||||
|
.onMessage(PickupResponse.class, this::onPickupResponse)
|
||||||
.onMessage(LoadMessage.class, this::onLoadMessage)
|
.onMessage(LoadMessage.class, this::onLoadMessage)
|
||||||
.onMessage(PickupResponse.class, this::onPickupResponse)
|
.onMessage(PickupResponse.class, this::onPickupResponse)
|
||||||
.onMessage(StartRoute.class, msg->{
|
.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
|
//Wenn fertig iteriert so geht der Wagen an den Verteilerzentrum
|
||||||
if(globalIndex==4){
|
if(globalIndex==4){
|
||||||
DistributionCenter.ArriveMessage antwort = new DistributionCenter.ArriveMessage(pakete,getContext().getSelf());
|
DistributionCenter.ArriveMessage antwort = new DistributionCenter.ArriveMessage(pakete,getContext().getSelf());
|
||||||
|
//ActorRef<DistributionCenter.Message> antwort1;
|
||||||
|
// antwort1.tell(antwort);
|
||||||
|
|
||||||
//Fehlende Antwort an den Verteilerzentrum
|
//Fehlende Antwort an den Verteilerzentrum
|
||||||
|
|
||||||
|
|
||||||
|
@ -90,16 +92,20 @@ public class DeliveryCar extends AbstractBehavior<DeliveryCar.Message> {
|
||||||
sendPickupMessage();
|
sendPickupMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private Behavior<Message> onStartRoute(){
|
public Behavior<Message> onStartRoute(){
|
||||||
if(globalIndex==0){
|
/*if(globalIndex==0){
|
||||||
checkNextStop();
|
checkNextStop();
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
if(globalIndex==4) {
|
if(globalIndex==4) {
|
||||||
globalIndex = 0;
|
globalIndex = 0;
|
||||||
onStartRoute();
|
onStartRoute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return this;*/
|
||||||
|
globalIndex = 0;
|
||||||
|
checkNextStop();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +126,7 @@ public class DeliveryCar extends AbstractBehavior<DeliveryCar.Message> {
|
||||||
if(pakete.get(globalIndex).empfaenger == nextCustomer ) {
|
if(pakete.get(globalIndex).empfaenger == nextCustomer ) {
|
||||||
nextCustomer.tell(new Customer.DeliveryMessage(paket));
|
nextCustomer.tell(new Customer.DeliveryMessage(paket));
|
||||||
pakete.remove(globalIndex);
|
pakete.remove(globalIndex);
|
||||||
globalIndex++;
|
// globalIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,11 @@ import java.util.List;
|
||||||
public class DistributionCenter extends AbstractBehavior<DistributionCenter.Message> {
|
public class DistributionCenter extends AbstractBehavior<DistributionCenter.Message> {
|
||||||
|
|
||||||
private final ActorRef<AddressBook.Message> addressBook;
|
private final ActorRef<AddressBook.Message> addressBook;
|
||||||
|
public static class StartAllRoutes implements Message {}
|
||||||
|
|
||||||
private final List<Paket> lagerraum = new ArrayList<>();
|
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) {
|
private DistributionCenter(ActorContext<Message> context, ActorRef<AddressBook.Message> addressBook) {
|
||||||
super(context);
|
super(context);
|
||||||
|
@ -91,6 +95,7 @@ public class DistributionCenter extends AbstractBehavior<DistributionCenter.Mess
|
||||||
.onMessage(ArriveMessage.class, this::onArriveMessage)
|
.onMessage(ArriveMessage.class, this::onArriveMessage)
|
||||||
.onMessage(LoadMessage.class, this::onLoadMessage)
|
.onMessage(LoadMessage.class, this::onLoadMessage)
|
||||||
.onMessage(GenerateRoutes.class, this::onGenerateRoutes)
|
.onMessage(GenerateRoutes.class, this::onGenerateRoutes)
|
||||||
|
.onMessage(StartAllRoutes.class, this::onStartAllRoutes)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,10 +141,24 @@ public class DistributionCenter extends AbstractBehavior<DistributionCenter.Mess
|
||||||
|
|
||||||
// Erstelle vier Lastwagen mit zufälligen Routen
|
// Erstelle vier Lastwagen mit zufälligen Routen
|
||||||
for (int i = 0; i < 4; i++) {
|
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().spawn(DeliveryCar.create(route), "deliveryCar" + i+1);
|
||||||
|
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());
|
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
|
// Dummy-Methode zum Generieren einer zufälligen Route
|
||||||
|
|
Loading…
Reference in New Issue