Modifying Akka Library

In an academic project, I have to add a modified version of send message function implemented as ! in Akka. In this new function, I want to block and prioritize sending some messages.
As you know ! function has been overridden in a lot of classes in the ActorRef file.
I want to know where to put my function and where to simply override it with an empty body. My first try was on LocalActorRef class which is private so I could not use my function in the test app. Actually the jar library that I exported does not contain this function usable.

Doing that by globally changing send/! sounds like a pretty bad idea. Are you aware about the priority mailbox which already exists?

thanks a lot! no I did not know about priority mailbox. but where can I implement the blocking logic? To be more specific on my project, my application has a FSM and actors and their messages change the application overall state. with known prerequisites we have to block sending some messages. to know these prerequisites we have to have a record of which messages are sent and delivered to the receiver(not blocked or stashed in mailbox).

In general blocking on message interchange a bad idea and will sacrifice a large part of what the actor model gives you and risk causing thread starvation and deadlocks in your application. I strongly recommend that you reconsider that part and read up on how non-blocking “wait” for async operations is usually done.

If you understand the consequences and anyways want to risk shooting yourself in the foot you can block on a request-response message interchange you can use the ask variation that returns a Future[Response] or CompletionStage<Response> (see ) and then block on completion of the future/completion stage.

Yes, I have used Future in my implemented function and I think I misrepresented the idea by using “blocking”. The goal is not to block the Actor but to prevent sending a message upon receiving certain messages. When sending a message an actor should check the Application state and when receiving one it has to sync and change its state. I have used Futures to keep track of which of the sent messages are delivered.
Anyways if I had to insistently implement a new send function is there a possible way?