@Override
    public void run() {
        while(true) {
            WatchKey key;
            try {
                key = watcher.take();
            } catch (InterruptedException e) {
                log.warn(e);
                continue;
            }

            List<FileInfo> fileInfos = addOnMap.get(key);
            checkAndProcessFileInfo(key, fileInfos);

            // reset key and remove from set if directory no longer accessible
            boolean valid = key.reset();
            if (!valid) {
                addOnMap.remove(key);

                // all directories are inaccessible
                if (addOnMap.isEmpty()) {
                    break;
                }
            }
        }
    }
@ Override public void run ( ) { while ( true ) { WatchKey key ; try { key = watcher . take ( ) ; } catch ( InterruptedException e ) { log . warn ( e ) ; continue ; } List < FileInfo > fileInfos = addOnMap . get ( key ) ; checkAndProcessFileInfo ( key , fileInfos ) ; boolean valid = key . reset ( ) ; if ( ! valid ) { addOnMap . remove ( key ) ; if ( addOnMap . isEmpty ( ) ) { break ; } } } }
Main method of fileManager, it constantly waits for new events and then processes them