Créer un site internet

RMI Callback

 RMI Callbacks

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 service

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. 

Server application:

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.

2. TemperatureMonitor 

Output:

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.

Screenshot from 2019 03 06 11 39 01

This is the link for the source code:

Client: https://github.com/MarquiseG/Temperature_Monitor_RMI_Callback_Client_V2

Server:  https://github.com/MarquiseG/Temperature_Monitor_RMI_Callback_Server_master_V2

References:

Michael Reilly,  David Reilly. Java™ Network Programming and Distributed Computing.  Addison-Wesley Professional, 2002.

Ian F. Darwin. Java CookbookO'Reilly Media, Inc., 2001

 

Comments

  • Mihai
    • 1. Mihai On 02/04/2020
    The code does not compile for some reason.
    • mkaroune
      • mkarouneOn 06/04/2020
      I have just tested and it works. Please add the compile error in the comment. I have done some updates too. They are not relevant to any error

Add a comment