Forums Register Login

2 questions on rmi

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
 

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
Fire me boy! Cool, soothing, shameless self promotion:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 917 times.
Similar Threads
RMI using Proxy classes
Deigning the MultiServer Environment
The Server
B&S 2.2.2 - Network Layer Query
RMI implementation
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 02:08:10.