org.jaffa.cache
Class CacheSourceMonitor

java.lang.Object
  extended byorg.jaffa.cache.CacheSourceMonitor

public class CacheSourceMonitor
extends Object

This is a helper class to monitor file(s), which provide data to a cache. The cache will be cleared, whenever any of the source files are modified. Note that any open iterators on the cache will have unpredictable results, whenever the cache is flushed. Create an instance of this class, providing the cache and the file(s) to be monitored. Then invoke the startMonitoring method. This will create a daemon Thread, which will monitor the files for any changes. Invoke the stopMonitoring method to stop the thread.

Author:
GautamJ

Nested Class Summary
 class CacheSourceMonitor.CacheSourceMonitorThread
          This thread class will monitor the files for any changes.
 
Constructor Summary
CacheSourceMonitor(ICache cache)
          Creates a new instance of CacheSourceMonitor.
CacheSourceMonitor(ICache cache, String file)
          Creates a new instance of CacheSourceMonitor.
 
Method Summary
 void addFile(String file)
          Add a file to be monitored for changes.
 void startMonitoring()
          This will create a daemon Thread for monitoring the files.
 void startMonitoring(int minutes)
          This will create a daemon Thread for monitoring the files.
 void stopMonitoring()
          This will stop the Thread, that was created by the call to the startMonitoring method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CacheSourceMonitor

public CacheSourceMonitor(ICache cache)
Creates a new instance of CacheSourceMonitor.

Parameters:
cache - The cache to be cleared, if any of the source files are modified.

CacheSourceMonitor

public CacheSourceMonitor(ICache cache,
                          String file)
Creates a new instance of CacheSourceMonitor.

Parameters:
cache - The cache to be cleared, if any of the source files are modified.
file - The file to be monitored. In case, the input represents a directory, then all the files (one level deep) under that directory will be monitored for any changes.
Method Detail

addFile

public void addFile(String file)
Add a file to be monitored for changes. In case, the input represents a directory, then all the files (one level deep) under that directory will be monitored for any changes.

Parameters:
file - The file to be monitored. In case, the input represents a directory, then all the files (one level deep) under that directory will be monitored for any changes.

startMonitoring

public void startMonitoring()
This will create a daemon Thread for monitoring the files. This thread will be run at the lowest priority, every 5 minutes by default.


startMonitoring

public void startMonitoring(int minutes)
This will create a daemon Thread for monitoring the files. This thread will be run at the lowest priority at the input frequency.

Parameters:
minutes - The frequency at which the files will be monitored.

stopMonitoring

public void stopMonitoring()
This will stop the Thread, that was created by the call to the startMonitoring method.



Copyright © 2002-2004 JAFFA Project.