• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: Constructor got some clue, please review

 
Yuan Ye
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I got some clues after data mining for a while.
I have made up a design overview of the data access. Please correct me if something wrong. Thanks.
I will have a Database class which will implement all the methods of DBMain interface, including lock, unlocking use Max's vector method.
I will create a new Database instance for each client. However I will only use a single thread of class DataHelp to do all the read/write of the db file, in all the database instances, I will force them to call the single thread of DataHelp to read/white. I will have to synchronize all the methods of DataHelp and Database.
Is that enough? Please give me some comment. Thanks
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Peter,
This is sounding like a reasonable start.
You may want to think about how you ensure that only the client who locked a record can then modify/delete/unlock it. When you work that out, you may decide to use some other collection.
If you have an instance of Data class for each connected client, why would you synchronize any of the Data class methods?
Regards, Andrew
 
Yuan Ye
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Andrew;
Thank you very much for your reply. You are right, I also don't understand why do I need to synchronize my data class method if I create an instance for each client. I thought so just because Max's book's example seems do so and the book claimed that it use a design of an instance per client. Are you saying that the example use an instance for all remote clients? Is that a simpler design compared to multiple instances of data class? Which one is perferable? Thanks
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Peter,
I believe Max's provided code creates one instance of DVDDatabaseImpl which is used by all connected clients. You should look at Max's code yourself and confirm this.
Which one is perferable?

That is not a black and white question. There are good and bad points for either implementation. Which one is preferable depends on a number of factors, including:
You have to decide what is meant by the instructions that you must implement "Network server functionality for the database system". The Data class has "lock", "unlock", "modify", "add" .... methods. Does the instruction above mean that you have to implement network functionality for all of these methods? Or do you only have to provide network functionality for the business methods that you will be using to provide access to the database?
How do you insure that only the client that has locked the record may update it and unlock it? To some extent this may depend on your lock() method signature (and there are multiple lock method signatures, so there is no one answer for that). This may also depend on your answer to the previous paragraph.
How important is performance / scalability to you?
All of these impact which choice is right for you.
Regards, Andrew
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic