Class 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 Detail

      • ConfigurationHandler

        public ConfigurationHandler​(ServerContext serverContext)
        Creates a new instance.
        Parameters:
        serverContext - The server context.
    • Method Detail

      • 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.
        Overrides:
        finalize in class Object
      • 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 interface AlertGenerator
        Returns:
        Information about the set of alerts that this generator may produce.
      • 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 interface AlertGenerator
        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
      • getRootEntry

        public Entry getRootEntry()
        Returns the configuration root entry.
        Returns:
        the root entry
      • 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 interface ConfigurationRepository
        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 or false 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 interface ConfigurationRepository
        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 interface ConfigurationRepository
        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 interface ConfigurationRepository
        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 interface ConfigurationRepository
        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 interface ConfigurationRepository
        Parameters:
        dn - The DN of the configuration entry.
        listener - The delete listener that should be deregistered.
      • 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.