Java RMI: How can I restrict RMI method to only be

2019-07-24 07:20发布

问题:

I have an RMI model which uses a thread on each side (Client/Server Side) to maintain a client heartbeat. If the client crashes without unlocking the server, the lock will eventually timeout.

I don't want the user of my client API to be able to call the methods that deal with the heartbeat/lock. However from my understanding of Java RMI, the client and server must implement a common interface which defines all the methods that I want RMI access to, and these methods must be public. Since the interface defines these methods as public, the client methods must also be public, and can not be hidden from the user.

Question:

Is there a way to restrict certain methods that have been exported over RMI so that only the client object itself can call them? In other words, can I make the method act as though it is private on the client side?