Actor System
Question
An actor is a lightweight execution context. An actor system is a collection of actors that can
execute concurrently in a shared nothing fashion. In an actor system each actor has a mailbox
with an address where it receives messages.
On receiving a message from its mailbox an actor can
● Send messages to other actors in the system
● Create a finite number of new actors in the system
● Change its own state
● Have side effects (print something, log something, change external durable state)...
An actor can process only one message at a time.
The lightweight nature of actors means one can create millions of actors that execute
concurrently even on systems with modest hardware capacity.
Problem
Implement an actor system that contains a set of actors
Actor
- has a unique address in an ActorSystem
- has a finite sized mailbox to receive messages in FIFO order
- can be shut down, after which it doesn't accept/receive any messages in its mailbox
ActorSystem
- Is initialized with a finite threadpool size.
- Receives messages for actors that it contains.
- Executes actors that have messages to process using fair scheduling (actors don't starve).
- Can be shut down, after which the actor system doesn't accept/relay any new messages.
- Shut down all it's actors once they have processed all their remaining messages.
- Throws appropriate exception if a message cannot be delivered
- All actors should execute concurrently in a thread safe manner.
Guidelines
- The code should be modular and testable.
- Provide at least one test case and demonstrate the working of your code
- State any assumptions you make.
- Thread Safe code