org.sape.carbon.core.config.node.file
Class ConfigurationFileMonitor

java.lang.Object
  |
  +--org.sape.carbon.core.config.node.file.ConfigurationFileMonitor
All Implemented Interfaces:
ConfigurationEventListener, EventListener

public class ConfigurationFileMonitor
extends Object
implements ConfigurationEventListener

This class manages a thread that monitors files for changes at a periodic interval. When a file is changed or removed, it is detected and the corresponding configuration node is refreshed.

Copyright 2003 Sapient

Since:
carbon 2.2
Version:
$Revision: 1.1 $($Author: dvoet $ / $Date: 2003/12/18 18:42:14 $)
Author:
Douglas Voet, Dec 11, 2003

Nested Class Summary
private  class ConfigurationFileMonitor.Monitor
          Runnable class that implements the monitor thread's functionality.
private static class ConfigurationFileMonitor.NodeInfo
          Helper class that maintains info about a node and its file.
 
Field Summary
private  org.apache.commons.logging.Log log
           
private  Map monitoredFiles
          synchronized map of files that are being monitored key = (String) node absolute name value = NodeInfo object
private  Thread monitorThread
          Thread monitoring files
private  long pollInterval
          The interval at which the files are polled to see if they have changed
private  String threadName
          Name of the trhead
 
Constructor Summary
ConfigurationFileMonitor(Node entryPoint, long pollInterval)
          Constructs a new ConfigurationFileMonitor
 
Method Summary
private  void addFileToMonitor(Node fileNode)
          Helper method to add a file to the monitor
 void childAdded(Node parent, Node child)
          updates the last modifed timestamp associate with parent and adds child to the monitored files map
 void childLoaded(Node parent, Node child)
          adds child to the monitored files map
 void interrupt()
          Interrupts the monitor thread.
private  void monitorThreadEnded()
           
 void nodeModified(Node node)
          Updates the last modifed timestamp associated with the node
 void nodeRemoved(String removedNodeName)
          removes the node from the monitored files map
 void start()
          Starts the monitor thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private org.apache.commons.logging.Log log

monitoredFiles

private Map monitoredFiles
synchronized map of files that are being monitored key = (String) node absolute name value = NodeInfo object


monitorThread

private Thread monitorThread
Thread monitoring files


threadName

private String threadName
Name of the trhead


pollInterval

private long pollInterval
The interval at which the files are polled to see if they have changed

Constructor Detail

ConfigurationFileMonitor

public ConfigurationFileMonitor(Node entryPoint,
                                long pollInterval)
Constructs a new ConfigurationFileMonitor

Parameters:
entryPoint - the node that is the root of configuration hierachy that is to be monitored. This does not need to be the root of the entire configuration hierachy.
pollInterval - the interval at which the files are polled to see if they have changed
Method Detail

nodeModified

public void nodeModified(Node node)
Updates the last modifed timestamp associated with the node

Specified by:
nodeModified in interface ConfigurationEventListener
Parameters:
node - the node that has been modified

childAdded

public void childAdded(Node parent,
                       Node child)
updates the last modifed timestamp associate with parent and adds child to the monitored files map

Specified by:
childAdded in interface ConfigurationEventListener
Parameters:
parent - the node the child was added to
child - the child that was added

childLoaded

public void childLoaded(Node parent,
                        Node child)
adds child to the monitored files map

Specified by:
childLoaded in interface ConfigurationEventListener
Parameters:
parent - the node that loaded the child
child - the child that was loaded

nodeRemoved

public void nodeRemoved(String removedNodeName)
removes the node from the monitored files map

Specified by:
nodeRemoved in interface ConfigurationEventListener
Parameters:
removedNodeName - the absolute name of the removed node

interrupt

public void interrupt()
Interrupts the monitor thread. The thread can be restarted by calling the start method.


start

public void start()
Starts the monitor thread.


monitorThreadEnded

private void monitorThreadEnded()

addFileToMonitor

private void addFileToMonitor(Node fileNode)
Helper method to add a file to the monitor

Parameters:
fileNode -


Copyright 1999-2003 Sapient Corporation. All Rights Reserved.