This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
In the URLyBird project, the requirements specify an interface that includes lock(recNo), unlock(recNo), and isLocked(recNo).
The way I'm implementing things, I don't see why the lock methods are required. Can someone please explain?
First, it looks like only update() and find() are even needed by the application. Obviously these methods are synchronized so that the file pointer is not disturbed while seeking/reading/writing. Now, assuming update() always checks the "owner" field before overwriting, then I've guaranteed not to overbook on top of another reservation. Therefore, why is lock needed? My synchronized methods ensure only one update() runs at a time anyway.
The other problem is that lock() doesn't have a parameter to specify the client requesting the lock. I can't use thead information here because a client can connect to any server thread.