When we execute actorRef.tell (message), what happens internally?
This section explains what happens under the hood to understand the things well. If you are not interested in knowing this, skip this section and move on to the next parts of this chapter.
On a high level, Actor Toolkit components perform the following steps:
ActorRef
makes a call to its!()
function.ActorRef
hands over the message to the dispatcher.- Dispatcher enqueues the message into the mailbox.
- Dispatcher creates an
executorService
(Executor). - Dispatcher creates a mailbox thread—
mbox
. - Dispatcher makes a call to the
execute()
function ofexecutorService
:
executorService.execute(mbox)
- The
executorService.execute()
method invokes the mailbox'srun()
function:
mbox.run()
- Mailbox's
run()
function dequeues the message. - Mailbox's
run()
function hands over that message to the actual Actor instance or object. - Now, finally, the real Actor instance processes that message and does the necessary job.
MessageDispatcher
The MessageDispatcher...