aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes FBN: Closing the database in Network mode. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "FBN: Closing the database in Network mode." Watch "FBN: Closing the database in Network mode." New topic
Author

FBN: Closing the database in Network mode.

Akash Singh
Ranch Hand

Joined: Aug 21, 2003
Posts: 80
I am not able to call lock(-1) to lock entire database before shutting
down the RMI server.
To shutdown RMI server, i am thinking :
1. lock(-1) lock the entire base.
2. close the database.
3. unbind it from the registry.
Below is ConnectionFactoryImpl class that is bound to RMI registry.
Client calls getData() method to get unique reference of RemoteData object.

Since, i have opened the database(instance of Data through DataAdapter) in this class, i would like to close it here. But close method on DataAdapter will close the database, without checking for lock held by client. Lock method in DataAdapter class does mothing. Lock method is in RemoteDataImpl class for network mode.
If i get the reference of RemoteDataImpl object in this ConnectionFactoryImpl class, i should be able to call lock(-1) to lock entire database, before closing it using DataAdapter.close() method. But is this right way to do this?
Is there something wrong in my design , thats why i am not able to close the database while shutting down the RMI server in proper way?
Regards,
Akash
Bharat Ruparel
Ranch Hand

Joined: Jul 30, 2003
Posts: 493
Hello Akash,
I think that you can get by with as little as hitting the carriage return to terminate the sever or unbind the registry. I will not invest in an elaborate shut-down process.
Regards.
Bharat


SCJP,SCJD,SCWCD,SCBCD,SCDJWS,SCEA
Akash Singh
Ranch Hand

Joined: Aug 21, 2003
Posts: 80
Thanks Bharat. i agree with you, since there is no mark gain or loose, in stoping the server.
Regards,
Akash
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11479
    
  94

Hi Akash,
Personally I would (and did) lock the database before shutting down the server. That way you know that no other processes are in the middle of performing a write to the file.
I don't understand your concern about closing the file not checking for lock owned by clients - if you have granted the lock on the entire database, there should be no locks owned by clients.
Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Svetlana Koshkina
Ranch Hand

Joined: Jul 08, 2003
Posts: 108
I thought you,as a client, don't have to close the database. Method 'close' that remote client should implement was intended for closing this connection as to give the server signal that this client is out. For ex. my Data class was so expensive that only administrator could close it as to terminate its instance. Once terminated the instance was revived by first client that wanted to connect.
:-) :roll:
Akash Singh
Ranch Hand

Joined: Aug 21, 2003
Posts: 80
Hi Andrew,
Thank You Very Much for reply.

Personally I would (and did) lock the database before shutting down the server. That way you know that no other processes are in the middle of performing a write to the file.

Yes, I wanted to implement shutdown in this way. But droped idea, after getting trouble in implementation. But, again i am thinking to implemement
it.

I don't understand your concern about closing the file not checking for lock owned by clients - if you have granted the lock on the entire database, there should be no locks owned by clients.

Firstly i want to share how many close method i have and what they do.
Local Mode:
1. close() method in Data class. This method closes the open data file.
This will be called by GUI client in local mode.
2. close() method in DataAdapter class. This class is wrapper on Data, so it calls close() method on Data class. This will be called by GUI client in local mode. In fact, GUI client will call close method on this class to close the database. Whenever they logout using GUI, close method on DataAdapter will be called to close the opened Data file.
Remote Mode:
1. close() method in RemoteData class. This method releases any lock
from the lockholder object, if any lock is held by remote client. This method will be called by unreferenced method implicitly if remote client dies/timeout etc., or if client logs out using GUI widgets.
Server :
In admin mode, if server needs to be shut down, first lock(-1) is called , this method waits till all locked records unlcoked, then it locks all records; to not allow any remote client to do any write. At this time close
will be called on DataAdapter class to close the open data file.
Connectionfactory create instance of DataAdapter, but LockHolder object(a HashMap) is not owned by ConnectionFactory class, it is created as static instance field in RemoteDataImpl class. Beacuse of this reason, i was not able to call to lock(-1) from ConnectionFactory class.
Now i am thinking to implement LockManager that will have lock and unlock method. This LockManager (a static final) will be owned by ConectionFactory, and will be passed to each RemoteDataImpl along with DataAdapter object to construct RemoteData object. In that case , since ConenctionFactory class owns reference of DataAdapter object and LockManager object , I will be able to call lock/unlock, and close data file to shutdown server.
But, I still do'nt know how to destroy a registry dynamically as we create the registry using LocateRegistry.createRegistry. I am using unbind, but restarting is giving problem, when it execute createRegistry method, because old registry already exits.
Looks like only soultion is -- exit JVM (after doing the proper shutdown)to restart the server. Is there any way to start server,stop,restart ,stop,restart....without exiting from JVM using GUI ?
Regards,
Akaksh

Hi Svetlana,
Thanks for reply.

I thought you,as a client, don't have to close the database. Method 'close' that remote client should implement was intended for closing this connection as to give the server signal that this client is out.

You are right. I am trying to implement close method for server shutdown, in addition to, close method in RemoteData class.
I have ConnectionFactory, that is responsible for database startup(opening data file) and providing reference of RemoteData object to RMI client(GUI), when it is bound to RMI registry.
This close method i would like to have in ConnectionFactory class to shut down the server in nice way, means lock the database(this will wait till no client has lock), close the datafile, unbinds ConnectionFactory object.

Regards,
Akash.
PS. I have tried to write in detail. If you guys think, there is something something wrong in my design, please help me.
Svetlana Koshkina
Ranch Hand

Joined: Jul 08, 2003
Posts: 108
What i meant that you would be better without implementing 'server shutdown': just let it run. Let all of your clients come and go whithout interfering with each other: that what they want from you. You are not supposed to implement remote administration of some server. 'CLOSE'(on client side) is not as you terminate all server's and database's instances.
As you can't shut down American Airlines server(right?) if you got dissatisfied and canceled your reservations. Or i maybe i don't know what you are asking, sorry.
Originally posted by Akash Singh:
Hi Andrew,
Thank You Very Much for reply.

You are right. I am trying to implement close method for server shutdown, in addition to, close method in RemoteData class.
I have ConnectionFactory, that is responsible for database startup(opening data file) and providing reference of RemoteData object to RMI client(GUI), when it is bound to RMI registry.
This close method i would like to have in ConnectionFactory class to shut down the server in nice way, means lock the database(this will wait till no client has lock), close the datafile, unbinds ConnectionFactory object.

Regards,
Akash.
PS. I have tried to write in detail. If you guys think, there is something something wrong in my design, please help me.
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11479
    
  94

Hi Akash,
But, I still do'nt know how to destroy a registry dynamically as we create the registry using LocateRegistry.createRegistry. I am using unbind, but restarting is giving problem, when it execute createRegistry method, because old registry already exits.

Don't worry about it. After you have locked the datbase, just do a System.exit(0) to stop the server.
Note that there is no requirement to restart the server - I wouldn't even go there. If the user want's to use a different port, let them shut the server down completely then start a new server application.
Do you unbind your server instance from the RMI Registry before trying to get the database lock or after?
Do you have any way of stopping new locks from being granted while you are waiting for clients to release existing locks?
Regards, Andrew
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11479
    
  94

Hi Svetlana,
Originally posted by Svetlana Koshkina:
As you can't shut down American Airlines server(right?)

I, as a client of an airline, cannot shut down their server - correct.
But what Akash is talking about is if the airline staff themselves need to shut down the server. In other words: what if American Airlines wanted to shut down their own server? It might not happen very often, but you can bet that if it does happen that they would want to be able to do it without corrupting the database.
Regards, Andrew
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: FBN: Closing the database in Network mode.