| Author |
please comment ! my design of local/remote and lock
|
jiaquan sun
Greenhorn
Joined: Oct 05, 2002
Posts: 12
|
|
I have finished FBN program. It seems fine. But I have no enough confidence ,at the same time my english was so poor!following was two part of my design document. please comment! thanks! ----------------------------------------------------------------------------- 4.Local/Remote mode ----------------------------------------------------------------------------- The factory pattern is used to handle local/remote mode. a) A interface named DataInterface is implemented by both Data and RemoteDataClient class. The interface is extended by RemoteData connection too. This connection is used for both remote and local methods. b) Data class is used to operate a local text file. c) RemoteDataImpl implements RemoteData and extends from UnicastRemoteObject. This class wraps a DataInterface, and pass on all the method calls to the DataInterface instance. d) RemoteDataClient lookups a remot RemoteData Object, and pass on all the methods calls (except for the lock, unlock and close methods) to the RemoteData Object instance. e) DataDriver is a factory class. The public DataInterface getData(String url) method returns local or remote connection according different URL. If the url is beginning with "file://", getData method will return a instance of Data class directly. Data class uses a local file specified by url as a database file. If the url is beginning with "rmi://", getData method will return a instance of RemoteDataClient.Via rmi, RemoteDataClient connects to a database server specified by url. ----------------------------------------------------------------------------- 6.Locking mechanism ----------------------------------------------------------------------------- Responding to the requirements on the Recode Lock function as required in the assignment instruction, I coded lock/unlock in two classes. a) In Data class, a HashSet is used to save all the records locked. Before lock a record, the HashSet is checked to find whether the record has been contained in it. If not contained, then add the record number to HashSet. Before unlock a record, the HashSet is checked to find whether the record has been contained in it. If yes, remove the record number from HashSet. b) In RemoteDataClient class, a HashSet is used to save the record locked by this client. The lock method at first calls the lock method wrapped in the RemoteData instance in the RemoteDataClient. If the call is successful, then add the record number to the HashSet, When unlock, firstly check whether the record has been locked by this client. If locked, then calls the unlock method in RemoteData and remove the record number from the HashSet. c) In local mode, the Data class is directly used as a Data client. Under this situation, since the record locked in the Data class is locked by the same connection, so no need to identify the connection. As a result, the locking process in Data class may ensure the proper running of the application. d) In remote mode, several RemoteDataClient are connecting to server and manipulate the database through the same Data class. Under this situation, Data class saves all the records locked by clients, while each client saves own locked record. When two classes work together, the record locked by a client will not be unlocked by another client. e) If the locked record number is -1, it means no record locking is permitted any more. When database server receives exist command, it will call lock method like this to prevent any database manipulation, and wait 5 seconds to exit (to give time to all the running commands to complete) f) If the locked record number is not in the record number range, throw IOException.
|
 |
John Smith
Ranch Hand
Joined: Oct 08, 2001
Posts: 2937
|
|
I have finished FBN program. It seems fine.
Did you test it with multiple threads booking the same flight repeatedly? Did you confirm that when 20 threads book the same flight 100 times each, the seat count for that flight is reduced by exactly 2000?
b) Data class is used to operate a local text file.
Well, it's a binary file.
e) DataDriver is a factory class.
If it is a factory, why not call it DataFactory?
e) If the locked record number is -1, it means no record locking is permitted any more. When database server receives exist command, it will call lock method like this to prevent any database manipulation, and wait 5 seconds to exit (to give time to all the running commands to complete)
I am not sure why you want to wait 5 seconds, -- as soon as lock(-1) returns, the database is locked and there is no point in waiting. Eugene. [ February 14, 2003: Message edited by: Eugene Kononov ]
|
 |
jiaquan sun
Greenhorn
Joined: Oct 05, 2002
Posts: 12
|
|
Eugene,thank you very much! I have tested the booking function with multiple threads(200 threads).The result is ok. because JDBC API have a interface named Driver, so I think user will more familiar with DataDriver. I think although database was locked,some modify process might have not finished.so I wait 5 seconds. My english was very poor.I must write document with a dictionary.So I am very worry about my document and essay test. Do you think whether or not my document clear enough??? and,please give me some sample essay questions!!! very thanks!!
|
 |
 |
|
|
subject: please comment ! my design of local/remote and lock
|
|
|