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
MemoryBackend
during 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 void
addEntry(Entry entry)
Add a configuration entry.static ConfigurationHandler
bootstrapConfiguration(ServerContext serverContext)
Bootstraps the server configuration.void
deleteEntry(Dn dn)
Delete a configuration entry.void
deregisterAddListener(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.void
deregisterChangeListener(Dn dn, ConfigChangeListener listener)
Attempts to deregister the provided change listener with the provided DN.void
deregisterDeleteListener(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.void
finalize()
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.Dn
getComponentEntryDN()
Retrieves the DN of the configuration entry with which this alert generator is associated.Path
getConfigurationFile()
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.Entry
getEntry(Dn dn)
Returns the configuration entry for the provided DN.Entry
getRootEntry()
Returns the configuration root entry.boolean
hasEntry(Dn dn)
Checks if the provided DN corresponds to a configuration entry.long
numSubordinates(Dn entryDN, boolean subtree)
Retrieves the number of subordinates for the requested entry.void
registerAddListener(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.void
registerChangeListener(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.void
registerDeleteListener(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.void
reinitializeWithFullSchema(Schema schema)
Re-initializes the configuration handler with a fully initialized schema.void
replaceEntry(Entry oldEntry, Entry newEntry)
Replaces the old configuration entry with the new configuration entry provided.void
search(SearchOperation searchOperation)
Search the configuration entries.void
writeLDIF(LDIFExportConfig exportConfig)
Writes the current configuration to LDIF with the provided export configuration.void
writeSuccessfulStartupConfig()
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:AlertGenerator
Retrieves 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:
getAlerts
in 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:ConfigurationRepository
Returns the set of DNs of children of the entry corresponding to the provided DN. .- Specified by:
getChildren
in 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:AlertGenerator
Retrieves the DN of the configuration entry with which this alert generator is associated.- Specified by:
getComponentEntryDN
in 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:ConfigurationRepository
Returns the configuration entry for the provided DN.- Specified by:
getEntry
in 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:ConfigurationRepository
Retrieves the add listeners that have been registered with the provided DN.- Specified by:
getAddListeners
in 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:ConfigurationRepository
Retrieves the change listeners that have been registered with the provided DN.- Specified by:
getChangeListeners
in 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:ConfigurationRepository
Retrieves the delete listeners that have been registered with the provided DN.- Specified by:
getDeleteListeners
in 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:ConfigurationRepository
Checks if the provided DN corresponds to a configuration entry.- Specified by:
hasEntry
in interfaceConfigurationRepository
- Parameters:
dn
- DN of the configuration entry- Returns:
true
if 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
-true
to include all entries from the requested entry to the lowest level in the tree orfalse
to 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:ConfigurationRepository
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.- Specified by:
registerAddListener
in 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:ConfigurationRepository
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.- Specified by:
registerDeleteListener
in 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:ConfigurationRepository
Registers 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:
registerChangeListener
in 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:ConfigurationRepository
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.- Specified by:
deregisterAddListener
in 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:ConfigurationRepository
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.- Specified by:
deregisterDeleteListener
in 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:ConfigurationRepository
Attempts to deregister the provided change listener with the provided DN.- Specified by:
deregisterChangeListener
in 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.
-
-