File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Lockmanager as inner class 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 "Lockmanager as inner class" Watch "Lockmanager as inner class" New topic

Lockmanager as inner class

Darien Chambers

Joined: Oct 26, 2002
Posts: 4
I've been reading this great forum and using it as a reference for my assignment. I wanted to get some comments about the design I'm considering. For the most part it should be pretty familiar as it combines the stuff I've read from books with things I've read here.
I'm going to create a Connection Factory which will handle whether we are going in network mode or local mode.
In local mode, the Connection Factory creates an instance to a DatabaseAdapter object. This object is just a simple facade to the Data class provided by Sun.
In remote mode, the Connection Factory looks up the remote object DatabaseRemoteImpl which implements the DatabaseAccess interface and extends Remote. The DatabaseRemoteImpl has all the remote methods defined.
When the controller wants to modify a record across the network, it calls the remote method modify. The DatabaseRemoteImpl has a reference to its own DatabaseAdapter object, which accesses Data. DatabaseRemoteImpl has an member class called LockManager which handles the locking. It puts the record into a synchronized list and then calls the DatabaseAdapter lock method (which in turn calls Data lock method). I modified the Data lock method to use a static list to store locked records.
The LockManager created by each DatabaseRemoteImpl will keep track of which records that client locked. The Data lock method (which I modified instead of extending) will keep track of all records locked.
Does this design sound okay or are there some obvious flaws/considerations I have to think about? Also, am I abstracting things too much by having that DatabaseAdapter object when I could just call Data directly? (The adapter provides an extra layer so that if things change in Data we don't have to worry about it in the upper layers, that's my initial reasoning anyway.)
Thanks! Knowing this forum, I think I will see some helpful responses.
Darien Chambers

Joined: Oct 26, 2002
Posts: 4
Oh, another question, is it bad that the locking mechanism here is split between the Data method and the DatabaseRemoteImpl method?
I agree. Here's the link:
subject: Lockmanager as inner class
It's not a secret anymore!