File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Providing multiple Data instances on RMI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Providing multiple Data instances on RMI" Watch "Providing multiple Data instances on RMI" New topic
Author

Providing multiple Data instances on RMI

Cleverson Schmidt
Ranch Hand

Joined: Feb 17, 2004
Posts: 55
Hi

Initially I started my project providing just one Data object to all clients. But I started to have problems with multiple clients accessing the same RandomAccessFile object(through a Services fa´┐Żade). The problems are caused by file pointer changes leading to unexpected results. To solve this problem the first idea I came up with was syncronizing on the RAF, but I consider this approach a little bit dangerous as I'm already syncronizing on a map object which holds the locks. My project could easily end up on a dead lock. Therefore I gave up the syncronizing on RAF solution and now I'm starting to think in providing a Data instance to each client. This will certainly solve the multiple RAF accesses problem as each client will have its own Data instance and so a file pointer. But here comes the problem. How can I provide multiple Data objects, one per client, on my RMI solution?

I have an interface exposing my business methods to be accessed by remote clients:

The realization of this interface is the remote object implementation:


This class performs its task delegating the calls to a local ServicesImpl object reference which is an attribute of RemoteServicesImpl. The ServicesImpl class is the class which holds a reference to a Data object. So, by using the RMI infrastructure, multiple client requests are handled automatically, each client request has its own thread, but the remote object is always the same and so is the Data object. Is it possible to provide a new remote object (RemoteServicesImpl ) to each client? Or all clients are handled by the same object? How can I provide one Data object to each Client?

Thank you in advance

Best Regards
Cleverson
Arun Subramanian
Ranch Hand

Joined: Oct 30, 2002
Posts: 47
Hi Cleverson-
Therefore I gave up the syncronizing on RAF solution and now I'm starting to think in providing a Data instance to each client. This will certainly solve the multiple RAF accesses problem as each client will have its own Data instance and so a file pointer.

This might not be a feasible solution for large number of clients (leading to large number of RAF instances) because of the OS limits on file descriptors and which has been mentioned atleast a few times in this forum.

Is it possible to provide a new remote object (RemoteServicesImpl ) to each client? Or all clients are handled by the same object? How can I provide one Data object to each Client?

You might want to use an RMIFactory that you register w/ the RMI registry and which in turn hands off the RemoteObject (and the DataAccessObject) on a per client basis. The following link which has been passed around quite a bit gives a nice description of the Factory Pattern as it would apply to RMI.
RMI Factory Pattern

Thanks,
Arun.


SCJP 1.4, SCBCD 1.3, SCWCD 5.0, SCJD B&S 2.3.1 (in progress)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Providing multiple Data instances on RMI
 
Similar Threads
Design questions
nx:All of URLy Bird1.1.3 about record lock
All of URLy Bird 1.1.3 how to use the same GUI and Data in alone or netword client
nx:All of URLy Bird 1.1.3 about interface extends multiple interface
B&S Stub errors running in network client mode