WarrenII Pan

Greenhorn
+ Follow
since Jul 17, 2005
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 WarrenII Pan

Thank you, Michael! You do give me a lot of help in resolving my questions!

Regards, WarrenII Pan
15 years ago
Hi, everyone!
I am interested in designing Java games. I got a problem recently. We all have the experience that when controlling an actor to do a certain action, we sometimes require to press the up and right arrow buttons simultaneously.
In order to help users get easier operation, my question is how to press a single button, say "F8", to perform the same function mentioned above?

Thanks in advance!

Regards, WarrenII Pan
15 years ago
Thank you, Lara! Sorry for coming late.

I just had an idea about stopping all the writes... you could lock each record in the database. At the point all the records were locked, then you would be ready to finish.


The stopping manner is not friendly enough,I think. Just like in the real world, the server should at least wait for the current writing thread finishing.
I think we can add new methods to Data definitely. Although the Data class implements the DBMain interface, the definition of implementation doesnt prohibit us adding new methods which aren't provided by DBMain, right?

Best Regards,
WarrenII Pan
Thank you very much, Andrew and Lara!
Hi Lara,
I would prefer your 1st choice to the 2nd one. Because I think using server GUI just like the one in Andrew�s book can perfectly match requirements of Sun�s B&S assignment.

Hi Andrew,
Your Server GUI is wonderful! It completely implements all the functionality in server side and matches the Sun�s requirements perfectly. With the greatest help of your posters, I decide to use a) a flag which indicates whether writes are currently allowed or not and b) the method of addShutdownHook waiting for the current updating thread finishing and then stopping the server just as you have mentioned in your previous post: Shutting down cleanly is something you really should do, no matter what exit/stop manners the user will take in the sever side, even if not use server GUI. BTW, your example of the usage of addShutdownHook method is more concise than Java�s API. Thank you again!

Best Regards,
WarrenII Pan
Thank you, Andrew and Samuel!

Hi, Andrew. After carefully thinking about your guidelines for solving these questions and testing some codes according to your advices, I found my approach is more complex and has some weakness. When there is a waiting sequence in server side, which has a lot of users who in turns want to write the same record in a db file, the advantages of your way will appear after pressing the �Stop� button. For example, the order should be after client A unlocks record No.5, the server stops. Then client C or client B gets the priority from waiting mode and accesses the flag indicating writes are currently not allowed and receives the current server status immediately, which is superior to my solution. Because in my solution, client C/B will not receive the server stop information unless press �Reserve� button again in client side. Here I got another question what if the server wants to stop when client A is writing? I think the server should at least wait for client A�s writing operation done and stop. So, is my writing flag still needed here?

My instruction describes the lock method as public void lock(int recNo) throws RecordNotFoundException. Does this mean it doesn�t allow me to use the magic number?

Now I know broadcasting the server�s status to all connecting clients is beyond the scope, but your suggestion using Observable pattern really sheds light on carrying out this objective. I will consult you about it latter for I have not finished it yet. Another question, if I don�t provide a stop button in the server GUI, should I be punished for this?

Thanks in advance!
Best Regards,
WarrenII Pan
[ August 06, 2005: Message edited by: WarrenII Pan ]
I read one of Andrew�s posters about this topic carefully these days. With the help of it, I finally found some useful hints and designed a solution to my problems. Thank you again, Andrew!

To detect the current writing operation thread, set a flag in the write method, assign initial value at the beginning of the method. After writing operation, assign another value to the flag. When a user presses the �stop� button in Server GUI, it will check the flag first to ensure that there is no writing thread. I also found if the checking process is in multiple threads itself, which implements the run method explicitly, the server GUI can wait for the last writing thread stopping and exit the JVM automatically as expected, but the whole program will run slowly; if not in multiple threads, when there is a writing thread, press �stop� button will not result in exiting JVM automatically. Is it necessary to put the process in multiple threads?

When the client users press the �Reserve� button, if the server has stopped(System.exit(0)), they will catch a RemoteException. In the catch clause, I give users information about the current server mode such as The server is not available now. But I still can�t find a way to broadcast to all the connecting clients when the server stops immediately. Is this beyond the scope?

Any advice will help!
Best Regards,
WarrenII, Pan
Thanks a lot! I just read an essay using"java -Djava.rmi.server.logCalls=true yourRMIServer" to compile the file. After trying it, I found all the remote method invocations are really displayed in the server console. Then I studied the code of "java.rmi.server.RemoteServer.java" which imports the package of "sun.rmi.server.UnicastServerRef" for the use of the logCalls field,and this package is not disclosed. However, I don't know how to get those information in my code. Can the methods setLog and getLog in the package of java.rmi.server.RemoteServer do the work? If so, how to use them?

Thanks in advance!
Regards,
WarrenII Pan
[ August 06, 2005: Message edited by: WarrenII Pan ]
Thank you, Ta Ri Ki Sun. I try to use a server GUI to allow user entering the position of db file and the RMI service port, starting and stopping the RMI Server. Without the GUI, how to fully implement these things then?

Best Regards,
WarrenII Pan
Hello, everyone!
I got 2 problems again. I am designing the server GUI. There is a �Stop� button to stop RMI server. When a user presses the button, the following things should happen:
First, stop RMI service. Using unbind method is available.

Second, track if some certain thread is currently in a write method. I search the forum using the keyword of �RMI stop� and benefit from one of Andrew�s posters which suggested to think carefully about this situation.
But how to detect the right thread which is writing a record? Am I losing some key points here?

Third, broadcast all connecting clients that the server is not acceptable temporarily. I still can�t figure out how to implement it.

I know my instruction doesn�t tell me �must� to achieve the 2nd and 3rd requirements, but this case will really occur when the examiner tests my program and press the stop button. So I must manage it properly.


Any advice will be appreciated!
Best Regards,
WarrenII Pan
Thanks Andrew for so fast response! Your answers make all my confused questions clear enough. By the way, I don't mean to flatter you, but we candidates are luck enough to meet a moderator like you, you indeed do an excellent job for all of us and you deserve the praise!

Best Regards,
WarrenII Pan
[ July 30, 2005: Message edited by: WarrenII Pan ]
Hello everyone! After about 10 days hard work, I finally implement almost all the requirements of my B&S assignment. Without the great help in this forum, especially the useful advices from Andrew, whose excellent enlightening work makes people�s lives more interesting and better, I would never do it so quickly and perfectly, so I need to thank all the people here again. According to other friends� proposals, I divided all the requirements into several small parts in order to achieve them separately and it works perfect! Here are some uncertain questions, which I don�t find similar answers to resolve now, I strongly desire to hear from you to set up my final submission:

1)About the Server IP. I think the process should be when the examiner tests the program in network client mode, he/she would input the right IP address of the server machine (using GUI ) which had already started by him/her. In other words, we don�t need to hardcode a common IP address in our programs, like 127.0.0.1 , localhost or something like this. I don�t know if I understand the process correctly.

2)About implementing delete and create methods in the DBMain interface. My instruction says, �Your data access must implement the following interface:�. There are two methods, delete and create, in the interface, but in the user interface section of this instruction which only requires the functionality of booking and searching, thus it makes those methods useless. My way is to implement them using some concrete sentences in the Data.java (which implements DBMain) and don�t invoke them in the client GUI at all. But how the examiner knows exactly to add right clauses testing the implementation of those methods in Client side? I don�t know whether the approach is right.

3)About null terminated text values. In the instruction, it told me that "All text values, and all fields(which are text only), contain only 8 bit characters, null terminated if less than the maximum length for the field". I have read the data in my JTable component already, but I don�t know how to test whether all the text values are null-terminated or not(maybe space-padding?).

4)About the class of reading db file. In the instruction, it says "all numeric values are stored in the header information use the formats of the DataInputStream and DataOutputStream classes". Should I be docked if I only use RandomAccessFile class to access the db file?

5)About SDK version. Following the instruction, "the platform must not have been superseded by a new production version for more than 18 months by the time you make your submission". Does this allow me to choose either SDK 1.4 or SDK 1.5 to compile the program if I upload the assignment next month?

6)Another locking manner in standalone mode. I know in standalone mode file level locking should be no needed. But what if a user opens several windows to run the same program? Do we need to ensure only one program should be run at one time in this mode? And if so, how to implement this?

7)About Owner field format. In the instruction� sDatabase schema, it describes Owner field as "The id value (an 8 digit number) of the customer who has booked this". I think the field contains number like 0,1,2�etc. So I decided to use JformattedTextField component to restrain users� input, only numbers can be accepted. Is that assumption right?

Any advice will be appreciated!
Best Regards,
WarrenII Pan
[ July 30, 2005: Message edited by: WarrenII Pan ]
Thanks, Andrew. According to your instruction, I understand my mistake completely. Just like other friends in this forum said, it is always easy to agree with you. With all my friends here like you and others, I am sure I can pass the SCJD Exam definitely. Thanks the greatest forum and the greatest moderator!

Regards,
WarrenII Pan
Thanks Barry and Andrew. Yes, I am running the above program in two different DOS windows. But all the windows I opened display the same object"DataAccess@757aef". Now it seem to me that it should be tested in RMI environment,is it rihgt?

Regards,
WarrenII Pan
Hi,everyone! I just get around to do my assignment of B&S. I got a problem in implementing the Singleton pattern. To make a long story short,I write the following code to explain this situation:
There are two class, DataAccess and Test . The DataAccess class uses Singleton pattern and the Test class is to test whether the former class has implemented this pattern correctly.





My question is when I open several MS-DOS windows to run Test class separately, the result is not as what I expected. I think inthe first wndow,it shoud display:

Before setI,the Value of i:0
Is the same Object of DataAccess?DataAccess@757aef
After setI,the Value of i:10

and in the second window it should be:

Before setI,the Value of i:10
Is the same Object of DataAccess?DataAccess@757aef
After setI,the Value of i:20

But all the windows I opened display the same thing as in the first window.
what's wrong?
Your advice would be greatly appreciated
WarrenII Pan

[Andrew: Put code between [code] and [/code] ubb tags]
[ July 17, 2005: Message edited by: Andrew Monkhouse ]