Monitoring local files for changes
Liberty has highly dynamic behavior, responding to changes in configuration, applications and other resources. Much of this dynamic behavior is based on monitoring of the local file system for changes. The service that performs this monitoring is available to all Liberty features through the FileMonitor SPI. The file monitor service is provided by the Liberty kernel, so you do not have to specify a feature in your server.xml file to make it available.
Pourquoi et quand exécuter cette tâche
The FileMonitor SPI provides different properties to specify what resources are monitored and with what frequency. You have to implement the FileMonitor interface and register the implementation class into the service registry.
La documentation d'API Java™ pour chaque interfaces SPI Liberty est détaillée dans la section Interfaces de programmation (Javadoc) du centre de documentation et est également disponible dans un fichier .zip distinct dans l'un des sous-répertoires javadoc du répertoire ${wlp.install.dir}/dev.
Exemple
...
import com.ibm.wsspi.kernel.filemonitor.FileMonitor;
...
public class MyFileMonitor implements FileMonitor {
...
private final BundleContext bundleContex;
...
public MyFileMonitor(BundleContext bundleContext) {
this.bundleContext = BundleContext;
...
}
public ServiceRegistration<FileMonitor> monitorFiles(Collection<String> paths, long monitorInterval) {
...
final Hashtable<String, Object> fileMonitorProps = new Hashtable<String, Object>();
fileMonitorProps.put(FileMonitor.MONITOR_FILES, paths);
fileMonitorProps.put(FileMonitor.MONITOR_INTERVAL, monitorInterval);
...
return bundleContext.registerService(FileMonitor.class, this, fileMonitorProps);
}
...
}