How it works...
As you know, a mailbox uses a message queue, and we need to provide a custom implementation for the queue.
In step two, we define a class, MyMessageQueue, which extends the trait MessageQueue and the implementing methods.
We want our actor to receive messages from only those actors whose name is MyActor, and not from any other actor.
To achieve the aforementioned functionality, we implement the enqueue method, and specify that the message should be enqueued if sender name is MyActor, otherwise ignore the message.
In this case, we used ConcurrentLinkedQueue as the underlying data structure for the queue.
However, it is up to us which data structure we pick for enqueing and removing messages. Changing the data structure may ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access