Hi I have a stupid quesiton about my unlock method. My assignment is urlybird 1.3.2. The signature of my lock and unlock method are as follows:
The lock and the unlock methods in ordinary should be pair as follows.
My question is .
If someone invokes the unlock method and the record which is exist is not locked before. Is it need to throw the SecurityException from unlock method or do something else in this case? The scenario is as follows:
(The record is exist, and the cookie is fake.) (I assume someone want to use the function, but he don't know how to use it correctly.) [CODE] cookie = 1; unlock(recNo,cookie) [CODE]
If someone invokes the unlock method and the record which is not exist is not locked before. How to deal with whis case?
(The record is invalid, and the cookie is fake.) [CODE] cookie = 1; unlock(recNo,cookie) [CODE]
I know all this case are came from the programming bug! But I am afraid of there is some trap I miss.
Write ur question in better english, cuz I dont understand what u are asking. If I understand better, then I'll be able to help u. But locking is a VERY delicate issue ! As long as u dont know for sure your locking scheme is perfect, think of it as a bad scheme. Cya [ February 07, 2005: Message edited by: Frank Verbruggen ]
My personal opinion is that an attempt to unlock a record which the process attempting to unlock it did not have a lock in the first place should not lead to an exceptional condition. It should either fall through silently or at most generate a warning flag as a return value. After all, unlocking a record is not a dangerous or highly involved process.
If its about unlocking a record with the wrong cookie, my assignment states:
// 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;
So be sure to implement this correctly. Lots of luck
The choice you have to make is whether a record that is not locked can be replaced, deleted and unlocked. All three of these methods require a cookie. The questions then become "what cookie should I use if the record isn't locked? Does any cookie match? What if another client has it locked?"
I chose to not permit these operations if the record isn't locked, and throw SecurityException, a fatal RuntimeException which indicates a bug in the client code.
Write ur question in better english, cuz I dont understand what u are asking. If I understand better, then I'll be able to help u. But locking is a VERY delicate issue ! As long as u dont know for sure your locking scheme is perfect, think of it as a bad scheme. Cya
Please write your responses in better English, not web-speak, especially when commenting on another's language use. Words such as "ur", "cuz" and "u" may make sense to you, but they can make it very difficult for others to read - especially if English is not their first language. Also, many people with visual disabilities rely on text readers to comprehend web pages. Web-speak short cuts like this can also confuse the text readers.
I agree with Peter's response and solution to your question. Whatever solution you choose, make sure you document your decision. [ February 07, 2005: Message edited by: Paul Bourdeaux ]
“Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.” - Rich Cook
Frank, but what if the cookie is null? (in other words there is no cookie)? No cookie isn't the wrong cookie after all
If your cookie is an Object this would be a good choice for no cookie. Most of the newer assignments declare the cookie as the primitive type long, so you could choose -1 as a null equivalent. I considered that, but chose instead to not allow it.
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop