Class ConfigurationHandler
- java.lang.Object
-
- org.opends.server.config.ConfigurationHandler
-
- All Implemented Interfaces:
ConfigurationRepository,AlertGenerator
public class ConfigurationHandler extends Object implements ConfigurationRepository, AlertGenerator
Responsible for managing configuration, including listeners on configuration entries.Configuration is represented by configuration entries, persisted on the file system. Configuration entries are initially read from configuration file ("config/config.ldif" by default), then stored in a
MemoryBackendduring server uptime.The handler allows to register and unregister some listeners on any configuration entry (add, change or delete listener). Configuration entries can be added, replaced or deleted to the handler. Any change of a configuration entry will trigger the listeners registered for this entry, and will also trigger an update of configuration file.
The handler also maintains an up-to-date archive of configuration files.
-
-
Constructor Summary
Constructors Constructor Description ConfigurationHandler(ServerContext serverContext)Creates a new instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddEntry(Entry entry)Add a configuration entry.static ConfigurationHandlerbootstrapConfiguration(ServerContext serverContext)Bootstraps the server configuration.voiddeleteEntry(Dn dn)Delete a configuration entry.voidderegisterAddListener(Dn dn, ConfigAddListener listener)Deregisters the provided add listener so that it will no longer be notified if any new entries are added immediately below the entry corresponding to the provided DN.voidderegisterChangeListener(Dn dn, ConfigChangeListener listener)Attempts to deregister the provided change listener with the provided DN.voidderegisterDeleteListener(Dn dn, ConfigDeleteListener listener)Deregisters the provided delete listener so that it will no longer be notified if any entries are deleted immediately below the entry corresponding to the provided DN.voidfinalize()Finalizes the configuration handler.List<ConfigAddListener>getAddListeners(Dn dn)Retrieves the add listeners that have been registered with the provided DN.Map<String,String>getAlerts()Retrieves information about the set of alerts that this generator may produce.List<ConfigChangeListener>getChangeListeners(Dn dn)Retrieves the change listeners that have been registered with the provided DN.Set<Dn>getChildren(Dn dn)Returns the set of DNs of children of the entry corresponding to the provided DN.DngetComponentEntryDN()Retrieves the DN of the configuration entry with which this alert generator is associated.PathgetConfigurationFile()Returns the configuration file containing all configuration entries.List<ConfigDeleteListener>getDeleteListeners(Dn dn)Retrieves the delete listeners that have been registered with the provided DN.EntrygetEntry(Dn dn)Returns the configuration entry for the provided DN.EntrygetRootEntry()Returns the configuration root entry.booleanhasEntry(Dn dn)Checks if the provided DN corresponds to a configuration entry.longnumSubordinates(Dn entryDN, boolean subtree)Retrieves the number of subordinates for the requested entry.voidregisterAddListener(Dn dn, ConfigAddListener listener)Registers the provided add listener so that it will be notified if any new entries are added immediately below the entry corresponding to the provided DN.voidregisterChangeListener(Dn dn, ConfigChangeListener listener)Registers the provided change listener so that it will be notified of any changes to the entry corrresponding to provided DN.voidregisterDeleteListener(Dn dn, ConfigDeleteListener listener)Registers the provided delete listener so that it will be notified if any entries are deleted immediately below the entry corresponding to the provided DN.voidreinitializeWithFullSchema(Schema schema)Re-initializes the configuration handler with a fully initialized schema.voidreplaceEntry(Entry oldEntry, Entry newEntry)Replaces the old configuration entry with the new configuration entry provided.voidsearch(SearchOperation searchOperation)Search the configuration entries.voidwriteLDIF(LDIFExportConfig exportConfig)Writes the current configuration to LDIF with the provided export configuration.voidwriteSuccessfulStartupConfig()Generates a configuration file with the ".startok" suffix, representing a configuration file that has a successful start.-
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.opends.server.api.AlertGenerator
getClassName
-
-
-
-
Constructor Detail
-
ConfigurationHandler
public ConfigurationHandler(ServerContext serverContext)
Creates a new instance.- Parameters:
serverContext- The server context.
-
-
Method Detail
-
bootstrapConfiguration
public static ConfigurationHandler bootstrapConfiguration(ServerContext serverContext) throws InitializationException
Bootstraps the server configuration.The returned ConfigurationHandler is initialized with a partial schema and must be later re-initialized with the full schema by calling
reinitializeWithFullSchema(Schema)method once the schema has been fully loaded.- Parameters:
serverContext- The server context.- Returns:
- the configuration handler
- Throws:
InitializationException- If an error occurs during bootstrapping.
-
reinitializeWithFullSchema
public void reinitializeWithFullSchema(Schema schema) throws InitializationException
Re-initializes the configuration handler with a fully initialized schema.Previously registered listeners are preserved.
- Parameters:
schema- The server schema, fully initialized.- Throws:
InitializationException- If an error occurs.
-
finalize
public void finalize()
Finalizes the configuration handler.
-
getAlerts
public Map<String,String> getAlerts()
Description copied from interface:AlertGeneratorRetrieves information about the set of alerts that this generator may produce. The map returned should be between the notification type for a particular notification and the human-readable description for that notification. This alert generator must not generate any alerts with types that are not contained in this list.- Specified by:
getAlertsin interfaceAlertGenerator- Returns:
- Information about the set of alerts that this generator may produce.
-
getChildren
public Set<Dn> getChildren(Dn dn) throws ConfigException
Description copied from interface:ConfigurationRepositoryReturns the set of DNs of children of the entry corresponding to the provided DN. .- Specified by:
getChildrenin interfaceConfigurationRepository- Parameters:
dn- DN of a configuration entry.- Returns:
- the set of DN of children of the corresponding entry
- Throws:
ConfigException- If a problem occurs during retrieval.
-
getComponentEntryDN
public Dn getComponentEntryDN()
Description copied from interface:AlertGeneratorRetrieves the DN of the configuration entry with which this alert generator is associated.- Specified by:
getComponentEntryDNin interfaceAlertGenerator- Returns:
- The DN of the configuration entry with which this alert generator is associated.
-
getConfigurationFile
public Path getConfigurationFile()
Returns the configuration file containing all configuration entries.- Returns:
- the configuration file
-
getEntry
public Entry getEntry(Dn dn)
Description copied from interface:ConfigurationRepositoryReturns the configuration entry for the provided DN.- Specified by:
getEntryin interfaceConfigurationRepository- Parameters:
dn- DN of the configuration entry- Returns:
- the config entry
-
getRootEntry
public Entry getRootEntry()
Returns the configuration root entry.- Returns:
- the root entry
-
getAddListeners
public List<ConfigAddListener> getAddListeners(Dn dn)
Description copied from interface:ConfigurationRepositoryRetrieves the add listeners that have been registered with the provided DN.- Specified by:
getAddListenersin interfaceConfigurationRepository- Parameters:
dn- The DN of the configuration entry.- Returns:
- The list of add listeners.
-
getChangeListeners
public List<ConfigChangeListener> getChangeListeners(Dn dn)
Description copied from interface:ConfigurationRepositoryRetrieves the change listeners that have been registered with the provided DN.- Specified by:
getChangeListenersin interfaceConfigurationRepository- Parameters:
dn- The DN of the configuration entry.- Returns:
- The list of change listeners.
-
getDeleteListeners
public List<ConfigDeleteListener> getDeleteListeners(Dn dn)
Description copied from interface:ConfigurationRepositoryRetrieves the delete listeners that have been registered with the provided DN.- Specified by:
getDeleteListenersin interfaceConfigurationRepository- Parameters:
dn- The DN of the configuration entry.- Returns:
- The list of delete listeners.
-
hasEntry
public boolean hasEntry(Dn dn)
Description copied from interface:ConfigurationRepositoryChecks if the provided DN corresponds to a configuration entry.- Specified by:
hasEntryin interfaceConfigurationRepository- Parameters:
dn- DN of the configuration entry- Returns:
trueif and only if there is a configuration entry with this DN
-
search
public void search(SearchOperation searchOperation)
Search the configuration entries.- Parameters:
searchOperation- Defines the search to perform
-
numSubordinates
public long numSubordinates(Dn entryDN, boolean subtree) throws ConfigException
Retrieves the number of subordinates for the requested entry.- Parameters:
entryDN- The distinguished name of the entry.subtree-trueto include all entries from the requested entry to the lowest level in the tree orfalseto only include the entries immediately below the requested entry.- Returns:
- The number of subordinate entries
- Throws:
ConfigException- If a problem occurs while trying to retrieve the entry.
-
addEntry
public void addEntry(Entry entry) throws LdapException
Add a configuration entry.The add is performed only if all Add listeners on the parent entry accept the changes. Once the change is accepted, entry is effectively added and all Add listeners are called again to apply the change resulting from this new entry.
- Parameters:
entry- The configuration entry to add.- Throws:
LdapException- If an error occurs.
-
deleteEntry
public void deleteEntry(Dn dn) throws LdapException
Delete a configuration entry.The delete is performed only if all Delete listeners on the parent entry accept the changes. Once the change is accepted, entry is effectively deleted and all Delete listeners are called again to apply the change resulting from this deletion.
- Parameters:
dn- DN of entry to delete.- Throws:
LdapException- If a problem occurs.
-
replaceEntry
public void replaceEntry(Entry oldEntry, Entry newEntry) throws LdapException
Replaces the old configuration entry with the new configuration entry provided.The replacement is performed only if all Change listeners on the entry accept the changes. Once the change is accepted, entry is effectively replaced and all Change listeners are called again to apply the change resulting from the replacement.
- Parameters:
oldEntry- The original entry that is being replaced.newEntry- The new entry to use in place of the existing entry with the same DN.- Throws:
LdapException- If a problem occurs while trying to replace the entry.
-
registerAddListener
public void registerAddListener(Dn dn, ConfigAddListener listener)
Description copied from interface:ConfigurationRepositoryRegisters the provided add listener so that it will be notified if any new entries are added immediately below the entry corresponding to the provided DN.- Specified by:
registerAddListenerin interfaceConfigurationRepository- Parameters:
dn- The DN of the configuration entry.listener- The add listener that should be registered.
-
registerDeleteListener
public void registerDeleteListener(Dn dn, ConfigDeleteListener listener)
Description copied from interface:ConfigurationRepositoryRegisters the provided delete listener so that it will be notified if any entries are deleted immediately below the entry corresponding to the provided DN.- Specified by:
registerDeleteListenerin interfaceConfigurationRepository- Parameters:
dn- The DN of the configuration entry.listener- The delete listener that should be registered.
-
registerChangeListener
public void registerChangeListener(Dn dn, ConfigChangeListener listener)
Description copied from interface:ConfigurationRepositoryRegisters the provided change listener so that it will be notified of any changes to the entry corrresponding to provided DN. No check will be made to determine whether the provided listener is already registered.- Specified by:
registerChangeListenerin interfaceConfigurationRepository- Parameters:
dn- The DN of the configuration entry.listener- The change listener that should be registered.
-
deregisterAddListener
public void deregisterAddListener(Dn dn, ConfigAddListener listener)
Description copied from interface:ConfigurationRepositoryDeregisters the provided add listener so that it will no longer be notified if any new entries are added immediately below the entry corresponding to the provided DN.- Specified by:
deregisterAddListenerin interfaceConfigurationRepository- Parameters:
dn- The DN of the configuration entry.listener- The add listener that should be deregistered.
-
deregisterDeleteListener
public void deregisterDeleteListener(Dn dn, ConfigDeleteListener listener)
Description copied from interface:ConfigurationRepositoryDeregisters the provided delete listener so that it will no longer be notified if any entries are deleted immediately below the entry corresponding to the provided DN.- Specified by:
deregisterDeleteListenerin interfaceConfigurationRepository- Parameters:
dn- The DN of the configuration entry.listener- The delete listener that should be deregistered.
-
deregisterChangeListener
public void deregisterChangeListener(Dn dn, ConfigChangeListener listener)
Description copied from interface:ConfigurationRepositoryAttempts to deregister the provided change listener with the provided DN.- Specified by:
deregisterChangeListenerin interfaceConfigurationRepository- Parameters:
dn- The DN of the configuration entry.listener- The change listener to deregister with this DN.
-
writeLDIF
public void writeLDIF(LDIFExportConfig exportConfig) throws LdapException
Writes the current configuration to LDIF with the provided export configuration.- Parameters:
exportConfig- The configuration to use for the export.- Throws:
LdapException- If a problem occurs while writing the LDIF.
-
writeSuccessfulStartupConfig
public void writeSuccessfulStartupConfig()
Generates a configuration file with the ".startok" suffix, representing a configuration file that has a successful start.This method must not be called if configuration can't be correctly initialized.
The actual generation is skipped if last known good configuration is used.
-
-