David Ding

Greenhorn
+ Follow
since Mar 19, 2004
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by David Ding

General Considerations (maximum = 100): 99
Documentation (maximum = 70): 70
O-O Design (maximum = 30): 23
GUI (maximum = 40): 24
Locking (maximum = 80): 44
Data store (maximum = 40): 40
Network server (maximum = 40): 40

I don't understand why my GUI got such a low score? But I'm still very happy. :-) Thank you for all the people who helped me on JavaRanch.
[ July 02, 2004: Message edited by: David Ding ]
16 years ago
I've finish all my program and docs, and I used ant to package my application. Just minutes ago, I mailed suncert asking for the upload rights.
I'm not very confident with my english, so I'm sure I've made some mistakes in my docs. Will this affect my score?
And I wanna know how to prepare the followup exam of B&S submission.

Thanks.
I've finished all the codes and comments, the last thing to do is finish the choice.txt and the userguide, but I don't know how to write choice.txt, what should I write in it?
P.S. I've fix the bug, the RemoteException is caused by an unremoved reference to the closed client. How careless I was.
I've finished both the standalone and the rmi parts, but I met a strange problem while testing with two clients.
Step 1: java -jar runme.jar server
Start the server, everything is ok.
Step 2: java -jar runme.jar
Start the client 1, all the operations are ok, they work well.
Step 3: java -jar runme.jar
Start the client 2, no exception occured while operating both the two clients.
Step 4: close one client
While I want to do any operations on the remaining client, it fails, in the message box:
RemoteException occurred in server thread; nested exception is:
java.rmi.ConnectException: Connection refused to host: 192.168.1.63; nested exception is:
java.net.ConnectException: Connection refused: connect
If I use only one server and one client, I first close the client, and then start a new one, the same problem happened again.
I am confused now, what's wrong with my rmi?
I plan to use Command pattern in the communication of View and Controller. The view sends CreateRecordCommand/UpdateRecordCommand/DeleteRecordCommand to Controller, in the Controller there's only one method handleCommand(Command cmd).
In SL-285 student guide, there're many methods in Controller such as handleXXXGesture().
Is my design a right MVC pattern?
Thanks
But I still don't know if I implement Serialize, will I go against the rule----must not use loopback networking, and must not involve the serialization of any objects when communicating between the GUI and database elements.
There's no doubt that there are two different model, one is for standalone, the other is for rmi, but should I also write two view, or I can use the remote view in standalone mode?
I've finished my Data.java file, now I'm designing GUI and the View.


Non-Networked Mode
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.
The operating mode is selected using the single command line argument that is permitted. Architecturally, this mode must use the database and GUI from the networked form, but must not use the network server code at all.


(1)I plan to use rmi for network mode, so I need to declare both Model and View Remote objects, and I want to reuse this view in standalone mode.
(2)I want to define a new Class to store the infomation of each record in db, I don't know whether I should implement Serialize or not if I want to pass an instance of this class as a parameter and as a return of a remote method, of course these methods will be unchanged in standalone mode.
Will these go against the rule listed above?


The User Interface
It must allow the user to search the data for all records, or for records where the name and/or location fields exactly match values specified by the user.
Declaration of find in DBMain.java
// Returns an array of record numbers that match the specified
// criteria. Field n in the database file is described by
// criteria[n]. A null value in criteria[n] matches any field
// value. A non-null value in criteria[n] matches any field
// value that begins with criteria[n]. (For example, "Fred"
// matches "Fred" or "Freddy".)
public int [] find(String [] criteria) throws RecordNotFoundException;


I provide two combo boxes which allow user to input or choose name and location, and there's also two radio buttons to choose and/or. If user choose or, input a name but left the location blank, I list all the records; In the same situation, if he choose and, no records will be showed. Am I right?
Tnanks
Thanks for replying my questions.
I looked thorough the API of JDK1.4 about the DataOutputStream and RandomAccessFile, I didn't find and method like skip() in DataInputStream. How can I fulfill the task?
In my cache, I only make a note that the record is deleted, the instruction require me to use the space of a deleted record, So I think I should lock the deleted record in the cache, modify the content and the delete flag, then write these infomation to the db file. Perhaps you are right, I don't need to do so, I will think about it later.
I used to invoke lock() and unlock() in the create/update/delete method, now I will change my code, let the DbModel to do the job of lock() and unlock(). Maybe this way is better.
I've read the Notification issues you give, and I think I will choose to use "1.2 Synchronization on the locks container / notifyAll() in unlock() only" because it is much easier for me to understand and implement.
I've just received SCJD assignment, and my subject is Bodgitt and Scarper. I've some questions in dealing with the Data.java.
I use an ArrayList as a cache to store the records, a Vector to store all the field names because I will use JTable(Vector, Vector) to show the records, a short[] to store the length of each field(Although I know the lengths are 32,64,64,6,8,8, I prefer to get these infomation from db file.).
When writing the db file in create/update/delete, can I skip to the pos I want to write my record. Or only to clear the file, and write all the data again?


// Returns an array of record numbers that match the specified
// criteria. Field n in the database file is described by
// criteria[n]. A null value in criteria[n] matches any field
// value. A non-null value in criteria[n] matches any field
// value that begins with criteria[n]. (For example, "Fred"
// matches "Fred" or "Freddy".)
public int [] find(String [] criteria) throws RecordNotFoundException;



It must allow the user to search the data for all records, or for records where the name and/or location fields exactly match values specified by the user.


Whether I should separate and/or into two parts or combine them, I mean only to find the records whose name or location matches the criteria? I don't understand why there use a array, only a String is enough, I pass in a condition from a JTextField, or use two JTextFields stands for name and location.


Locking
Your server must be capable of handling multiple concurrent requests, and as part of this capability, must provide locking functionality as specified in the interface provided above. You may assume that at any moment, at most one program is accessing the database file; therefore your locking system only needs to be concerned with multiple concurrent clients of your server. Any attempt to lock a resource that is already locked should cause the current thread to give up the CPU, consuming no CPU cycles until the desired resource becomes available.


I plan to use a WeakHashMap in my Data.java. To lock a record, I put a Key into the WeakHashMap, of course unlock is to remove the Key. I think only the create/update/delete method need lock. First lock a record, do the operation, and then unlock it. I wonder whether I should do lock/unlock in create/update/delete method or do it in the method invoke them in Model. My solution is in the c/u/d method I first invoke lock()-->in lock() use a dead loop-->if the record is locked, then sleep(100)-->when the record is unlocked, break the loop and lock the record-->do the operation-->unlock the record. Does it meet the requirement?
As it is said in the Instruction, I must provide a multitask server, if I don't use synchronize, I can't guarantee the safe of the system. For example, two threads want the same record, the first one check the lock list, the record isn't in the lock list, just before locking the record, the second thread check the list. I am not familiar with multithread, could somebody show me a way or give me an example how to prevent this situation?
[ March 19, 2004: Message edited by: David Ding ]
[ March 19, 2004: Message edited by: David Ding ]
[ March 19, 2004: Message edited by: David Ding ]
[ March 19, 2004: Message edited by: David Ding ]