org.jcomet.dynamic
Class DynamicProperties

java.lang.Object
  extended byjava.util.Dictionary
      extended byjava.util.Hashtable
          extended byjava.util.Properties
              extended byorg.jcomet.dynamic.DynamicProperties
All Implemented Interfaces:
java.lang.Cloneable, FileChangeListener, java.util.Map, Reloadable, java.io.Serializable

public class DynamicProperties
extends java.util.Properties
implements Reloadable, FileChangeListener

This object can monitor its source configuration file and reload when even it is modified. It is also provides the ability to register listeners that are notified when properties change.

Author:
Amir Shevat
See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.Properties
defaults
 
Constructor Summary
DynamicProperties()
           
 
Method Summary
 void fileChanged(java.io.File file)
          Internal use - do not invoke
protected  void finalize()
          Internal use - do not invoke
 PropertyChangedListener getPropertyChangedListener()
          Returns the PropertyChangedListener of this object
 void load(java.io.File propFile)
          Creates a DynamicProperties that does not monitor its source file.
 void load(java.io.File propFile, long monitorInterval)
          Once loaded this object will monitor and reload every change to its source file.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          same as super but with a notification addon
 void reload()
          Forces this Object to reload all its source files and notify the listener of any change in them
 void setPropertyChangedListener(PropertyChangedListener propertyChangedListener)
          Sets the PropertyChangedListener of this object, application should use this method to register themselves as listeners
 
Methods inherited from class java.util.Properties
getProperty, getProperty, list, list, load, propertyNames, save, setProperty, store
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, putAll, rehash, remove, size, toString, values
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DynamicProperties

public DynamicProperties()
Method Detail

load

public void load(java.io.File propFile)
          throws java.io.IOException
Creates a DynamicProperties that does not monitor its source file. User can still reload when ever there is a need.

Throws:
java.io.IOException

load

public void load(java.io.File propFile,
                 long monitorInterval)
          throws java.io.IOException
Once loaded this object will monitor and reload every change to its source file.

Parameters:
monitorInterval - -1 for "do not monitor", greater then 0 for "monitor every monitorInterval" (milli)
Throws:
java.io.IOException

reload

public void reload()
Forces this Object to reload all its source files and notify the listener of any change in them

Specified by:
reload in interface Reloadable

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
same as super but with a notification addon

Specified by:
put in interface java.util.Map

fileChanged

public void fileChanged(java.io.File file)
                 throws java.io.IOException
Internal use - do not invoke

Specified by:
fileChanged in interface FileChangeListener
Parameters:
file - the file that was changed
Throws:
java.io.IOException

finalize

protected void finalize()
                 throws java.lang.Throwable
Internal use - do not invoke

Throws:
java.lang.Throwable

getPropertyChangedListener

public PropertyChangedListener getPropertyChangedListener()
Returns the PropertyChangedListener of this object

Returns:
the PropertyChangedListener of this object

setPropertyChangedListener

public void setPropertyChangedListener(PropertyChangedListener propertyChangedListener)
Sets the PropertyChangedListener of this object, application should use this method to register themselves as listeners

Parameters:
propertyChangedListener - PropertyChangedListener of this object


Copyright spacebug Open source initiative (www.spacebug.com). Amir Shevat