{@inheritDoc}

@see jcifs.SmbWatchHandle#watch()
503490
@Override
    public List<FileNotifyInformation> watch () throws CIFSException {
        if ( !this.handle.isValid() ) {
            throw new SmbException("Watch was broken by tree disconnect");
        }
        try ( SmbTreeHandleImpl th = this.handle.getTree() ) {

            CommonServerMessageBlockRequest req;
            NotifyResponse resp = null;
            if ( th.isSMB2() ) {
                Smb2ChangeNotifyRequest r = new Smb2ChangeNotifyRequest(th.getConfig(), this.handle.getFileId());
                r.setCompletionFilter(this.filter);
                r.setNotifyFlags(this.recursive ? Smb2ChangeNotifyRequest.SMB2_WATCH_TREE : 0);
                req = r;
            }
            else {
                if ( !th.hasCapability(SmbConstants.CAP_NT_SMBS) ) {
                    throw new SmbUnsupportedOperationException("Not supported without CAP_NT_SMBS");
                }

                /*
                 * NtTrans Notify Change Request / Response
                 */
                req = new NtTransNotifyChange(th.getConfig(), this.handle.getFid(), this.filter, this.recursive);
                resp = new NtTransNotifyChangeResponse(th.getConfig());
            }

            if ( log.isTraceEnabled() ) {
                log.trace("Sending NtTransNotifyChange for " + this.handle);
            }
            try {
                resp = th.send(req, resp, RequestParam.NO_TIMEOUT, RequestParam.NO_RETRY);
            }
            catch ( SmbException e ) {
                if ( e.getNtStatus() == 0xC0000120 ) {
                    // cancelled
                    log.debug("Request was cancelled", e);
                    return null;
                }
                throw e;
            }
            if ( log.isTraceEnabled() ) {
                log.trace("Returned from NtTransNotifyChange " + resp.getErrorCode());
            }

            if ( !resp.isReceived() ) {
                throw new CIFSException("Did not receive response");
            }

            if ( resp.getErrorCode() == 0x10B ) {
                this.handle.markClosed();
            }
            if ( resp.getErrorCode() == 0x10C ) {
                resp.getNotifyInformation().clear();
            }
            return resp.getNotifyInformation();
        }
    }
865201
public static void watchFile(String file, SimpleHutoolWatcher watcher, boolean shouldFirstExecute) {
        if (shouldFirstExecute) {
            watcher.doSomething();
        }
        SimpleWatcher simpleWatcher = new SimpleWatcher() {
            @Override
            public void onModify(WatchEvent<?> event, Path currentPath) {
                watcher.onModify(event, currentPath);
                watcher.doSomething();
            }
        };
        try (WatchMonitor monitor = WatchMonitor.createAll(file, simpleWatcher)) {
            monitor.start();
        }
    }
302134
public function watch($resource)
    {
        if (!$this->files->exists($resource)) {
            throw new RuntimeException('Resource must exist before you can watch it.');
        } elseif ($this->files->isDirectory($resource)) {
            $resource = new DirectoryResource(new SplFileInfo($resource), $this->files);

            $resource->setupDirectory();
        } else {
            $resource = new FileResource(new SplFileInfo($resource), $this->files);
        }

        // The listener gives users the ability to bind listeners on the events
        // created when watching a file or directory. We'll give the listener
        // to the tracker so the tracker can fire any bound listeners.
        $listener = new Listener();

        $this->tracker->register($resource, $listener);

        return $listener;
    }
1118927
@Override
  public void notifyWatch(TableKraken table, byte []key)
  {
    WatchTable watchTable = _tableMap.get(table);

    if (watchTable != null) {
      watchTable.onPut(key, TableListener.TypePut.REMOTE);
    }
  }
485969
private void monitorForChanges() {
        if (monitorRunning) {
            return;
        }

        final Path path;
        try {
            path = Paths.get(configPath);
        } catch (final Exception e) {
            LOGGER.warn("Cannot monitor configuration {}, disabling monitoring; {}", configPath, e.getMessage());
            return;
        }

        if (!path.toFile().exists()) {
            LOGGER.debug("Configuration {} does not exist, disabling monitoring", configPath);
            return;
        }
        final Path directoryPath = path.getParent();

        try {
            final WatchService watchService = FileSystems.getDefault().newWatchService();
            directoryPath.register(watchService, ENTRY_MODIFY);

            monitorThread = new Thread(new Runnable() {

                @Override
                public void run() {
                    try {
                        for (;;) {
                            final WatchKey key;
                            try {
                                key = watchService.take();
                            } catch (final InterruptedException e) {
                                LOGGER.debug("Interrupted the configuration monitor thread.");
                                break;
                            }

                            for (final WatchEvent<?> event : key.pollEvents()) {
                                final WatchEvent.Kind<?> kind = event.kind();
                                if (kind == OVERFLOW) {
                                    continue;
                                }

                                // If the configuration file triggered this event, reload it
                                final Path changed = (Path) event.context();
                                if (changed.equals(path.getFileName())) {
                                    LOGGER.info(
                                            "Configuration {} has been updated, reloading.",
                                            path);
                                    try {
                                        loadConfiguration();
                                    } catch (final IOException e) {
                                        LOGGER.error("Failed to reload configuration {}", configPath, e);
                                    }
                                }

                                // reset the key
                                final boolean valid = key.reset();
                                if (!valid) {
                                    LOGGER.debug("Monitor of {} is no longer valid", path);
                                    break;
                                }
                            }
                        }
                    } finally {
                        try {
                            watchService.close();
                        } catch (final IOException e) {
                            LOGGER.error("Failed to stop configuration monitor", e);
                        }
                    }
                    monitorRunning = false;
                }
            });
        } catch (final IOException e) {
            LOGGER.error("Failed to start configuration monitor", e);
        }

        monitorThread.start();
        monitorRunning = true;
    }
