aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes How to get client ID Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "How to get client ID" Watch "How to get client ID" New topic
Author

How to get client ID

Kevin Li
Greenhorn

Joined: Sep 25, 2001
Posts: 21
In my design, I choose RMI implement.When I prepare to design my LockManager, I meet a trouble that I don't know how go get client ID. I am not planing to use Thread.currentThread() method for the client ID, as there is no guarantee that RMI always use the same thread for individual client. So what is the better way?
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Kevin,
There are multiple threads here on this subject. The best way to accomplish it is to use a connection factory and the principle of object identity. If all clients are issued a unique connection via a connection factory, then you already have a client id, namely "this". So with that in hand, when the client calls lock(record) on your remote data interface, then your connection object calls lockManager.lock(record, this). Then your lockManager simply maps locked records to unique connection objects.
Some have opted to issue unique ints or longs using a static member somewhere in their design to keep up with the next id or by using hash codes. You can do it this way but it is more difficutlt to design and more likely to fail.
Hope this helps
Michael Morris


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Jim Bedenbaugh
Ranch Hand

Joined: Nov 09, 2001
Posts: 171
Originally posted by Michael Morris:
Hi Kevin,
There are multiple threads here on this subject. The best way to accomplish it is to use a connection factory and the principle of object identity. . .
Michael Morris

Michael,
I have read lots of the threads on record locking and all the different techniques for tracking a unique id with each record.
My question is, why even concern oneself with who locked a record? Tracking who locked a record is not a requirement. All we really care about is whether a record is locked or not. I know in more sophisticated systems, tracking who locked a record and displaying it back to the user is de riguer, but why bother? I mean, in reality, this database would be replaced in short order by a real database with real locking capablities, etc.
Thoughts?


Regards,
Jim
SCJP, SCJD, SCWCD, SCEA Part I
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451

Originally posted by Jim Bedenbaugh:
My question is, why even concern oneself with who locked a record? Tracking who locked a record is not a requirement.

Actually there is a requirement which states that if an object attempts to unlock a record for which it does not own the lock, then the attempt to unlock the record should be ignored.
Michael Morris
Jim Bedenbaugh
Ranch Hand

Joined: Nov 09, 2001
Posts: 171
Originally posted by Michael Morris:

Actually there is a requirement which states that if an object attempts to unlock a record for which it does not own the lock, then the attempt to unlock the record should be ignored.
Michael Morris

Ooops!
How the heck did I miss that?
Well, not to worry. I can add that in pretty easily tomorrow - my hashtable can save the "this" in the value portion of the entry.
No big deal, but I sure am glad you mentioned
this! Makes me wonder what else I mighta missed. . .
Outta curiosity, I wonder how much would have been deducted if I hadn't done this?
Kevin Li
Greenhorn

Joined: Sep 25, 2001
Posts: 21
Originally posted by Michael Morris:
Hi Kevin,
use a connection factory and the principle of object identity. If all clients are issued a unique connection via a connection factory, then you already have a client id, namely "this".
Michael Morris

Michael Morris,
Would you mind describing how to build a connection factory further.
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451

Originally posted by Jim Bedenbaugh:
Outta curiosity, I wonder how much would have been deducted if I hadn't done this?

You probably would have lost some points on locking, but I doubt that in itself would have resulted in a failure.

Originally posted by Kevin Li:
Would you mind describing how to build a connection factory further.

To create a connection factory in RMI, you create a class which extends UnicastRemoteObject (or Activatable) which will contain a method named something like getConnection or getDataAccess and will be bound to the RMI registry which will return a stub to an implementation of your remote Data interface. That implementation will also extend UnicastRemoteObject but will not be bound to the RMI registry. Now each client has his own personal remote connection. For more information on the Factory Pattern check with Design Patterns by Gamma, et. al.
Michael Morris
Kevin Li
Greenhorn

Joined: Sep 25, 2001
Posts: 21
I got it, thank you for your help,Michael Morris.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get client ID