aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes RMI factory pattern - Where will the Database file be? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "RMI factory pattern - Where will the Database file be?" Watch "RMI factory pattern - Where will the Database file be?" New topic
Author

RMI factory pattern - Where will the Database file be?

Joel Mata
Greenhorn

Joined: Oct 31, 2009
Posts: 25

Hi All,

I'm trying to apply the Factory Pattern to the RMI but is seams that by doing it the getClient() brings a RMIServerImpl to the client. Which seams to be making the database file to be also managed by the client.

What am i doing wrong?
Can this design pattern be implemented in this case, where a file in the server is to be handled?

My design was based on:
http://www.itec.uni-klu.ac.at/~harald/ds2001/rmi/factory/factory2.html


ITIL V3, SCJP, Spring Core v3 and Going for the OCJMD
Rehan Zahoor
Ranch Hand

Joined: Jun 19, 2012
Posts: 34

The RMI creates a skeleton and a stub. RMIImpl would be on the server the client would just have a shadow of it. So factory pattern works alright.


**OCP, Java SE 6 Programmer**OCM, Java SE 6 Developer**
Joel Mata
Greenhorn

Joined: Oct 31, 2009
Posts: 25

Rehan Zahoor wrote:The RMI creates a skeleton and a stub. RMIImpl would be on the server the client would just have a shadow of it. So factory pattern works alright.

I undestand, but then
in this context the database is not shared among other clients, is this acceptable?
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5534
    
  13

Joel Mata wrote:is this acceptable?

Of course! That's what RMI is all about.

And if you think about it? If the database is shared among the clients, what would happen with the database file? This file only exists server side...


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Joel Mata
Greenhorn

Joined: Oct 31, 2009
Posts: 25

Roel De Nijs wrote:
Joel Mata wrote:is this acceptable?

Of course! That's what RMI is all about.

And if you think about it? If the database is shared among the clients, what would happen with the database file? This file only exists server side...


Hi Roel, could you explain yourself again?
I understand RMI but with the RMI factory design pattern the remote call brings all server implementation and then it opens the file on the client. The idea of having multiple clients where each one has his own database file seams odd to me.

I was more expecting having the client calling methods locally but being run on the server, that is that all clients would share the same database file.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5534
    
  13

How can a file be opened on the client if this fily is physically residing on the server
Joel Mata
Greenhorn

Joined: Oct 31, 2009
Posts: 25

Roel De Nijs wrote:How can a file be opened on the client if this fily is physically residing on the server


yes, thats my problem :S. The factory is returning the RMIServerImpl which then creates a DB on the client. If i disconnect the server the client keeps working.

What data could i provide to help you guys to track what am i doing wrong?
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5534
    
  13

With a RMI factory I would expect something like:


On the server you'll (re)bind an instance of your factory to the registry:


And on the client you'll do something like to retrieve a client to call the methods on:


If you have a similar setup, I think you implemented the RMI Factory Pattern correctly.

Disclaimer: I created these code snippets without an IDE, so there might be a few typos.
Joel Mata
Greenhorn

Joined: Oct 31, 2009
Posts: 25

Roel De Nijs wrote:With a RMI factory I would expect something like:



HI Roel. The problem was that my RMIServerImpl was not extending UnicastRemoteObject, instead was implementing Serializable.
Solved! Thanks.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5534
    
  13

Glad to hear I was able to help!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RMI factory pattern - Where will the Database file be?