aspose file tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Locking Mechanism. Please help Max, Peter, Eugene,Mark Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Reply Bookmark "Locking Mechanism. Please help Max, Peter, Eugene,Mark" Watch "Locking Mechanism. Please help Max, Peter, Eugene,Mark" New topic
Author

Locking Mechanism. Please help Max, Peter, Eugene,Mark

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Couple of days ago I had posted my design and got good feedback. However the way things are working I do not think my clients are getting unique remote objects.
The flow of things are as follows.
(*) My Clients looks up the registry to find a RemoteDataFactory object.
(*) That stub is retrieved from the registry. This is my RemoteDataFactory. RemoteDataFactory inherits from UnicastRemoteObjects.
(*) From this factory my clients pass the location of the db.db file. The factory has a mapOfRemoteObjects. It checks if a remote object was created for this location if it had then return the same object otherwise create a new RemoteObject and put it in the map.
(*) The remoteObject also inherits from UnicastRemoteObject it contains LockManager and Data object.
(*) My client calls remoteObject.lock(rowID). This method in turn calls lockManager.lock(rowID, this);
(*) LockManager has a Map, LockManager's lock method does the following before putting it in the map

In my second condition !(mapOfLocks.get(aRow) == remoteData) this always yields false and so no clients have to wait.
So Now it is making me think that remoteData is not unique. When I do a toString on the stub for both clients it returns the following

I do not know what is going on. Is my design wrong. Why am I not getting unique remote objects? Do I have to do something special?
I do not want to put my whole design and I apologize if it is confusing. Please let me know if you need more info on a particular aspects.
I really appreciate all y'alls help!!
-Amish
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937

(*) From this factory my clients pass the location of the db.db file. The factory has a mapOfRemoteObjects. It checks if a remote object was created for this location if it had then return the same object otherwise create a new RemoteObject and put it in the map.
Why am I not getting unique remote objects?

You have a faulty logic. You should always return a new remote object, it's just that it would wrap the same Data instance and the same corresponding instance of the lock manager if that particular database has already been requested.
Eugene.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi Eugene
You are right. I should not have done it this way. I do not know how I overlooked this. So now I will have two maps one for all the Data instances that I have already instantiated and the other map for all the LockManager. Is this a good idea? Or is there a better way?
Thanks
-Amish
Originally posted by Eugene Kononov:

You have a faulty logic. You should always return a new remote object, it's just that it would wrap the same Data instance and the same corresponding instance of the lock manager if that particular database has already been requested.
Eugene.
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937

So now I will have two maps one for all the Data instances that I have already instantiated and the other map for all the LockManager. Is this a good idea? Or is there a better way?

Perhaps a cleaner approach is to have one map where the database is the key and the array list of two items is the value:
database name --> (Data instance, lockmanager instance)
Eugene.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Thank You very much Eugene!!!
-Amish

Originally posted by Eugene Kononov:

Perhaps a cleaner approach is to have one map where the database is the key and the array list of two items is the value:
database name --> (Data instance, lockmanager instance)
Eugene.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Locking Mechanism. Please help Max, Peter, Eugene,Mark
 
Similar Threads
How to create RemoteData?
ClassCast Exception with RMI
Data Serialization
B&S 2.3.1 - Identifying clients uniquely in RMI
Please help me feel confident with my design ...