79825
def watch(self, limit=None, timeout=None):
        """"""
        start_time = time.time()
        count = 0
        while not timeout or time.time() - start_time < timeout:
            new = self.read()
            if new != self.temp:
                count += 1
                self.callback(new)
                if count == limit:
                    break
            self.temp = new
            time.sleep(self.interval)
1324013
@Override
	public void monitorTarget(ResourceID resourceID, HeartbeatTarget<O> heartbeatTarget) {
		if (!stopped) {
			if (heartbeatTargets.containsKey(resourceID)) {
				log.debug("The target with resource ID {} is already been monitored.", resourceID);
			} else {
				HeartbeatManagerImpl.HeartbeatMonitor<O> heartbeatMonitor = new HeartbeatManagerImpl.HeartbeatMonitor<>(
					resourceID,
					heartbeatTarget,
					scheduledExecutor,
					heartbeatListener,
					heartbeatTimeoutIntervalMs);

				heartbeatTargets.put(
					resourceID,
					heartbeatMonitor);

				// check if we have stopped in the meantime (concurrent stop operation)
				if (stopped) {
					heartbeatMonitor.cancel();

					heartbeatTargets.remove(resourceID);
				}
			}
		}
	}
1339464
@Override
    public void run() {
        if (!mDone) {
            synchronized (this) {
                if (!mDone) {
                    call();
                    mDone = true;
                    try {
                        this.notifyAll();
                    } catch (Exception ignored) {
                    }
                }
            }
        }
    }
1140503
public static Runnable watch(Path path, PathEventListener listener) throws IOException {
		return watch(path, listener,
			StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE, StandardWatchEventKinds.ENTRY_MODIFY);
	}
40211
private void startFolderMonitor() {
    if (serverConfiguration.getAppFolderToMonitor() != null) {
      try {
        folderMonitor = new FolderMonitor(this, serverConfiguration);
        folderMonitor.start();
      } catch (IOException e) {
        log.warning("Could not monitor the given folder: "
            + serverConfiguration.getAppFolderToMonitor());
      }
    }
  }
1364408
public static void unwatch(Thread thread, Runnable task) {
        if (thread == null) {
            throw new NullPointerException("thread");
        }
        if (task == null) {
            throw new NullPointerException("task");
        }

        schedule(thread, task, false);
    }
145546
def watch_async(self, limit=None, timeout=None):
        """"""
        return self.watch(limit=limit, timeout=timeout)
932858
def watch(self, flag):
        """"""
        lib.EnvSetDefmessageHandlerWatch(
            self._env, int(flag), self._cls, self._idx)
259784
def monitor(args, watch):
    
    watch = watch if isinstance(watch, (list, tuple)) else [watch]
    watch = [Path(entry).expand().abspath() for entry in watch]
    event_handler = RunScriptChangeHandler(args)
    observer = Observer()
    for entry in watch:
        if entry.isfile():
            entry = entry.parent
        click.secho('watch recursive: {0}'.format(entry), fg='blue')
        observer.schedule(event_handler, entry, recursive=True)
    event_handler.run()  # run always once
    observer.start()

    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        observer.stop()
    observer.join()
1126678
@Override
	public void run() {
		Stopwatch stopwatch = SimonManager.getStopwatch(NAME);
		try (Split ignored = stopwatch.start();) {
			sleep(SLEEP);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		// signal to latch that the thread is finished
		latch.countDown();
	}
441687
@Override
	public synchronized void run()
	{
		List<ActiveObject> inactiveList = new ArrayList<>();
		try
		{
			log.debug("Starting activity watchdog (wakeUpInterval="+WAKE_UP_INTERVAL+"ms)");
			while (!stop)
			{
				wait(WAKE_UP_INTERVAL);
				if (stop)
					return;
				
				// Check watchlist
				long now = System.currentTimeMillis();
				synchronized (watchList)
				{
					for (int i = 0; i < watchList.size(); i++)
					{
						WeakReference<ActiveObject> weakRef = watchList.get(i);
						ActiveObject obj = weakRef.get();
						if (obj == null)
						{
							// Object was garbage collected, remove and continue
							watchList.remove(i--);
							continue;
						}
					
						// Check object activity
						if ((now - obj.getLastActivity()) > obj.getTimeoutDelay())
						{
							log.trace("Marking object as inactive : "+obj);
							inactiveList.add(obj);
						}
					}
				}
				
				// Process inactive objects
				for (int n = 0; n < inactiveList.size(); n++)
				{
					ActiveObject obj = inactiveList.get(n);
					try
					{
						if (!obj.onActivityTimeout())
							inactiveList.remove(n--);
					}
					catch (Exception e)
					{
						log.error("Error notifying an inactive object",e);
					}
				}
				
				// Remove expired objects
				synchronized (watchList)
				{
					for(int n=0;n<inactiveList.size();n++)
					{
						ActiveObject targetObj = inactiveList.get(n);
						for (int i = 0; i < watchList.size(); i++)
						{
							WeakReference<ActiveObject> weakRef = watchList.get(i);
							ActiveObject obj = weakRef.get();
							if (obj == targetObj)
							{
								log.trace("Removing inactive object from watch list : "+targetObj);
								watchList.remove(i--);
								break;
							}
						}
					}
				}
		
				// Clear inactive object list
				inactiveList.clear();
			}
			log.debug("Activity watchdog stopped");
		}
		catch (Throwable e)
		{
			log.error("Activity watchdog failed",e);
		}
	}
1359666
def start_watching(self):
        
        if not self.is_sync:
            return

        self._stop = False
        while not self._stop:
            self.reactor.doIteration(0)