// First attempt graceful shutdown
sendStopToNexus(commandPort);
// FIXME LOCALHOST should be getHostName
CommandMonitorTalker talker = new CommandMonitorTalker(LOCALHOST, commandPort);
long started = System.currentTimeMillis();
long max = 5 * 60 * 1000; // wait 5 minutes for NX to shutdown, before attempting to halt it
long period = 1000;
// Then ping for a bit and finally give up and ask it to halt
while (true) {
try {
talker.send(PingCommand.NAME);
}
catch (ConnectException e) {
// likely its shutdown already
break;
}
catch (Exception e) {
// ignore, not sure there is much we can do
}
// If we have waited long enough, then ask remote to halt
if (System.currentTimeMillis() - started > max) {
try {
talker.send(HaltCommand.NAME);
break;
}
catch (Exception e) {
// ignore, not sure there is much we can do
break;