How to create a priority based mailbox for an Akka actor [Java]

Hello!

I want to prioritize by message type the order of the messages that will be read from the message queue by an Actor.

For example:

First Int message will be processed.

Then String type message will be processed.

There is a Scala example of exactly the same thing I want to implement in Java:

Can you help please with a Java code example?

I’m not sure what PriorityGenerator was when creating the UnboundedPriorityMailbox in that blog, but it’s just a Comparator in passed to the mailbox constructor.

So make a comparator, create the mailbox implementation and follow the rest of the steps for configuration.