Workshop
Begin
- Download prepared workshop task: Akka Task
- Open Project with your IDE - perferably NetBeans
- Look at TODOs in the comments (On NetBeans Ctrl + 6)
- Try to implement the missing functionality
- There are some tests but not everything is covered.
- Improve the program with one of the ideas below or come up with your own improvement
There are also questions at certain locations. Try to answer them, this will help you to understands the concepts.
See also: Akka Javadocs
Task Overview
Do you remember the restaurant task from the JAVA3 course? (Original assignment description)
One of the most challenging part of this assignment is the synchronization between the restaurant manager, the chef who cooks the meals and the waiter who collects orders and serves meals. There are a lot of different possibilities to solve the problems, some of them works with the some Java features which are available now for a long time (see wait-notify). You can also make use of the advanced Java Executor Framework
For our workshop task we will try to implement the a restaurant using Akka Actors.
Structure
Actors The program consists of four actors:
- The restaurant is responsible to manage the basic tasks and to “employ the staff”
- Customers should order meals and eat them when they are served
- Chefs are responsible to cook customer´s order
- Waiter are responsible to record the orders and serve the prepared meals
Messages
- OpeningMessage - The restaurant opens, staff should be employed
- EnteringMessage - A customer enters the restaurant
- WhatsYourOrder - A waiter asks for the customer´s order
- CompleteOrder - Complete order of a customer
- PreparedMeal - One prepared meal ready to serve
- EatingFinished - A customer has finished eating, the whole order has been served
- ClosingMessage - The restaurant closes. Kick out customers and fire staff
Recipes The assignment already consists of a set of recipes. Feel free to add your own ones.
Improvements?
The task offers a lot of opportunities to improve the implementation.
- Increase number of recipes
- Create customer-actors outside of restaurant
- Make customer order not random
- Direct communication between Waiter and customer using ActorSelections
- Direct communication between Chef and Waiter using ActorSelection
- Is everything for free? Shouldn’t the customer pay for the meals?
You can also think of your own improvements. Maybe restructuring the whole application. Or pulling out some actors to run somewhere else and connecting them using networks (see Akka Networking).