AddressBook müsste jetzt richtig sein

This commit is contained in:
Egor Rutkowski 2024-05-15 15:07:01 +02:00
parent fc6f611458
commit ab7328301b
1 changed files with 5 additions and 5 deletions

View File

@ -15,7 +15,7 @@ public class AddressBook extends AbstractBehavior<AddressBook.Message> {
ArrayList<ActorRef<Customer.Message>> customers;
public interface Message {}
public record CustomerMessage(ActorRef<Customer.Message> fragender, String nameFragender) implements Message{}
public record Response(ActorRef<Customer.Message> addresse) implements Message{}
@Override
public Receive<AddressBook.Message> createReceive() {
@ -33,12 +33,12 @@ public class AddressBook extends AbstractBehavior<AddressBook.Message> {
customers = actors;
}
//Methode, um einen zufälligen Empfänger auszugeben (wahrscheinlich das Senden am Ende noch nicht ganz richtig)
//Methode, um einen zufälligen Empfänger auszugeben
public Behavior<Message> onCustomerMessage(CustomerMessage msg){
Collections.shuffle(customers);
var adressOf = customers.get(0);
getContext().getLog().info("{} asked for an adress",msg.nameFragender);
msg.fragender().tell((Customer.Message) new Response(adressOf).addresse);
var addressOf = customers.get(0);
getContext().getLog().info("{} asked for an address",msg.nameFragender);
msg.fragender.tell(new Customer.AddressMessage(addressOf));
return this;
}
}