Top Description Fields Constructors Methods
org.jabref.gui.util

public Class DefaultFileUpdateMonitor

extends Object
implements Runnable, FileUpdateMonitor
Class Inheritance
All Implemented Interfaces
org.jabref.model.util.FileUpdateMonitor, java.lang.Runnable
Imports
java.io.IOException, java.nio.file.ClosedWatchServiceException, .FileSystems, .Path, .StandardWatchEventKinds, .WatchEvent, .WatchKey, .WatchService, java.util.Optional, java.util.concurrent.atomic.AtomicBoolean, .AtomicReference, org.jabref.logic.JabRefException, .WatchServiceUnavailableException, org.jabref.model.util.FileUpdateListener, .FileUpdateMonitor, com.google.common.collect.ArrayListMultimap, .Multimap, org.slf4j.Logger, .LoggerFactory

This class monitors a set of files for changes. Upon detecting a change it notifies the registered FileUpdateListeners.

Implementation based on https://stackoverflow.com/questions/16251273/can-i-watch-for-single-file-change-with-watchservice-not-the-whole-directory.

Field Summary

Modifier and TypeField and Description
private final AtomicReference<Optional<JabRefException>>
private final Multimap<Path, FileUpdateListener>
private static final Logger
private final AtomicBoolean
private volatile WatchService

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
addListenerForFile(Path
The file to monitor.
file
,
FileUpdateListener listener)

Implements org.jabref.model.util.FileUpdateMonitor.addListenerForFile.

Add a new file to monitor.

public boolean
isActive()

Implements org.jabref.model.util.FileUpdateMonitor.isActive.

Indicates whether the native system's file monitor has successfully started.

private void
public void
removeListener(Path
The path to remove.
path
,
FileUpdateListener listener)

Implements org.jabref.model.util.FileUpdateMonitor.removeListener.

Removes a listener from the monitor.

public void
run()

Implements java.lang.Runnable.run.

Runs this operation.

public void
shutdown()

Implements org.jabref.model.util.FileUpdateMonitor.shutdown.

stops watching for changes

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

filesystemMonitorFailureback to summary
private final AtomicReference<Optional<JabRefException>> filesystemMonitorFailure
listenersback to summary
private final Multimap<Path, FileUpdateListener> listeners
LOGGERback to summary
private static final Logger LOGGER
notShutdownback to summary
private final AtomicBoolean notShutdown
watcherback to summary
private volatile WatchService watcher

Constructor Detail

DefaultFileUpdateMonitorback to summary
public DefaultFileUpdateMonitor()

Method Detail

addListenerForFileback to summary
public void addListenerForFile(Path file, FileUpdateListener listener) throws IOException

Implements org.jabref.model.util.FileUpdateMonitor.addListenerForFile.

Doc from org.jabref.model.util.FileUpdateMonitor.addListenerForFile.

Add a new file to monitor.

Parameters
file:Path

The file to monitor.

Annotations
@Override
Exceptions
IOException:
if the file does not exist.
isActiveback to summary
public boolean isActive()

Implements org.jabref.model.util.FileUpdateMonitor.isActive.

Doc from org.jabref.model.util.FileUpdateMonitor.isActive.

Indicates whether the native system's file monitor has successfully started.

Returns:boolean

true is process is running; false otherwise.

Annotations
@Override
notifyAboutChangeback to summary
private void notifyAboutChange(Path path)
removeListenerback to summary
public void removeListener(Path path, FileUpdateListener listener)

Implements org.jabref.model.util.FileUpdateMonitor.removeListener.

Doc from org.jabref.model.util.FileUpdateMonitor.removeListener.

Removes a listener from the monitor.

Parameters
path:Path

The path to remove.

Annotations
@Override
runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override
shutdownback to summary
public void shutdown()

Implements org.jabref.model.util.FileUpdateMonitor.shutdown.

Doc from org.jabref.model.util.FileUpdateMonitor.shutdown.

stops watching for changes

Annotations
@Override