private void notifyChanges() { if (notificationListener != null) { notificationListener.announce(notificationChannel, notificationInstanceId); } }
@Override protected void watchEventsOccurred() { walkTreeAndSetWatches(); unregisterStaleWatches(); }
@Override protected void beforePollEventLoop() { walkTreeAndSetWatches(); }
@Override public void run() { try { WatchOperationOptions watchOperationOptions = new WatchOperationOptions(); watchOperationOptions.setAnnouncements(false); watchOperationOptions.setWatcher(false); watchOperationOptions.setInterval(interval); watch(watchOperationOptions); } catch (Exception e) { throw new RuntimeException(e); } } }, "watchOperationsThread");
@Override public int execute(String[] operationArgs) throws Exception { WatchOperationOptions operationOptions = parseOptions(operationArgs); new WatchOperation(config, operationOptions).execute(); return 0; }
private void startNotificationListener() { logger.log(Level.INFO, "Starting notification listener for " + config.getLocalDir() + " ..."); notificationListener = new NotificationListener(options.getAnnouncementsHost(), options.getAnnouncementsPort(), this); notificationListener.start(); notificationListener.subscribe(notificationChannel); }
public WatchRunner(Config config, WatchOperationOptions watchOperationOptions, PortTO portTO) throws ConfigException { this.config = config; this.portTO = portTO; this.watchOperation = new WatchOperation(config, watchOperationOptions); this.eventBus = LocalEventBus.getInstance(); this.eventBus.register(this); }
@Override public void watchEventsOccurred() { try { waitWhilePaused(); runSync(); } catch (Exception e) { logger.log(Level.INFO, "Sync FAILED (event-triggered).", e); } }
public void start() { logger.log(Level.INFO, "Starting notification listener thread ..."); stop(); incomingMessageThread = new SocketThread(); incomingMessageThread.start(); }
/** * Creates a recursive watcher for the given root path. The returned watcher * will ignore the ignore paths and fire an event through the {@link WatchListener} * as soon as the settle delay (in ms) has passed. * * <p>The method returns a platform-specific recursive watcher: {@link WindowsRecursiveWatcher} * for Windows and {@link DefaultRecursiveWatcher} for other operating systems. */ public static RecursiveWatcher createRecursiveWatcher(Path root, List<Path> ignorePaths, int settleDelay, WatchListener listener) { if (EnvironmentUtil.isWindows()) { return new WindowsRecursiveWatcher(root, ignorePaths, settleDelay, listener); } else { return new DefaultRecursiveWatcher(root, ignorePaths, settleDelay, listener); } }
public boolean isSyncRunning() { return watchOperation.isSyncRunning(); }
@Override public void run() { logger.log(Level.INFO, "File system actions (on watched folders) settled. Updating watches ..."); watchEventsOccurred(); fireListenerEvents(); } }, settleDelay);
private synchronized void fireListenerEvents() { if (listener != null) { logger.log(Level.INFO, "- Firing watch event (watchEventsOccurred) ..."); listener.watchEventsOccurred(); } }
private void processIncomingMessage(String messageLine) { String[] messageParts = messageLine.split("!"); if (messageParts.length == 2) { String channel = messageParts[0]; String message = messageParts[1]; if (!"debug".equals(channel)) { logger.log(Level.INFO, "Received message for channel " + channel + ": " + message); listener.pushNotificationReceived(channel, message); } } } }
public void announce(String channel, String message) { logger.log(Level.INFO, "Announcing to channel " + channel + ": " + message.trim()); sendMessageOrAddToOutgoingQueue(String.format("announce %s %s\n", channel, message)); }
private void stopRecursiveWatcher() { try { logger.log(Level.INFO, "Stopping recursive watcher for " + config.getLocalDir() + " ..."); recursiveWatcher.stop(); } catch (Exception e) { logger.log(Level.WARNING, "Cannot stop file watcher.", e); } }
public void stop() { watchOperation.stop(); config.getPortFile().delete(); watchThread = null; }
private void stopNotificationListener() { logger.log(Level.INFO, "Stopping notification listener for " + config.getLocalDir() + " ..."); notificationListener.stop(); }
public void watch(WatchOperationOptions options) throws Exception { new WatchOperation(config, options).execute(); }
@Override public void pushNotificationReceived(String channel, String message) { if (channel.equals(notificationChannel) && !message.equals(notificationInstanceId)) { try { waitWhilePaused(); runSync(); } catch (Exception e) { logger.log(Level.INFO, "Sync FAILED (event-triggered).", e); } } }