• 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

NX: [URLyBird] unlock(...) and not locked record

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all, what do you do if the parameter recNo represents a record that was not locked by lock(...) method:
  • throw new SecurityException
  • throw new IllegalStateException with the message "the record is not locked"
  • simple return and do nothing


  • Regards, Maksim
     
    ranger
    Posts: 17347
    11
    Mac IntelliJ IDE Spring
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Well I believe the instructions states that a client that does not own the lock of a record cannot call unlock.
    So basically any call to unlock for a record that is not locked or is locked by a different user, then nothing should happen in that call. You can always throw an exception if you want. However, if you code your application that the only time unlock is called is quickly after lock has been called, then you don't have to do anything. Meaning in your booking method you call lock-read-modify-unlock. Then all calls to unlock will be by the client that locked the record.
    Mark
     
    Wanderer
    Posts: 18671
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I agree with Mark. I don't know for sure about URLyBird, but the Contractors assignment has the following statement in the API for unlock():

    Cookie must be the cookie returned when the record was locked; otherwise throws SecurityException.


    No room for argument there. However check your own instructions to be sure.
     
    Maksim Golubkow
    Greenhorn
    Posts: 22
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Mark, Jim thanks for yours replies, so I have to throw SecurityException.
    Regards, Maksim
     
    Ranch Hand
    Posts: 442
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Originally posted by Maksim Golubkow:
    Mark, Jim thanks for yours replies, so I have to throw SecurityException.
    Regards, Maksim


    Hi again Maksim, are you sure your instructions state what Mark just mentioned?
    because I'm also doing URLyBird, and my instructions do not state this, if yours does please post a snippet of your instructions file, I want to confirm that ours is different,
    Thanks, TQ
     
    Maksim Golubkow
    Greenhorn
    Posts: 22
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi TQ,
    here is my instructions of the unlock method:

    Releases the lock on a record. Cookie must be the cookie returned when the record was locked; otherwise throws SecurityException.


    What exception should be thrown if the record was not locked before? My first implementation has thrown IllegalStateException with the message "The record was not locked by lock(...) method!" to force the user of my API to write good code.
    Regards, Maksim
     
    author and jackaroo
    Posts: 12200
    280
    Mac IntelliJ IDE Firefox Browser Oracle C++ Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi Maksim
    With the instruction you mentioned, you should throw SecurityException.
    TQ: This is in the comments before the unlock method signature in the interface definition in version 1.1.1 of UrlyBird:

    Regards, Andrew
     
    Maksim Golubkow
    Greenhorn
    Posts: 22
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks Andrew, I'm doing version 1.2.2 and there is no RecordNotFoundException in the throws clause.
    Regards, Maksim
     
    Ta Ri Ki Sun
    Ranch Hand
    Posts: 442
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi guys, I'm doing version 1.3.1, and heres my snippet


    // Releases the lock on a record.
    public void unlock(int recNo) throws RecordNotFoundException;
    // Determines if a record is currenly locked. Returns true if the
    // record is locked, false otherwise.


    I got that assignment after they mailed me to get a new download because I was missing the db file, I then planned my project for a week before starting to code, and I got a new download then as well, and my file had not changed, so I started coding to that spec and wont even think about getting another download at this point, too risky, so this is what I'm submitting.
    Quite strange that I also get 80 marks for locking, I hope I dont lose marks for having not implemented things they never asked for.
     
    Ta Ri Ki Sun
    Ranch Hand
    Posts: 442
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I also still have my 1.2.1 instructions file and unlock has the following


    // Releases the lock on a record. Cookie must be the cookie
    // returned when the record was locked; otherwise throws SecurityException.
    public void unlock(long recNo, long cookie)
    throws SecurityException;

     
    Greenhorn
    Posts: 19
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi,
    I'm doing 1.3.3 of URLyBird and my unlock is

    // Releases the lock on a record.
    public void unlock(int recNo) throws RecordNotFoundException;


    I've got a question on the lock method:

    // Locks a record so that it can only be updated or deleted by this client.
    // If the specified record is already locked, the current thread gives up
    // the CPU and consumes no CPU cycles until the record is unlocked.
    public void lock(int recNo) throws RecordNotFoundException;


    I assume this should have some call to wait() in it, but this throws an InterruptedException. Since I can't just declare it as thrown, because that changes the interface, what should I do with it? Re-throw as a RecordNotFoundException? Just ignore it (not sure if I can)? Fall over in a screaming heap and exit the server!
    Any thoughts?
     
    Andrew Monkhouse
    author and jackaroo
    Posts: 12200
    280
    Mac IntelliJ IDE Firefox Browser Oracle C++ Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    G'day Rob,
    Personally I would catch it, then rethrow it as a RecordNotFoundException, with a suitable reason.
    If you are using JDK 1.4 you can nest exceptions, so you could nest the InterruptedException within the RecordNotFoundException.
    Regards, Andrew
     
    She still doesn't approve of my superhero lifestyle. Or this shameless plug:
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic