• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

find problems in my design/locking mech

 
mike seluker
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Plz read my design and locking mechanism and see if there are any prbs. I've tested it many times and its working fine...
I'm using RMI and I've only one instance of my data class though its not singleton.
Showing user the dialog box to select the mode.
I've modified the data class. I've NetworkData (for network mode) and LocalData (local mode) both are basically modified version of Data. NetworkData extends the Unicast.. Object and implements a RemoteDataBase interface, which contains no methods but extends DataBase interface and implements Remote (kind of marker for remote object).
DataBase interface have all the public methods of Data class.
LocalData implements DataBase..
I've modified lock/unlock signature to include clientId (makes thing easier for me)..Included a bookSeats method in the DataBase interface which clients call to make the seat reservation. This method is not synchronized.
The sequence of execution in it is
Lock -> (synchronized)getRecord ->(synchronized)modify -> unlock(in finally clause)
Now here is the lock code:
synchronized(hashmap) {
chk (in while loop) recordid in hashmap, if it exist wait
otherwise put recordid in the hashmap
}
Unlock Code:
synchronized(hashmap) {
chk whether the same client has locked the record. If yes
unlock it and notifies all else do nothing
}
Now the only prb which i see is that what if records not get unlocked? According to me it can happen only if there is some exception occurs inside the unlock method, otherwise even if client crashes unlock will get executed since client is booking seats thru bookSeats method which is on server side.
Now i'm wondering what exception can occur in unlock method (other than RuntimeException). Is there a need for me to keep a timer and than chk for old locks...
Please comment on this.... I'd appreciate it.
PS: I've not yet coded for record = -1. will take care of this once this got finalized.
[This message has been edited by mike seluker (edited November 21, 2001).]
 
mike seluker
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will anybody going to read and comment on my design / lcoking mech...
ur comments are awaited gurus.......
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>>I've modified the data class. I've NetworkData (for network >>mode) and LocalData (local mode) both are basically modified >>version of Data.
Are you saying you basically made two Data classes, like you copied and pasted and made slight modifications to both versions?
If yes. Don't change the data class, unless you can defend your choice to. In my case I did change the Data class, but only by implementing lock, unlock, and criteriaFind only, and at a minimum.
Instead try making an interface that has all the methods of the Data class. and make those two classes you have implement that interface.
>>Included a bookSeats method in the DataBase interface which >>clients call to make the seat reservation.
This sounds similar to my DataAccessFacade class, which is the class that the client side uses to call methods through. This way the client does not need to know anything of the Data class and corresponding interfaces. It just communicates with the Facade. My Facade only really had about 4 public methods, 4 private methods, none of them where the same names as the Data class. 1. bookFlight, 2. getAvailableSeats, 3. findFlights, 4. fillComboBox.
>>I've modified lock/unlock signature to include clientId (makes >>thing easier for me)..
Really, is it easier for you? How do you get the ID, what distinctly points to your client? If you use the binding of a connection factory into the Registry, and each client will get their own remote connection object, then you know that that object is unique for each client, and in actuality, this connection class should be the class that really handles whether the client can lock or unlock a record.
In my Data class I just have a Hashset that has all the locked records, and has no client identification in it at all.
The unique connection object also has a Hashset of locks that client has, and therefore, only calls the Data classes unlock, when the record you are trying to unlock is in it's own Hashset.

>>otherwise even if client crashes unlock will get executed >>since client is booking seats thru bookSeats method which is >>on server side.
I think bookSeats needs to be on the client side. less network traffic? maybe, maybe not, but in that case you will then need to use the Unreferenced interface to clean up for a crashed client, but that is really easy.

>>Is there a need for me to keep a timer and than chk for old >>locks
A lot of people have used timers and it is a good idea. I mean if you are locking modifying then unlocking in one bookSeats method, then the whole process should be fast, so if say in 30 seconds it doesn't unlock, then something had to have happened, and it is a good idea to remove the old lock. I actually did not do this, but I guess I was lazy.
Hope this helps, and I hope I understood your design, so that my comments are accurate. If not, just ignore me
Mark
 
mike seluker
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>>>Are you saying you basically made two Data classes, like you copied and pasted and made slight modifications to both versions?
If yes. Don't change the data class, unless you can defend your choice to. In my case I did change the Data class, but only by implementing lock, unlock, and criteriaFind only, and at a minimum.
Instead try making an interface that has all the methods of the Data class. and make those two classes you have implement that interface.>>
I've done the same thing what u have written. I mean I made an Interface (DataBase) which has all the methods of DataClass. Now I've two classes NetworkData(Implements RemoteDataBase interface and this interface extends DataBase and Remote) and LocalData( Implements DataBase). Since these two classes implements DataBase interface, Both of them have methods of Data Class and I've modified lock, unlock, criteriaFind method. My understanding is that u have done the same thing. right???
Now copy/paste i'm confused. Can u elaborate on it plz?
>>>Really, is it easier for you? How do you get the ID, what distinctly points to your client? >>>>
I'm using a private int valriable on the server side for unique client Id. Whenever a new client connects to the server, the server increments the variable and return its value to the client. On client side this is a final variable where client store its id.
So every time client call bookSeat method it also passes the clientId which i use in locking/Unlocking.
I've understand ur logic of Connection class ( As i remember there was a discussion on the same issue by u, peter and denise)
But Is my method is wrong I mean its very simple and clear. Can this simplicity be acceptable justification for modifying the lock / unlock signature???
>>otherwise even if client crashes unlock will get executed >>since client is booking seats thru bookSeats method which is >>on server side.
>>>>I think bookSeats needs to be on the client side. less network traffic? maybe, maybe not, but in that case you will then need to use the Unreferenced interface to clean up for a crashed client, but that is really easy.>>>
I need to read and think about this unreferenced interface. I'm a beginner in case of RMI. Can u tell me what happen if I don't use Unreferenced. Since even if client crashes, Unlock method is called and lock held by the crashed client will be removed? Is it like some garbage collection needs to be done. And since I'm not using "Connection" class, Is Unreferenced still req??

>>Is there a need for me to keep a timer and than chk for old >>locks
>>>>A lot of people have used timers and it is a good idea. I mean if you are locking modifying then unlocking in one bookSeats method, then the whole process should be fast, so if say in 30 seconds it doesn't unlock, then something had to have happened, and it is a good idea to remove the old lock. I actually did not do this, but I guess I was lazy. >>>>>
I've given a alot of thought to this.. Now my point is that suppose Client A calls lock. After excution of lock it successfully reads the record (say 20). And now just before calling the modify method , the cpu switches the context. Now this client which is still alive did not get the CPU for say (60 sec which we set for timer) and we remove the lock from record 20. And in the mean time some other client B, calls the book seat method for same record 20 and gets the lock. reads the record and again context swtich and at this point, first client gets the cpu and modifies the records. Now client B gets the cpu and modifies the same record. Won't this lead to data corruption.
plz comment...
Hope this helps, and I hope I understood your design, so that my comments are accurate. If not, just ignore me
Ur comments are accurate and more comments are welcomed...
Mike
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic