Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
cherylking committed Oct 20, 2023
1 parent df4b23f commit 82bc11a
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3247,7 +3247,7 @@ private void registerSingleFile(final File registerFile, final ThreadPoolExecuto
* @throws IOException unable to read the canonical path name
*/
private void registerSingleFile(final File registerFile, final ThreadPoolExecutor executor, boolean removeOnContainerRebuild) throws IOException {
if (trackingMode == FileTrackMode.POLLING || trackingMode == FileTrackMode.NOT_SET) {
if (trackingMode == FileTrackMode.POLLING || trackingMode == FileTrackMode.NOT_SET) {
String parentPath = registerFile.getParentFile().getCanonicalPath();

debug("Registering single file polling for " + registerFile.toString());
Expand All @@ -3265,11 +3265,6 @@ private void registerSingleFile(final File registerFile, final ThreadPoolExecuto
if (parentPath.equals(observer.getDirectory().getCanonicalPath())) {
debug("Updating file polling for " + registerFile.toString() + " since its parent directory is already being observed");
existingObserver = observer;
if (fileObservers.contains(existingObserver)) {
debug("Found existing observer in fileObservers");
} else if (newFileObservers.contains(existingObserver)) {
debug("Found existing observer in newFileObservers");
}
}
}

Expand Down Expand Up @@ -3299,8 +3294,8 @@ public boolean accept(File file) {
observer = addFileAlterationObserver(executor, parentPath, singleFileFilter);
}
if (removeOnContainerRebuild) {
debug("Adding file to containerfileDirectoriesFileObservers: " + registerFile.toString());
containerfileDirectoriesFileObservers.add(observer);
debug("Adding file to containerfileDirectoriesFileObservers: " + registerFile.toString());
containerfileDirectoriesFileObservers.add(observer);
}
} catch (Exception e) {
error("Could not observe single file " + registerFile.toString(), e);
Expand All @@ -3324,14 +3319,22 @@ public boolean accept(File file) {

private FileAlterationObserver addFileAlterationObserver(final ThreadPoolExecutor executor, FileAlterationObserver observer, String parentPath, FileFilter filter)
throws Exception {
// create new observer for filter
FileAlterationObserver newObserver = getFileAlterationObserver(executor, parentPath, filter);
// iterate through existing listeners on observer and add them to newObserver
for (FileAlterationListener nextListener: observer.getListeners()) {
newObserver.addListener(nextListener);
}
newObserver.initialize();
// clean up old existing observer
// clean up previous observer
fileObservers.remove(observer);
newFileObservers.remove(observer);
try {
// destroy the observer
observer.destroy();
} catch (Exception e) {
debug("Could not destroy file observer", e);
}
// add new observer with the combined listeners
newFileObservers.add(newObserver);
return newObserver;
Expand Down

0 comments on commit 82bc11a

Please sign in to comment.