Another question, I want to use MVC, but because every client has its own connection, how to fire the databaseChangeListener for every client?
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
If the interface Connection extends the interface DB, then you will have to copy the method signatures into Connection so that you can get them to throw RemoteException...
I remember you said in other thread that you call lock()/unlock() from client. If Connection provide the user logic, for example, bookingRoom(), is not it a good design to lock() and unlock() in this method? Thus the lock()/unlock() need not deal with client crash. And thus the Connection forces the order of lock() and unlock(), then we need not deal with the owner of the lock,
[Andrew] If the interface Connection extends the interface DB, then you will have to copy the method signatures into Connection so that you can get them to throw RemoteException...
[Davidd] Then Connection is a top lever interface and cannot extend DB because overriding method cannot throws Exception that overriden method does not throw, Can it?
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
When a client tries to lock a record, if the record has been locked, should the client just wait or check whether the client itself locked the record?
In Data class's update() or delete() method, I check whether the record is locked by others first. If I found the record do not be locked, what should I do, overwriting the record directly or locking the record first or throwing an Exception?
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Verifying whether the current client has already locked the requested record is a good defensive practice, however even allowing a client to lock more than one record raises a whole lot of other issues (such as deadlock).
I think you should not allow an update or a delete unless a lock for that particular record has already been granted. Check your method signatures and the comments provided with the interface - does it indicate an exception should be thrown if the user attempts to do something they shouldn't?
I only let a client book one record once,
then will Verifying whether the current client has already locked the requested record raise other issues or need it verify?
Do you think warpping a HashMap using Collections.synchronizedMap() is a good idea or it need not?
When a client lock a record and InteruptedException is catched, I just do nothing and keep it in while loop to seek the lock, is it ok?
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
wrapping the HashMap in the manner you suggested may be enough - but you have to decide whether it is enough based on your implementation.
The program must be able to work in a non-networked mode. In this mode, the database and GUI must run in the same VM and must perform no networking, must not use loopback networking, and must not involve the serialization of any objects when communicating between the GUI and database elements.
Architecturally, this mode must use the database and GUI from the networked form, but must not use the network server code at all.
Your choice of RMI or serialized objects will not affect your grade. In either case, the program must allow the user to specify the location of the database, and it must also accept an indication that a local database is to be used, in which case, the networking must be bypassed entirely.
All configuration must be done via a GUI, and must be persistent between runs of the program.
After locking a record, I think it need not to notifyAll(), is it right?
I mean as I put all verifying and updating of the map into sychronized block, whether use Collections.synchronizedMap() is holding a candle to the sun?
In my local mode, I [...] use Connection interface and ConnectionImpl class directly to act as a data model. Do you think I break the instructions?
Every time when program runs [...] I always show a configuration form first. [...] Do you think it is consists with the instructions?
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
quote:
--------------------------------------------------------------------------------
In my local mode, I [...] use Connection interface and ConnectionImpl class directly to act as a data model. Do you think I break the instructions?
--------------------------------------------------------------------------------
I think this is OK as far as the instructions are concerned.
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
You guys wanna see my fabulous new place? Or do you wanna look at this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|