• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading in records

 
Phil Harron
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I was wondering about a design solution related to reading in the data. I'm working on Urlybird version 1.3.1

What I was thinking of doing was this :

I have a Data class and a DataManager class. The DataManager class reads the data in from the file getting header/schema info etc. It also reads in each record and creates an object called Booking for each, setting the location, name, size, rate etc. The DataManager holds these Bookings in a thread safe List of some sort.

When a new client connects the server doles out the Bookings held in the list. Each GUI will have its own Data class, but I thought of making the DataManager a singleton and let it deal with reading/writing and maintaining the list of Bookings. The DataManager will be created when the first client connects.

Can anyone tell me if they see anything wrong in this approach??

Thanks
Phil
 
Denis Spirin
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

When a new client connects the server doles out the Bookings held in the list. Each GUI will have its own Data class, but I thought of making the DataManager a singleton and let it deal with reading/writing and maintaining the list of Bookings. The DataManager will be created when the first client connects.


As I understand, you use socket networking? For RMI such object should be bound to registry before any client connects.

Can anyone tell me if they see anything wrong in this approach??


Sure, there must be only one such object if you use sockets. How do you lock records by the way?
 
Phil Harron
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Denis,

As I understand, you use socket networking? For RMI such object should be bound to registry before any client connects.


I'm going to use RMI - so you mean the Data class would need to be bound?

Sure, there must be only one such object if you use sockets. How do you lock records by the way?


I'm using a private static vector to hold the record Id's of locked bookings.

Thanks
Phil
 
Denis Spirin
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm going to use RMI - so you mean the Data class would need to be bound?


I thought you were talking about DataManager class. Sure, there must be only one instance of Data class, but all you need is just declare it as static in corresponding class which would extend UnicastRemoteObject class. But when you bind some class to registry, only one instance of it will be served to clients (while client requests will be processed by multiple threads).

I'm using a private static vector to hold the record Id's of locked bookings.


Therefore, private static vector will not be thread-safe (as any static field). You shopuld ask yourself: what would happen if 2 (or more) threads would try to book the same record. Even if you use thread-safe collection, it does not ensure that there is no client collision. There are few ways to implement locking, most common is to create LockManager class (which must be singleton) with lock and unlock methods, which will take care of multiple threads by using wait and notify(All). You should search forum to find out how people implemented it.
 
Phil Harron
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Denis, I'll take your advice..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic