aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes server gui ? and  safe shutdown Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "server gui ? and  safe shutdown" Watch "server gui ? and  safe shutdown" New topic
Author

server gui ? and safe shutdown

Abhinav Anand
Ranch Hand

Joined: May 02, 2002
Posts: 113
Hi guys,
I have completed the assignment but I have a doubt. In my present implementation the output area for the server is the command window from where it is started. Additionally there is no provision of safe server shutdown (i.e. you have to press ctrl + c to stop server) and no way to save servers log into a file.
I really doubt if this a very good implementation, so I am thinking about using a gui for logging the information and providing some mechanism for safe server shutdown and saving log.
Any suggetions ??
Vishal Sinha
Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
I wrote the code below to shut down gracefully. When the user types EXIT and presses Enter, I call Naming.unbound() to remove the bound remote object.
I am interested to hear from others the need to have a GUI on the server side. It is not mentioned as the requirement as far as I can tell.

[ May 02, 2002: Message edited by: Sai Prasad ]
Adam Roberts
Ranch Hand

Joined: Mar 18, 2002
Posts: 71
I made a *really* simple GUI for the server( probably on the borderline of sloppy ) but it worked.
Two buttons and a text box that simply displayed what was going on. One button locked all the records(or unlocked it if all were locked) the other started a timer for 60 seconds(the timeout to each thread) ,locked all records then exited.


Adam Roberts - SCJP2, SCJD<br />insert witty something here
Abhinav Anand
Ranch Hand

Joined: May 02, 2002
Posts: 113
Hi Sai,
I have doubt about your implementation. If you are jamming the output of your server console into one readline statement then I guess that you are not displaying any server log. Am I right.
Thanks,
Abhinav
Abhinav Anand
Ranch Hand

Joined: May 02, 2002
Posts: 113
Hi adam,
I am also thinking about using the same sort of gui implementation on the server side. I have designed a menu system containing the options server and log. The server menu contains one option, shutdown. The log menu contains two options, clear log, save log to file. The menu system is supported by a tool bar containnig shortcut buttons to the above said options. The main display area is dominated by a jtextarea in which all the activities of the server is logged.
This gui is displayed only when the server is started for networked mode otherwise I don't display any gui.
Any suggetions are welcome.
Thanks,
Abhinav.
HanMing Low
Ranch Hand

Joined: Oct 18, 2001
Posts: 196
Hi,
I'm using a JFrame with 2 button and a JTextField.
2 Button for - Start, Stop server
TextField for - message e.g. server bind to port number xxx or server failed to start due to xxxx.
What you need to do to start the server is simply
LocateRegistry.createRegistry(portNumber);
String url = new String("rmi://localhost:" + portNumber + "/" + SERVICE_NAME);
Naming.rebind(url, this);
To stop,
Lock the whole database,
Naming.unbind(url);
Unlock the whole database.

However, I'm not sure what do you mean by the gui is displayed only when the server is started up for network mode.
My interpretation is that once you start your server, you'll want to connect it through the network.
Hope this helps.
Cheers.

Han Ming
Abhinav Anand
Ranch Hand

Joined: May 02, 2002
Posts: 113
Hi,
I start my server when I have to use networked mode access i.e. the server is running on one computer and the client connects to it from a different computer. In this case the server is running as a standalone program with a proper gui and is started by a command from the console.
However when no networking is to be performed the server is not at all started instead an instance of it is created by the client. In this case the server is not running as a standalone program so no gui is displayed.
Any suggetions are always welcome.
Thanks.
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
Sai Prasad posted:


I would guess that code would waste a LOT of cpu cycles. Having said that, I can't think of a better way to shut down the server.
Eugene Kononov.
Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
I moved away from the console design to a server side GUI with one Stop button, couple of JTextArea(s) in a JSplitPane and couple of menu items.
When the user stops the server, I lock the entire database and terminate the server VM process. I think this is a better way to do it than a console window waiting for the user to type "EXIT".
Ramesh kumaar
Ranch Hand

