I am looking at how to address Server Shutdown. As I see it for this scenario, I need to :-
1) ensure all writes to the DB have completed
2) close the DB file
However, I am not sure whether to remove the service from the RMI register, as the client will get the exception of service not available.
I have a server GUI which provides an "Exit" button to stop the server. My approach is to use the addShutdownHook. I have defined an inner class, ServerShutdown, in
my Data class which uses a private Data class method processServerShutDown (). All the Data class members are synchronized, therefore, when the processServerShutDown () is invoked, it will have exclusive access to Data class members. I have a map of all the locked records ( lockedRecords ).
It seems that the processServerShutDown() is working fine in that it waits for writes to the DB to be completed, before closing the DB file and completing. However, I had assumed that at this point the server service and effectively access to the Data class to a client would be availble because the JVM would terminated the server process. But from the above log, there is still a window after the processServerShutDown() has completed that server service is STILL available. My concern is that in this window, it is possible for a client to get half way through a Booking and the server terminates leaving a a client in wait for the Book to complete but will not and a corrupted DB file.
Any suggestions as to how I can stop any further access to the Data class by a client after the processServerShutDown() ?
I could introduce a static flag which could be monitored at the start of every method in the Data class but. I just wondered if there is a neater approach !
Of course, please feel free to improve/correct me if you see an issue in the above.