no.feide.moria.configuration
Class ConfigurationManager

java.lang.Object
  extended by no.feide.moria.configuration.ConfigurationManager

public final class ConfigurationManager
extends java.lang.Object

The configuration manager's task is to load and monitor the configuration files for changes. Each module (authorization, web, store and directory) has a configuration file which is read and passed as a Properties object to the module at startup. The authorization module does its own file parsing, so for that module the Properties object just contains the name of the configuration file, which is then read and parsed by the authorization module. If a configuration file is changed, the entire file is reread and the updated configuration is passed to the corresponding module. The constructor requires the no.feide.moria.configuration.cm property to be set, and the property has to point to the configuration file for the ConfigurationManager module. The file can be referenced by either full file path or as a resource in the classpath.

The configuration file has to contain properties that point to the other modules' properties files. These files can be referenced by either full file path or as a resource in the classpath. The no.feide.moria.configuration.fileListenerIntervalSeconds attribute specifies the interval between each file poll.







       # Example content for ConfigurationManager properties
       no.feide.moria.configuration.fileListenerIntervalSeconds=1
       no.feide.moria.configuration.sm=/sm-test-valid.properties
       no.feide.moria.configuration.dm=/dm-test-valid.properties
       no.feide.moria.configuration.am=/am-data.xml






 

When a configuration file is changed, the content is read into a properties object which is sent to the MoriaController.

Version:
$Revision: 1.24 $
Author:
Lars Preben S. Arnesen <lars.preben.arnesen@conduct.no>
See Also:
MoriaController

Nested Class Summary
(package private)  class ConfigurationManager.FileListenerTask
          This class is used to monitor the configuration files.
 
Field Summary
private  no.feide.moria.log.MessageLogger messageLogger
          For logging events that do not throw exceptions to the layer above.
static java.lang.String MODULE_AM
          Name of the Authorization module, used in configuration properties.
private static java.lang.String MODULE_CM
          Name of the Configuration module, used in configuration properties.
static java.lang.String MODULE_DM
          Name of the Directory module, used in configuration properties.
static java.lang.String MODULE_SM
          Name of the Store module, used in configuration properties.
static java.lang.String MODULE_WEB
          Name of the Web module, used in configuration properties.
private static java.lang.String[] NEEDS_LISTENER
          List of the modules that have configuration to watch.
private static java.lang.String PROPS_PREFIX
          Attribute name prefix for file name properties.
private  java.util.Timer timer
          Timer for the configuration files.
private static java.lang.String TIMER_DELAY
          Attribute name for timer delay.
private  java.util.HashMap timerEntries
          Storage for all timers.
 
Constructor Summary
ConfigurationManager()
          Constructor.
 
Method Summary
private  void addFileChangeListener(java.lang.String fileName, java.lang.String module, int intervalSec)
          Monitor a file.
 void destroy()
          Destructor.
private  void fileChangeEvent(java.lang.String module, java.io.File configurationFile)
          Send changed configuration to MoriaController.
private static java.io.File fileForURI(java.lang.String fileURI)
          Resolves a fileURI to a File object.
(package private)  int numFileListeners()
          Number of active file listeners.
private static java.util.Properties readProperties(java.lang.String fileURI)
          Read properties from file.
private  void removeFileChangeListener(java.lang.String fileName)
          Stop monitoring file.
 void stop()
          Remove all file listeners.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

messageLogger

private final no.feide.moria.log.MessageLogger messageLogger
For logging events that do not throw exceptions to the layer above.


MODULE_SM

public static final java.lang.String MODULE_SM
Name of the Store module, used in configuration properties.

See Also:
Constant Field Values

MODULE_DM

public static final java.lang.String MODULE_DM
Name of the Directory module, used in configuration properties.

See Also:
Constant Field Values

MODULE_AM

public static final java.lang.String MODULE_AM
Name of the Authorization module, used in configuration properties.

See Also:
Constant Field Values

MODULE_CM

private static final java.lang.String MODULE_CM
Name of the Configuration module, used in configuration properties.

See Also:
Constant Field Values

MODULE_WEB

public static final java.lang.String MODULE_WEB
Name of the Web module, used in configuration properties.

See Also:
Constant Field Values

TIMER_DELAY

private static final java.lang.String TIMER_DELAY
Attribute name for timer delay.

See Also:
Constant Field Values

PROPS_PREFIX

private static final java.lang.String PROPS_PREFIX
Attribute name prefix for file name properties.

See Also:
Constant Field Values

NEEDS_LISTENER

private static final java.lang.String[] NEEDS_LISTENER
List of the modules that have configuration to watch.


timer

private final java.util.Timer timer
Timer for the configuration files.


timerEntries

private final java.util.HashMap timerEntries
Storage for all timers.

Constructor Detail

ConfigurationManager

public ConfigurationManager()
                     throws ConfigurationManagerException
Constructor. The constructor reads the ConfigurationManager's properties from file (set by System.properties) and starts file listeners for all modules' configuration files.

Throws:
BaseConfigException - If the system property pointing to the base configuration file is not a non-empty string.
ConfigurationManagerException - If there are any problems with the configuration file.
Method Detail

stop

public void stop()
Remove all file listeners.


destroy

public void destroy()
Destructor. Will call stop().

See Also:
stop()

numFileListeners

int numFileListeners()
Number of active file listeners. Basically needed for testing.

Returns:
The number of active file listeners.

readProperties

private static java.util.Properties readProperties(java.lang.String fileURI)
                                            throws java.io.IOException
Read properties from file. The fileURI can be absolute path to file or relative to the classpath. If the fileURI does not resolve to a readeble file, anIOException or IllegalArgumentExceptionis thrown.

Parameters:
fileURI - The reference to the properties file.
Returns:
Properties from the file.
Throws:
java.io.IOException - If something goes wrong during file read.
java.lang.IllegalArgumentException - If fileURI is not a non-empty string.

addFileChangeListener

private void addFileChangeListener(java.lang.String fileName,
                                   java.lang.String module,
                                   int intervalSec)
                            throws java.io.FileNotFoundException
Monitor a file. A new file listener is started for the module's properties file. If the file cannot be read, a FileNotFoundException is thrown.

Parameters:
fileName - Full path or relative (classpath) path to the properties file.
module - The module the configuration file belongs to.
intervalSec - Polling period in seconds.
Throws:
java.io.FileNotFoundException - If the file is not found.

removeFileChangeListener

private void removeFileChangeListener(java.lang.String fileName)
Stop monitoring file.

Parameters:
fileName - The file name to stop monitoring.

fileChangeEvent

private void fileChangeEvent(java.lang.String module,
                             java.io.File configurationFile)
Send changed configuration to MoriaController.

Parameters:
module - The module the configuration file belongs to.
configurationFile - A File object representing the changed file.
See Also:
MoriaController.setConfig(java.lang.String, java.util.Properties)

fileForURI

private static java.io.File fileForURI(java.lang.String fileURI)
                                throws java.io.FileNotFoundException
Resolves a fileURI to a File object.

Parameters:
fileURI - Reference to the file (full path or relative within the classpath).
Returns:
A File object referenced by the fileURI.
Throws:
java.io.FileNotFoundException - If the fileURI cannot be resolved to a readable file.


Copyright © 2001-2006 UNINETT FAS. All Rights Reserved.