I am building a distributed application with Java RMI.
Whenever an agent register to the server, the server does some calculation (e.g, adds the agent to an array). And the agents keep sending liveliness messages to the server.
What I want is that whenever an agents stops sending this message or the connection gets lost, the server notice that and recalculate (e.g, deletes the client from the list)
What is the best way to do this?
I saw some solutions ping the clients or use multi-threads. Any advice is appreciated
Have your server issue each client with a unique remote object, say a remote session for example, that implements Unreferenced
, and have the unreferenced()
method implementation implement the logic you require.
NB There isn't really such a thing as 'loses connection' in RMI. Its underlying connections come and go all the time, subject to connect pooling, and at the API level there is no connection at all.