Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Lock container Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Lock container" Watch "Lock container" New topic
Author

Lock container

Kumar Bhaskar
Greenhorn

Joined: Jun 03, 2004
Posts: 5
Hi,

My assignment has the cookie version of the lock-unlock-update-delete methods.

So far I have a static WeakHashMap that stores record numbers as the keys and the cookies (long) as the values. Is this good?

I'm asking because I saw a posting that said cookies are only for security checks and should not be used to identify clients.

Thanks,
K D Bhaskar
[ June 16, 2004: Message edited by: Philippe Maquet ]
Philippe Maquet
Bartender

Joined: Jun 02, 2003
Posts: 1872
Hi Kumar,

To make the discussion easier, could you please give us the link to that thread?

Thank you,

Phil.
Kumar Bhaskar
Greenhorn

Joined: Jun 03, 2004
Posts: 5
Hi Phil,

Originally posted by Philippe Maquet:
Hi Kumar,

To make the discussion easier, could you please give us the link to that thread?

Thank you,

Phil.


Thread # 006857
You say:

Cookies uniquely identify locks granted, not clients, and play the role of a sort of "password" in update() / delete() / unlock().


Thanks
K D Bhaskar
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11525
    
100

Hi Kumar,

Phil is correct in thread 006857, in that using the lock cookie is not guaranteed to identify the client.

Some of the proposals in that thread for what to use as a lock cookie would make it very easy for any client to unlock a record for which they do not own the lock (e.g. if you used the record number as the cookie then it is trivial to unlock a record, likewise if you used an incremental number).

However, if you are using the Random class to generate the cookie, then you are going to get a random number somewhere between 9223372036854775807 and -9223372036854775808. It is no longer a trivial matter to determine a potential cookie for a lock you don't own (unless you use a constant seed for your random number).

So for all intents and purposes, if the same cookie is used in two subsequent calls, then you might want to assume that the same client is calling both methods. There is no guarantee that the same client is calling both methods, but it is a reasonable assumption.

If you want to guarantee that the client who locks the record is the only client who can then modify it or unlock it, then you will need to ignore the cookie as an identification mechanism, and look at an RMI Connection Factory or a Sockets based solution.

(Short answer: you might want to go with the assumption, and make a comment in your design decisions document about why you did not go for a more complex solution ).

Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Kumar Bhaskar
Greenhorn

Joined: Jun 03, 2004
Posts: 5
Andrew,

Thanks.

One more question. I've read postings here that talk about readme.txt. My instructions don't mention any readme file. They ask me to submit a userguide.txt for the database server and gui client.

So userguide.txt = readme.txt or should I submit a readme file too.

K D Bhaskar
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11525
    
100

Hi Kumar,

There are at many different assignments being worked on by different candidates. Some are so similar that it is difficult to work out what the differences are. And some are very obviously different. See the SCJD FAQ for more information about variants of assignments.

The "Fly By Night Services" assignment had a "readme.txt" file. The newer assignments have (I think) a "versions" file and a "choices" file which between them have much the same information. (The readme.txt file also described the file layout, but the new assignments tell you how you must layout your files, so this does not apply to you).

Bottom line: follow your instructions, not anyone else's. So don't bother trying to create a "readme.txt" file if your instructions don't require it.

Regards, Andrew
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Lock container