aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes NX: [URLyBird] unlock(...) and not locked record 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 "NX: [URLyBird] unlock(...) and not locked record" Watch "NX: [URLyBird] unlock(...) and not locked record" New topic
Author

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

Maksim Golubkow
Greenhorn

Joined: Jun 04, 2003
Posts: 22
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
    Mark Spritzler
    ranger
    Sheriff

    Joined: Feb 05, 2001
    Posts: 17259
        
        6

    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


    Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
    How to Ask Questions the Smart Way FAQ
    Jim Yingst
    Wanderer
    Sheriff

    Joined: Jan 30, 2000
    Posts: 18671
    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.


    "I'm not back." - Bill Harding, Twister
    Maksim Golubkow
    Greenhorn

    Joined: Jun 04, 2003
    Posts: 22
    Mark, Jim thanks for yours replies, so I have to throw SecurityException.
    Regards, Maksim
    Ta Ri Ki Sun
    Ranch Hand

    Joined: Mar 26, 2002
    Posts: 442
    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

    Joined: Jun 04, 2003
    Posts: 22
    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
    Andrew Monkhouse
    author and jackaroo
    Marshal Commander

    Joined: Mar 28, 2003
    Posts: 11509
        
      95

    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


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

    Joined: Jun 04, 2003
    Posts: 22
    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

    Joined: Mar 26, 2002
    Posts: 442
    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

    Joined: Mar 26, 2002
    Posts: 442
    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;
    Rob Pearson
    Greenhorn

    Joined: Jun 12, 2003
    Posts: 19
    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?


    Assignment: URLyBird 1.3.3, using Java 1.4.0_01<br />Status: Designing, Experimenting, Reading.
    Andrew Monkhouse
    author and jackaroo
    Marshal Commander

    Joined: Mar 28, 2003
    Posts: 11509
        
      95

    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
     
    wood burning stoves
     
    subject: NX: [URLyBird] unlock(...) and not locked record