public void close(boolean permanently) throws Exception
{
// To avoid a NPE cause by the stop
NodeManager nodeManagerInUse = nodeManager;
if (configuration.isBackup())
{
long timeout = 30000;
long start = System.currentTimeMillis();
while (backupActivationThread.isAlive() && System.currentTimeMillis() - start < timeout)
{
if (nodeManagerInUse != null)
{
nodeManagerInUse.interrupt();
}
backupActivationThread.interrupt();
backupActivationThread.join(1000);
}
if (System.currentTimeMillis() - start >= timeout)
{
threadDump("Timed out waiting for backup activation to exit");
}
if (nodeManagerInUse != null)
{
nodeManagerInUse.stopBackup();
}
}
else
{
if (nodeManagerInUse != null)
{
// if we are now live, behave as live
// We need to delete the file too, otherwise the backup will failover when we shutdown or if the backup is
// started before the live
if (permanently)
{
nodeManagerInUse.crashLiveServer();
}
else
{
nodeManagerInUse.pauseLiveServer();
}
}
}
}