• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Locking with a cookie

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Got a question regarding locking with a cookie. Here is an abstract from SUN's requirement:



My intention is to follow Andrew's book. Creating a unique object (in this case Data class) for each connected client. By doing so, actually I can ignore the long cookie and just use the unique instance of my Data class to identify the client for locking/unlocking (correct me if I am wrong).

However, the code above has a comment "Releases the lock on a record. Cookie must be the cookie". Well... the word "must" terrifies me

Is it possible for me to do away with the long cookie and of course, state a proper argument inside my choice.txt?
 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,


Is it possible for me to do away with the long cookie and of course, state a proper argument inside my choice.txt?



I think that would almost certainly rule you out of the game. The interface provided is not the best designed one, but you have to work with it. I am pretty sure changing method signatures here will automatically fail you.

Cheers, Jared.
 
Shan Jun Hao
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about providing an adapter... overriding the method? I remember I saw an argument on this issue somewhere here, but I couldn't find it now.
 
Jared Cope
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Originally posted by Shan Jun Hao:
How about providing an adapter... overriding the method? I remember I saw an argument on this issue somewhere here, but I couldn't find it now.



There is nothing to stop you wrapping that interface (and Data.java) in some other object and using that other object for database access by the client. But I think the key is that you do have to implement the functionality of the interface in a class called Data.java as a minimum.

I suspect Sun will instantiate an instance of this class in a test harness to see if our implementation is correct, hence we must not modify the interface method signatures.

Cheers, Jared.
 
Shan Jun Hao
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok... anyone for those who are interested, I have found a relevant topic:

Should lock methods be callable by the client
 
Shan Jun Hao
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I decide to generate a simple lock cookie:



Well, I think it's fine and can't think of any negative implications on this.

In case I miss out anything... I am welcome to any comments and suggestions.
 
Jared Cope
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Originally posted by Shan Jun Hao:

Well, I think it's fine and can't think of any negative implications on this.



Personally I didn't like the 'Random' aspect of assigning a cookie as it is possible (though unlikely) that two cookies could be the same but associated with different records. Since my design uses a Map to store valid-cookie-to-recNo information I would run into trouble. You may be okay though.

I actually just went for using a long instance variable and just increment it each time I want a new lock cookie. I am guaranteed unique-ness of cookie then for what I consider to be the rest of time. For example, if my server has to deal with 1000 locks per second, I am effectively okay for about 600,000,000 years before cookie values wrap around with overflow. I doubt my server would still be up at that time, and if it is -- I'm pretty sure I won't be the one that gets the help-desk call at 6am in the morning.

Cheers, Jared.
 
Shan Jun Hao
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay... I learn something new. I also have a Map to store the recNo and cookie. In short, you just declare a static long right?
 
Jared Cope
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Originally posted by Shan Jun Hao:
In short, you just declare a static long right?



Yes.

Cheers, Jared.
 
Shan Jun Hao
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey thanks so much for the advice!
reply
    Bookmark Topic Watch Topic
  • New Topic