Joined: Mar 19, 2002
Posts: 146
Hello All,

Guys i have gone through the above postings. Here i have a doubt, As per most of ur design if u have GUI to start the server and stop a server. How to start the server in a console(Non GUI) mode.

I just like to know wheather we have to provide both(console,GUI) the ways to start, stop the server. So that the user can start the server in eaither mode he is intrested in.
comments are welcome.

thanks & regards,
-rameshkumar
Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
I have only gui version for the admin to start the server. I don't see any reason to have two ways to stop the server.
Rasika Chitnis
Ranch Hand

Joined: Jun 19, 2001
Posts: 131
just wondering what is the difference between lookup, bind, rebind methods in Naming class and the methods with same name in the Registry class ?
Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
If you want to use those methods in the Registry class, you need to get an instance of the Registry object. Methods in those classes serve the same purpose.
Rasika Chitnis
Ranch Hand

Joined: Jun 19, 2001
Posts: 131
I guess you can not use the methods in Registry directly because it is an Interface not a class.
Surprisingly I don't find any class that implements Registry Interface. Even though Naming has exactly same methods as Registry, it does not implement Registry Interface.
Rasika Chitnis
Ranch Hand

Joined: Jun 19, 2001
Posts: 131
When I started thinking about having GUI for
server, the first thing that came to my mind was
do I write a separate class (probably extends
JFrame) that creates GUI and instantiate the
DBServer (the class that extends UnicastRemoteObject and implements DBRemoteInterface) or add methods in DBServer to create GUI and add actionListeners for 'start server' and 'stop server' buttons ?
I personally prefer creating a separate class. What do you guys think ??
thanks in advance for your response.
Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
I have a seperate class to handle the GUI on the server which then instantiates the Remote object.
[ May 10, 2002: Message edited by: Sai Prasad ]
Rasika Chitnis
Ranch Hand

Joined: Jun 19, 2001
Posts: 131
I have implemented server GUI now, with two
buttons to start and stop the server and a label.
But the problem I am facing now is if I start the
server once and then stop the server, and then try
to start the server second time, I get
ExportException. Any idea why this is happening ?
thanks
Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
Yes. You don't need a "Start" button. Bind the
remote connection object to the RMI Registry
when you start the server and when Stop is
pressed, lock the entire database and terminate
the entire server VM process. If you don't kill
the server process and if a client has a
reference to the remote object, the client can
still invoke methods on it.
[ May 10, 2002: Message edited by: Sai Prasad ]
Abhinav Anand
Ranch Hand

Joined: May 02, 2002
Posts: 113
I have completely encapsulated the server gui from the actual implementation of the server. The server gui is contained in a different class and it is concerned with only one type of tasks that is to display messages, save messages to file and clear excessive messages. If the user tries to close the gui then the gui confirms whether the user wants to shutdown the server. If the user confirms that he wants to shutdown the server then the gui class simply notifies all the classes that had requested to be notified of the server shutdown. Any class that wants to receive notification of server shutdown has to request so by activating the notifyOfServerShutdown method of the gui class. The server gui simply activates the shutdown methods of these classes when the user confirms of server shutdown.
Now it depends upon the notified classes as to what to do. In my present implementation the DataServer class simply locks the whole database, unbinds the data instance from the rmiregistry and exits the program.
Please comment !!
Any suggetions are always welcome.
Rasika Chitnis
Ranch Hand

Joined: Jun 19, 2001
Posts: 131
How do you guys handle any exception thrown by
Naming.unbind while stopping the server ?
Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
System.exit(0); There is nothing the user can do to handle this exception. Right?
Abhinav Anand
Ranch Hand

Joined: May 02, 2002
Posts: 113
Hi,
When the unbind method throws an error I simply log an error message in the console and exit the program by executing...
System.exit(1);
Any suggetions are welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: server gui ? and safe shutdown