• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

How could the RMI server get to know client crashed?

 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As title. When we use the RMI solution, how could a RMI server get to know that one of its client crashed? It seems that a lot of guys at here know the answer. Please help.
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(1) This is not a requirement. (2) java.rmi.server.Unreferenced.
- Peter
 
Lin Feng
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Peter ,
Thank you for your reply. However it seems that the Unreferenced is not strong enough. It will be only called when there are no more clients that reference that object. So it means that if there are still other clients refered to that object , the server will not be notified.
Yes it is true that it is not a requirement. But we all know that we take the test not only for the test. :-) So I want to make it clear. You just give me some hints that I should read the java.rim.server package. Could you give me some other hints?
Regards
Lin
 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Lin,
Make the *client* implement the Unreferenced interface. Let's say the client dies, ~15 minutes later, the RMI runtime will call its unreferenced() method. Put in this method the code you want to execute before the client gets garbage collected...
Do you understand?
/Daniela
 
Lin Feng
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Daniela,
I am sorry that I did not follow you. :-((((((((
My understanding is The unferenced interface is just something based on object reference counter. If the counter is 0 then the method of that interface will be called. You can do some thing such as resource release etc.
You mentioned that I can make the client implements the UnReferenced interface. My understanding for your suggestion is to implement call back objects. Based on that the server can monitor the status of client. Is that your suggestion? If so the client dose not have to implenent the Unreferened interface. If it is not I cannot figure out your solution.
Yes based on the call back solutiion , my question can be answered. However it is at the RMI layer. It is on the application layer. Could you give me a suggestion on the RMI layer?
Thanks
Lin
 
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


But we all know that we take the test not only for the test.


I understand your desire to code this project as complete as it can be. Bear in mind, however, that you may be penalized for the bells and whistles that yo are thinking of implementing.
Eugene.
 
Daniela Ch
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lin,
I didn't understand your question...I will repeat what I said but in different words, maybe this will help...
When a remote object (one that extends Remote) implements the Unreferenced interface, 15 minutes after he crashes, its unreferenced() method will be called.
My understanding for your suggestion is to implement call back objects
I dont know if the unreferenced() method is what you call a call back object, but this is the only method you need to implement in your client if you implement Unreferenced.
Based on that the server can monitor the status of client.
yes
If so the client dose not have to implenent the Unreferened interface.
Do you understand now why the client should implement the Unreferenced interface?
There is a lot of threads that talk about the Unreferenced interface. Start by reading this very interesting one:
https://coderanch.com/t/180156/java-developer-SCJD/certification/Unreferenced-interface-should-not-used
Then if you decide that you still want to use Unreferenced, make a search on "unreferenced". By reading people's questions/answers you will learn a lot...
/Daniela
 
Lin Feng
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Daniela,
Thank you for your help. According to your suggestion , I just read a few post for unreferenced interface. Base on your answer and the other post I just figured out how to use the unreference interface to find out if client crashed.

step 1 ) create a class which implements the unreferenced on server side
step 2) create one instance of the class for each client and pass the reference to clients.

If a client crashed , the unreferenced of a corresponed object will be called and the server can get to know that a client crashed.

Is my understanding correct ?

Do we have other solutions for it?
Regards
Lin
 
Daniela Ch
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lin look what i have found for you :
Any remote object that implements java.rmi.server.Unreferenced interface can get immediate notification via the unreferenced() method as soon as the server does not have any valid references to it. The following code snippet demonstrates how:

I got it from an RMI faq http://jguru.com/faq/printablefaq.jsp?topic=RMI
/Daniela
 
Peter den Haan
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by LIN FENG:
Thank you for your reply. However it seems that the Unreferenced is not strong enough. It will be only called when there are no more clients that reference that object. So it means that if there are still other clients refered to that object , the server will not be notified.

Which is perfectly fine if each client gets its own object. That solves your "how do I track client identity" problem at the same time. If you didn't know you had this problem, examine the javadoc for Data.unlock() (This is also what Lin was suggesting).
Unreferenced notification has inevitable delays. If the client simply "forgets" about the remote object by releasing all references to it, you'll have to wait for the garbage collector to do its job. If the client crashes, the remote object lease has to expire first (10 mins, but can be changed using a system property). So the preferred method of dispensing with a remote Data remains a call to close().
Personally, I did implement cleanup using Unreferenced, not because I thought it was in any way required but because it added a very useful feature with just 3 lines of code (including method header and closing brace, but not counting comments).
- Peter
 
reply
    Bookmark Topic Watch Topic
  • New Topic