This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Server Design Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Server Design" Watch "Server Design" New topic
Author

Server Design

Terry McKee
Ranch Hand

Joined: Sep 29, 2000
Posts: 173
I see that many people are associating a single Data object with a Server...using the singleton pattern. I am confused by this. Shouldn't different client's be able to use different datasource's simultaneously?
Marco Barenkamp
Ranch Hand

Joined: Aug 27, 2001
Posts: 94
Hi,
due to the fact, that the server is a remote Server,
it will always be a singleton because every client
will lookup the same server instance.

Marco Barenkamp<br />_ _ _ _ _ ________________________ _ _ _ _ _ <br />L M I N T E R N E T S E R V I C E S AG<br /> <br />Head of Software Development<br /> <br /> <br />BEA Certified Enterprise Developer<br />Sun Certified Programmer for the Java2 Platform<br />Sun Certified Web Component Developer for the Java2 Platform<br />Sun Certified Developer for the Java 2 Platform <br />Sun Certified Business Component Developer for the Java 2 Platform <br />Sun Certified Enterprise Architect for the Java 2 Platform Enterprise Edition<br /> <br />LMIS AG
Terry McKee
Ranch Hand

Joined: Sep 29, 2000
Posts: 173
I understand that the server should only have 1 instance, but shouldn't the server contain references to multiple Data references?
Example:

Client A -> connects to -> Server A -> connects to Data Source A
Client B -> connects to -> Server A -> connects to Data Source B

How are people approaching this issue?
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
I agree completely with Terry. Singleton is one of the most abused patterns and here, as so often, completely inappropriate. Come on, how often have you used a database with exactly one table?
- Peter
Jack Zhang
Greenhorn

Joined: Sep 06, 2001
Posts: 5
A single datasource does not necessarily mean only one table. If you allow multiple objects to open the same file, how could you provide record locking?
-- Jack
Terry McKee
Ranch Hand

Joined: Sep 29, 2000
Posts: 173
<code>
A single datasource does not necessarily mean only one table. If you allow multiple objects to open the same file, how could you provide record locking?
</code>
My initial thought about how to approach this is basically to have a server that contains some kind of collection that holds references to Data objects and the canonical paths to those datasources. When a client connects with the server the collection is checked to see if the passed file is already established within the collection. It doesn't have to be more complicated than that. I am not going to add any kind of timing out feature if a client gets disconnected from the server without closing first. But I really think that it is an important design decision that shouldn't be overlooked.
Terry McKee
Ranch Hand

Joined: Sep 29, 2000
Posts: 173
One item that I might add is that the collection that contains references to the canonical path of the datasource as well as the reference to the datasource would also have to have a count of client's referencing it. This is so that if 2 clients are pointing to the same data reference and client 1 closes the collection still maintains a reference to the datasource for client 2.
mitchner green
Greenhorn

Joined: Sep 18, 2001
Posts: 21
Terry, I considered that also. I thought about creating different instances of the Data classes, different instances of the Lock class and so on. Then I thought about all the complication I was adding to meet that requirement. ugh. Plus trying to test that would be a pain.
I went back and re-read the assignment and decided not to deal with that issue at all. There is no requirement stating we have to. I think it is "out-of-scope".
When my server is running, a client connects to whatever file the server is using. A network client can't choose a different file.
Of course, when running in "stand-alone" mode, or when starting the server, a file can be chosen.
That is what I decided.
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by Jack Zhang:
A single datasource does not necessarily mean only one table. If you allow multiple objects to open the same file, how could you provide record locking?
Multiple objects should not open the same file. What I object against is everything with the words "Data" and "Singleton" in one sentence. Data implements a table. If you make Data a singleton, you are making an architectural mistake that may be hard to fix later. Even if the current implementation supports no more than one table, don't do it.
- Peter

[This message has been edited by Peter den Haan (edited September 19, 2001).]
Terry McKee
Ranch Hand

Joined: Sep 29, 2000
Posts: 173
Mitchner,
So in your design clients would be able to choose the filename if they were in local mode OR the host and port if they were in remote mode...interesting. I assume that you have some kind of property that tells the server on startup where to point for the datasource?
mitchner green
Greenhorn

Joined: Sep 18, 2001
Posts: 21
At server start-up (or local mode startup) the filename ("db.db") is one of the arguments. Actually, I think my design will support one server using db.db on one port while another server uses another filename on another port.
I say "I think" that is supported because I haven't tested that scenario. Maybe I'll give it a try and see what happens...
My server arguments are: database file name, host name, port #. "default" can be entered for host and port to use 127.0.0.1 and 1099. If only one argument is provided, the server and client both start in that VM.
On the client the arguments are host and port only. Again, "default" can be entered to connect to 127.0.0.1/1099.
vladimir levin
Ranch Hand

Joined: Dec 19, 2000
Posts: 45
Data is not really a table. Data is a class which implements
database operations of the read, create, update, delete
variety. It is like some of the API's that you'd see in the
1980's in my opinion, like clipper. Of course a real database
system will not just provide methods like this, it would
have a relational database language -- SQL. Anyway, my point
is that in theory the Data class could perform operations
on multiple 'tables'. There should be only one instance of
the Data class on the server, and all client threads should
concurrently execute methods of the Data class. That being said, one does not
*have* to implement the Data class as a
singleton. It is reasonable, I think, to
just create one instance of it in the server.

Originally posted by Peter den Haan:
Originally posted by Jack Zhang:
[b]A single datasource does not necessarily mean only one table. If you allow multiple objects to open the same file, how could you provide record locking?
Multiple objects should not open the same file. What I object against is everything with the words "Data" and "Singleton" in one sentence. Data implements a table. If you make Data a singleton, you are making an architectural mistake that may be hard to fix later. Even if the current implementation supports no more than one table, don't do it.
- Peter

[This message has been edited by Peter den Haan (edited September 19, 2001).][/B]


[This message has been edited by vladimir levin (edited September 21, 2001).]
Terry McKee
Ranch Hand

Joined: Sep 29, 2000
Posts: 173
A couple of things,
First, I agree with Vladimir that the Data class should not be a Singleton. I don't think that the server should be a Singleton either. It just doesn't make since. If you want to programatically start two instances of servers up at the same time it should be fine. Either they point to differend Data instances OR 1 server will throw an exception if it is trying to point to the same Data instance.
Second to Mitchner,
You wrote:
My server arguments are: database file name, host name, port #.
Perhaps I just don't understand. I can understand that you pass the file name to the server. But the host name and port number would be passed from the client. Wouldn't it?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Server Design