aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Restarting the server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Restarting the server" Watch "Restarting the server" New topic
Author

Restarting the server

Hanna Habashy
Ranch Hand

Joined: Aug 20, 2003
Posts: 532
hi:
How can I restart the server withen the same thread?
I have a window for server administration. The administrator should be able to restart the server, shutdown the server, reinitialize the properties file, and change the center database location.
I want to know how can I shutdown, and then restart the server withen the same thread(same window).
I searched the previous posts, but I couldn't find anything.
thanks


SCJD 1.4<br />SCJP 1.4<br />-----------------------------------<br />"With regard to excellence, it is not enough to know, but we must try to have and use it.<br />" Aristotle
Denis Spirin
Ranch Hand

Joined: Mar 22, 2004
Posts: 72
But why do you need that ? Whats the reason to restart server? If you mean that admin may want to choose another database file and restart with that file, then he can just restart program. Why do you want to keep it in the same thread?


Regards<br /> <br />Ph.D.<br />SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJD 2
Hanna Habashy
Ranch Hand

Joined: Aug 20, 2003
Posts: 532
hi Denis:
I think it is easer this way. I don't want to make the admin restart the whole program manually. I can spwan different threads, but I don't want to deal with that right now.
I am using the follwing lines to unbound the remote objects and the remot registry.

UnicastRemoteObject.unexportObject(data, true);
UnicastRemoteObject.unexportObject(reg, true);

It is working fine uptill now, the catch with that is any other clients connecting to the server at that time, need to reconnect.
I know it makes sense, but it would be nice if the clients don't need to reconnect.
any ideas?
Denis Spirin
Ranch Hand

Joined: Mar 22, 2004
Posts: 72
I still cant get it. What do you mean by saying "restart"? If you want to change datatbase file the server serves to client, then you need to put some 'switch' in corresponding class and add button to GUI, so that admin could call some method to chande db file. However you will also need locking on case if client was doing something with db while another file was opened.
It would be good for real program, but for scjd youre not REQUIRED to do that. You will get NO EXTRA POINTS for that, you may only LOSE points if examiner will find a bug or simply will not like code.
Hanna Habashy
Ranch Hand

Joined: Aug 20, 2003
Posts: 532
hi Denis:

If you want to change datatbase file the server serves to client, then you need to put some 'switch' in corresponding class and add button to GUI, so that admin could call some method to chande db file.

If I use switch statement to change the database the server servs, I am limiting the number of database files programatically. I want to give the option to the admin to choose any database file he liks.
My remote data access object needs the data file location in its constructor, then I bind this object to the registery.
the reasons I am providing this function:
1) My instruction is not clear it says:

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.

What I understand from this is that the user must be able to choose a database file in either mode.

2)The application doesn't know anything about the database. It configuers everthing at runtime. So, one can plug in a database file with differnt fields length or names, as long as the database file has correct metadata section. it would be nice to be able to use this property.
Pavel Tcheshmedjiev
Greenhorn

Joined: Mar 09, 2004
Posts: 13
Hi Hanna,
As far as I understand you want your clients to redirect to the new server. So if a client is not able to perform the remote call(the original remote object is no longer there, you have restarted the server), it can try to acquire a new remote object reference from the registry(in the catch section). You can also define its maximum retries.

In this case(running clients) you will have to implement a safe server stop so you can start the server again.

And finally, as Denis said, you will not gain any points of additionally complicating your tasks.

Thanks, Pafka


SCJP, SCJD
Hanna Habashy
Ranch Hand

Joined: Aug 20, 2003
Posts: 532
hi Pavel :
Thanks for the informative response. It is not exactly what I want to do. I created a frame to admin the server, like restart or shuting it down. I did it by unbounding the remote objects. In this case, I need to notify all connected clients that the server is shutting down, or restarting, so that the clients can reconnect manually.

How can I let the clients know?
How can I send a message to all connected clients?
any ideas?

I imagen it will be a popup window with the message, but I don't know how to message clients.

As far as points and grades, I am not very concered about it. I am doing this project for learning. I did not know anything about RMI or Swing before, and I am taking advantage to learn and explore as much as I can. At my job, I use J2EE, so maybe I will never get another chance to learn it.
Denis Spirin
Ranch Hand

Joined: Mar 22, 2004
Posts: 72
Suppose you want to switch database. Admin can press button "change database" and choose it (JFileChooser). Once he has chosen db file, server calls corresponding method on your RemoteDatabaseImpl (your class which extends UnicastRemoteObject) and passes file name. This method
1. blocks entire db and read access
2. reads data from file
But there is the problem - how to let users know that db file has changed?
1. Kick off all users which are trying to book record
2. Call method to make them to refresh their data. Use RMI callback. http://www.ryerson.ca/~dgrimsha/courses/cps841/RMICallbacks.html
Hanna Habashy
Ranch Hand

Joined: Aug 20, 2003
Posts: 532
thanks Denis:
that was a very helpful link. I searched the web before, but I didn't know the term callback.
thanks again
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11460
    
  94

Hi Hanna & others,

Just a cautionary note - this does seem to be going well beyond the requirements of the instructions. You might want to think about whether you really want to go to that level of complexity.

Ooops, I am sounding like Mark

Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Restarting the server