This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

2 questions on rmi

 
walid aly
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic