public class ConfigurationHandler extends Object implements ConfigurationRepository, AlertGenerator
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 and Description |
---|
ConfigurationHandler(ServerContext serverContext)
Creates a new instance.
|
Modifier and Type | Method and 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.
|
boolean |
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.
|
File |
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.
|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getClassName
public ConfigurationHandler(ServerContext serverContext)
serverContext
- The server context.public static ConfigurationHandler bootstrapConfiguration(ServerContext serverContext) throws InitializationException
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.
serverContext
- The server context.InitializationException
- If an error occurs during bootstrapping.public void reinitializeWithFullSchema(Schema schema) throws InitializationException
Previously registered listeners are preserved.
schema
- The server schema, fully initialized.InitializationException
- If an error occurs.public void finalize()
public Map<String,String> getAlerts()
AlertGenerator
getAlerts
in interface AlertGenerator
public Set<Dn> getChildren(Dn dn) throws ConfigException
ConfigurationRepository
getChildren
in interface ConfigurationRepository
dn
- DN of a configuration entry.ConfigException
- If a problem occurs during retrieval.public Dn getComponentEntryDN()
AlertGenerator
getComponentEntryDN
in interface AlertGenerator
public File getConfigurationFile()
public Entry getEntry(Dn dn)
ConfigurationRepository
getEntry
in interface ConfigurationRepository
dn
- DN of the configuration entrypublic Entry getRootEntry()
public List<ConfigAddListener> getAddListeners(Dn dn)
ConfigurationRepository
getAddListeners
in interface ConfigurationRepository
dn
- The DN of the configuration entry.public List<ConfigChangeListener> getChangeListeners(Dn dn)
ConfigurationRepository
getChangeListeners
in interface ConfigurationRepository
dn
- The DN of the configuration entry.public List<ConfigDeleteListener> getDeleteListeners(Dn dn)
ConfigurationRepository
getDeleteListeners
in interface ConfigurationRepository
dn
- The DN of the configuration entry.public boolean hasEntry(Dn dn)
ConfigurationRepository
hasEntry
in interface ConfigurationRepository
dn
- DN of the configuration entrytrue
if and only if there is a configuration entry with
this DNpublic void search(SearchOperation searchOperation)
searchOperation
- Defines the search to performpublic long numSubordinates(Dn entryDN, boolean subtree) throws ConfigException
entryDN
- The distinguished name of the entry.subtree
- true
to include all entries from the requested entry to the lowest level in the tree or
false
to only include the entries immediately below the requested entry.ConfigException
- If a problem occurs while trying to retrieve the entry.public void addEntry(Entry entry) throws LdapException
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.
entry
- The configuration entry to add.LdapException
- If an error occurs.public void deleteEntry(Dn dn) throws LdapException
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.
dn
- DN of entry to delete.LdapException
- If a problem occurs.public void replaceEntry(Entry oldEntry, Entry newEntry) throws LdapException
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.
oldEntry
- The original entry that is being replaced.newEntry
- The new entry to use in place of the existing entry with the same DN.LdapException
- If a problem occurs while trying to replace the entry.public void registerAddListener(Dn dn, ConfigAddListener listener)
ConfigurationRepository
registerAddListener
in interface ConfigurationRepository
dn
- The DN of the configuration entry.listener
- The add listener that should be registered.public void registerDeleteListener(Dn dn, ConfigDeleteListener listener)
ConfigurationRepository
registerDeleteListener
in interface ConfigurationRepository
dn
- The DN of the configuration entry.listener
- The delete listener that should be registered.public void registerChangeListener(Dn dn, ConfigChangeListener listener)
ConfigurationRepository
registerChangeListener
in interface ConfigurationRepository
dn
- The DN of the configuration entry.listener
- The change listener that should be registered.public void deregisterAddListener(Dn dn, ConfigAddListener listener)
ConfigurationRepository
deregisterAddListener
in interface ConfigurationRepository
dn
- The DN of the configuration entry.listener
- The add listener that should be deregistered.public void deregisterDeleteListener(Dn dn, ConfigDeleteListener listener)
ConfigurationRepository
deregisterDeleteListener
in interface ConfigurationRepository
dn
- The DN of the configuration entry.listener
- The delete listener that should be deregistered.public boolean deregisterChangeListener(Dn dn, ConfigChangeListener listener)
ConfigurationRepository
deregisterChangeListener
in interface ConfigurationRepository
dn
- The DN of the configuration entry.listener
- The change listener to deregister with this DN.true
if the specified listener was deregistered, or
false
if it was not.public void writeLDIF(LDIFExportConfig exportConfig) throws LdapException
exportConfig
- The configuration to use for the export.LdapException
- If a problem occurs while writing the LDIF.public void writeSuccessfulStartupConfig()
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.
Copyright 2010-2022 ForgeRock AS.