Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Safe Server shutdown

 
Sam O'Neill
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone
In my implementation I have decided to use RMI and have a DataServer class that is displays a simple GUI and binds my remote connection factory to the registry.
The GUI displays log and error messages fom the server and has 2 menu options namely 'Help' and 'Shutdown'.
Each time a client requests a data connection from the remote connection factory, the factory will check its current collection of Data and LockManager pairs to see if it already holds references to the requested filename's instances and if so returns a new remote connection object constructed with the relevant pair. Otherwise it instantiates the pair, stores them for future use and returns a new remote connection instance with the newly instantiated pair.
This means that my server will require no changes if the client application needs to access more than one data file in future which is highly likley.
The difficulty is knowing how to handle the shutdown of the server to make sure all locks for all files have been released. I realise this is above and beyond the scope for the assignment but its bugging me and I really want to find a good solution.
Currently when the user selects shutdown the DataServer calls close on the connection factory that does the following:
1) Prevents any new connections being made - returns an IOException if a connection is requested after close.
2) Cycles through each of the LockManagers for each of the data files opened, waits for all their locks to be released then locks the whole
file with -1.
I don't like though as it is very conceivable that a client will in future need a reference to more than one file and will want to perform updates on each. If the client locks a record in data file A and does an update and unlocks the record, then tries to lock a record in data file B to update that then unlocks it; and the DataServer has meanwhile called close() on the connection factory which is merrily locking whole data files one after the other and has managed to lock data File B before data File A then the client will sit there trying to get its lock for the second update on file B forever.
Worse still the server has no guarentee that the client won't lock a record in file A and try to lock a record in file B before trying to unlock its record in file A such that the connection factory will find itself in a deadlock situation where it has locked file B and is trying to lock file A but the client cannot unlock its record in file A without getting the lock on its record in file B.
How have people handled this shutdown situation? I basically somehow need to establish when there are no locks on any of the files and at that moment prevent any further locks on all files simultaneously - but how to do this is alluding me at this stage

This is easily done withmore than one file but how about many?
Any ideas would be more than appreciated
Thanks Sam
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

How have people handled this shutdown situation?

I handled in with CTRL-C. I had no server GUI, no cleaning dead clients, no WeakHashMap, no Unreferenced, no periodic threads for timeouts, or any other nonsense of that sort. I got full score for my server design.
Eugene.
 
Ramesh Krishna
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
do not implement GUI for server .
chances of loosing marks are high if you implement server GUI .
This is my own experience .
CTRL-C will do for shutting down the server .
Thanks
Ramesh Krishna .
 
Sam O'Neill
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok will not waste any more time on this but would still be nice to know how it is done!
Thanks Sam
 
Sam O'Neill
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I have to ask is it sufficient then in your opinion to just have a Data Server that binds the factory to the registry and thats all folks?
Thanks Sam
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

So I have to ask is it sufficient then in your opinion to just have a Data Server that binds the factory to the registry and thats all folks?

Yes, that's all.
Eugene.
 
Sam O'Neill
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Eugene
All the input is really appreciated - maybe one of these days I'll feel confident enough with all of this to help everybody else for a change which'd be great.
Sam
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic