This example uses KAR's Actor Programming Model to implement Dijkstra's solution to the Dining Philosophers problem (https://en.wikipedia.org/wiki/Dining_philosophers_problem).
The Philosophers and their Forks are all actors and interact via actor method invocations to implement the distributed protocol that ensures no Philosopher starves.
Philosophers use a tail call pattern to move from one state to the next and achieve fault tolerance.
A Cafe may contain an arbitrary number of tables of Philosophers. Each Cafe tracks its occupancy and generates messages when it seats new tables or when a sated Philosopher leaves.
To run the example locally using Open Liberty, first
compile and package the application by doing mvn package
.
Next, run the application by doing:
kar run -app dp -actors Cafe,Fork,Philosopher,Table mvn liberty:run
In a second shell window, use the kar
cli to invite some Philosopers to dinner:
# Invite 10 Philosophers to a meal of 20 servings each
kar invoke -app dp Cafe Cafe+de+Flore seatTable 10 20