In this exercise, you will implement a request-response pattern between the Barista and CoffeeMachine actors.
The CoffeeMachine will process one coffee at a time and notify the Barista when the coffee is ready.
- The
Baristawill send a coffee order to theCoffeeMachineand handle its response. - The
CoffeeMachinewill notify theBaristaonce the coffee is brewed.
-
Edit
CoffeeMachine.java:- Implement the logic for sending a response to the Barista when a coffee is ready.
-
Edit
Barista.java:- Upon receiving an
OrderCoffee, send aBrewCoffeemessage to theCoffeeMachine. - Handle the
CoffeeIsReadyresponse from theCoffeeMachine:-
Log the pickup action with the following line, replacing
[coffee]with the coffee received:getContext().getLog().info("Barista: Picking up {}", [coffee]);
-
Send a
PickupCoffeemessage to theCoffeeMachineto reset its state.
-
- Upon receiving an
-
Run the tests:
-
Validate your implementation by running the unit tests:
mvn clean test
-
-
Hint:
- If you need to review the completed implementation, navigate to:
akka-interaction-patterns-for-java/solutions/001_request_response_pattern
- If you need to review the completed implementation, navigate to:
- Consider how the
Baristahandles responses from theCoffeeMachine. - Observe how this interaction pattern ensures state consistency in the
CoffeeMachine.
