This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Distributed Java and the fly likes 2 questions on rmi Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "2 questions on rmi" Watch "2 questions on rmi" New topic
Author

2 questions on rmi

walid aly
Ranch Hand

Joined: Nov 06, 2002
Posts: 38
Dear Friends
i have 2 questions
1-is there is any way the rmi server can know that a certain a client is connected and then know when it leaves.
i want to implement a method that close thee server but i just want to check that no more clients are connected..
2.a more simple question
interface x extends Remote
{public void m () throw RemoteException
}
////////////////////
class c extend uni... implement x
{
public void m() throws Remote Exception{}
}
y do we always make the class that implement a remote interface always throw remoteexecption in the implemented methods, lthough this will force noone to catch them

thanks
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by walid aly:
1-is there is any way the rmi server can know that a certain a client is connected and then know when it leaves.
Check out the java.rmi.server.Unreferenced interface. If your Remote object implements this interface, RMI will call the unreferenced() method when it finds that no more remote references to the object exist. In some ways, it's like a remote version of finalize(). Beware that an entry in the RMI registry is a remote reference---as long as the object is in the registry, unreferenced() will not be called.
If you need immediate notification, consider making clients call a close() method or similar.
2.a more simple question [...] y do we always make the class that implement a remote interface always throw remoteexecption in the implemented methods
We don't. The classIs a perfectly valid implementation of the interface X you listed above.
The method in X needs to throw RemoteException because the RMI transport mechanism can throw it. So while your object will never throw RemoteException, the stub object that clients use can definitely throw RemoteException when there is some type of RMI problem (e.g. networking problems, or marshalling problems if your classes get out of sync).
- Peter
 
 
subject: 2 questions on rmi