• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

2 questions on rmi

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
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 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
 
There is no greater crime than stealing somebody's best friend. I miss you tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic