• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

FBN: Closing the database in Network mode.

 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 493
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Akash Singh
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bharat. i agree with you, since there is no mark gain or loose, in stoping the server.
Regards,
Akash
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Farmers know to never drive a tractor near a honey locust tree. But a tiny ad is okay:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic