監視本端檔案的變更

對於配置、應用程式及其他資源中的變更,Liberty 有高度動態的回應行為。這個動態行為大部分是以監視本端檔案系統的變更為基礎。 所有 Liberty 特性都可以透過 FileMonitor SPI 來使用執行這項監視的服務。檔案監視服務是由 Liberty 核心所提供,因此您不需要在 server.xml 檔中指定特性來使其可供使用。

關於這項作業

FileMonitor SPI 提供不同的內容來指定要監視哪些資源,以及監視的頻率。 您必須實作 FileMonitor 介面,以及將實作類別登錄在服務登錄中。

每一個 Liberty SPI 的 Java™ API 說明文件都詳述於資訊中心的程式設計介面 (Javadoc) 一節,也以個別的 .zip 檔來提供(其位於 ${wlp.install.dir}/dev 目錄下的其中一個 javadoc 子目錄中)。

範例

...
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);
  }
  ...
}

指示主題類型的圖示 作業主題

檔名:twlp_monitor_local_files.html