public void stop() { watchOperation.stop(); config.getPortFile().delete(); watchThread = null; }
@Override public void run() { try { logger.log(Level.INFO, "STARTING watch at" + config.getLocalDir()); watchOperationResult = null; // Write port to portFile File portFile = config.getPortFile(); portFile.createNewFile(); portFile.deleteOnExit(); new Persister().write(portTO, portFile); // Start operation (blocks!) watchOperationResult = watchOperation.execute(); logger.log(Level.INFO, "STOPPED watch at " + config.getLocalDir()); } catch (Exception e) { logger.log(Level.SEVERE, "ERROR while running watch at " + config.getLocalDir(), e); } } }, "WR/" + config.getLocalDir().getName());
private int runCommand(Command command, String commandName, String[] commandArgs) { File portFile = null; if (config != null) { portFile = config.getPortFile(); } File daemonPidFile = new File(UserConfig.getUserConfigDir(), DaemonOperation.PID_FILE); boolean localDirHandledInDaemonScope = portFile != null && portFile.exists(); boolean daemonRunning = PidFileUtil.isProcessRunning(daemonPidFile); boolean needsToRunInInitializedScope = command.getRequiredCommandScope() == CommandScope.INITIALIZED_LOCALDIR; boolean sendToRest = daemonRunning & localDirHandledInDaemonScope && needsToRunInInitializedScope; command.setOut(out); if (sendToRest) { if (command.canExecuteInDaemonScope()) { return sendToRest(command, commandName, commandArgs, portFile); } else { logger.log(Level.SEVERE, "Command not allowed when folder is daemon-managed: " + command.toString()); return showErrorAndExit("Command not allowed when folder is daemon-managed"); } } else { return runLocally(command, commandArgs); } }