A common technique used in event-driven programming is the callback. Rather than routinely pinging the server for information, we would like our client to change its on-screen state information only when the server has new information to report. An RMI callback occurs when the client sends a remote reference (proxy) to another service (server), and the server calls methods on the client's reference whenever it is needed.
RMI Callback service
As an example for RMI callbaks, a temperature service is implemented. The server supplies information about the temperature. The temperature monitor (client) registers with the temperature service (Server). When the temperature does change, a callback is made, notifying registered client references.
1. TemperatureServer interface's methods are implemented by the Server used by the client application (Monitor) to register or remove a listener and to get the current temperature.
2. TemperatureListener interface's method is implemented by the client application used used by the server application to notify the client when the temperature is changed.
3. TemperatureServerImpl is the Server application implementation.
Client (Monitor) application:
1. Add the interfaces TemperatureServer and TemperatureListener.
1. Start the Server application.
2. Start the Monitor (Client) application. The monitor displays the current temperature then each time the temperature is changed on the server, the new value is displayed in the monitor.
This is the link for the source code: