public synchronized void stopSynchronized() { stop(); }
private synchronized HostCommand nextCommandSynchronized() throws IOException { // In case of failure to move on to next command, stop the partition server and rethrow the exception. try { return host.nextCommand(); } catch (IOException e) { stop(); throw e; } }
private synchronized void setStateSynchronized(HostState state) throws IOException { // In case of failure to set host state, stop the partition server and rethrow the exception. try { host.setState(state); } catch (IOException e) { stop(); throw e; } }
public void processCommandOnStartup() { try { HostCommand command = host.getCurrentCommand(); LOG.info("Current command is: " + command); if (command != null) { commandQueue.put(command); } else { host.nextCommand(); } } catch (Exception e) { LOG.error("Failed to process current command on startup.", e); stop(); } hasProcessedCommandOnStartup = true; }
@Override public synchronized void onCommandQueueChange(Host host) { LOG.info("Command queue changed."); // Do not process anything when we have not yet tried to process a command when starting up. if (!hasProcessedCommandOnStartup) { LOG.info("Ignoring command queue change as commands have not yet been executed on startup."); return; } try { HostCommand command = host.getCurrentCommand(); if (command == null) { // When command queue changes, and current command is empty, move on to next command host.nextCommand(); } else { // A current command was already in place, we are still executing it. Do nothing. LOG.info("Ignoring command queue change as a command is currently being executed."); } } catch (IOException e) { LOG.error("Failed to move on to next command.", e); stop(); } }