org.opends.server.replication.server
Class ReplicationBackend

java.lang.Object
  extended by org.opends.server.api.Backend
      extended by org.opends.server.replication.server.ReplicationBackend

public class ReplicationBackend
extends Backend

This class defines a backend that stores its information in an associated replication server object. This is primarily intended to take advantage of the backup/restore/ import/export of the backend API, and to provide an LDAP access to the replication server database.

Entries stored in this backend are held in the DB associated with the replication server.

Currently are only implemented the create and restore backup features.


Constructor Summary
ReplicationBackend()
          Creates a new backend with the provided information.
 
Method Summary
 void addEntry(Entry entry, AddOperation addOperation)
          Adds the provided entry to this backend.
 void configureBackend(Configuration config)
          Configure this backend based on the information in the provided configuration.
 void createBackup(BackupConfig backupConfig)
          Creates a backup of the contents of this backend in a form that may be restored at a later date if necessary.
 void deleteEntry(DN entryDN, DeleteOperation deleteOperation)
          Removes the specified entry from this backend.
 boolean entryExists(DN entryDN)
          Indicates whether an entry with the specified DN exists in the backend.
 void exportLDIF(LDIFExportConfig exportConfig)
          Exports the contents of this backend to LDIF.
 void finalizeBackend()
          Performs any necessary work to finalize this backend, including closing any underlying databases or connections and deregistering any suffixes that it manages with the Directory Server.
 DN[] getBaseDNs()
          Retrieves the set of base-level DNs that may be used within this backend.
 Entry getEntry(DN entryDN)
          Retrieves the requested entry from this backend.
 long getEntryCount()
          Retrieves the total number of entries contained in this backend, if that information is available.
 java.util.HashSet<java.lang.String> getSupportedControls()
          Retrieves the OIDs of the controls that may be supported by this backend.
 java.util.HashSet<java.lang.String> getSupportedFeatures()
          Retrieves the OIDs of the features that may be supported by this backend.
 ConditionResult hasSubordinates(DN entryDN)
          Indicates whether the requested entry has any subordinates.
 LDIFImportResult importLDIF(LDIFImportConfig importConfig)
          Imports information from an LDIF file into this backend.
 void initializeBackend()
          Initializes this backend based on the information provided when the backend was configured.
 boolean isIndexed(AttributeType attributeType, IndexType indexType)
          Indicates whether search operations which target the specified attribute in the indicated manner would be considered indexed in this backend.
 boolean isLocal()
          Indicates whether the data associated with this backend may be considered local (i.e., in a repository managed by the Directory Server) rather than remote (i.e., in an external repository accessed by the Directory Server but managed through some other means).
 long numSubordinates(DN entryDN, boolean subtree)
          Retrieves the number of subordinates for the requested entry.
 void preloadEntryCache()
          Attempts to pre-load all the entries stored within this backend into the entry cache.
 void removeBackup(BackupDirectory backupDirectory, java.lang.String backupID)
          Removes the specified backup if it is possible to do so.
 void renameEntry(DN currentDN, Entry entry, ModifyDNOperation modifyDNOperation)
          Moves and/or renames the provided entry in this backend, altering any subordinate entries as necessary.
 void replaceEntry(Entry entry, ModifyOperation modifyOperation)
          Replaces the specified entry with the provided entry in this backend.
 void restoreBackup(RestoreConfig restoreConfig)
          Restores a backup of the contents of this backend.
 void search(SearchOperation searchOperation)
          Processes the specified search in this backend.
 void setBaseDNs(DN[] baseDNs)
          Set the base DNs for this backend.
 void setServer(ReplicationServer server)
          Set the replication server associated with this backend.
 boolean supportsBackup()
          Indicates whether this backend provides a backup mechanism of any kind.
 boolean supportsBackup(BackupConfig backupConfig, java.lang.StringBuilder unsupportedReason)
          Indicates whether this backend provides a mechanism to perform a backup of its contents in a form that can be restored later, based on the provided configuration.
 boolean supportsLDIFExport()
          Indicates whether this backend provides a mechanism to export the data it contains to an LDIF file.
 boolean supportsLDIFImport()
          Indicates whether this backend provides a mechanism to import its data from an LDIF file.
 boolean supportsRestore()
          Indicates whether this backend provides a mechanism to restore a backup.
 
Methods inherited from class org.opends.server.api.Backend
addSubordinateBackend, getBackendID, getBackendMonitor, getParentBackend, getSubordinateBackends, getWritabilityMode, handlesEntry, handlesEntry, hasSubSuffix, isConfigurationAcceptable, isIndexed, isIndexed, isPrivateBackend, removeSubordinateBackend, removeSubSuffix, setBackendID, setBackendMonitor, setParentBackend, setPrivateBackend, setSubordinateBackends, setWritabilityMode, supportsControl, supportsFeature
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReplicationBackend

public ReplicationBackend()
Creates a new backend with the provided information. All backend implementations must implement a default constructor that use super() to invoke this constructor.

Method Detail

setBaseDNs

public void setBaseDNs(DN[] baseDNs)
Set the base DNs for this backend. This is used by the unit tests to set the base DNs without having to provide a configuration object when initializing the backend.

Parameters:
baseDNs - The set of base DNs to be served by this memory backend.

configureBackend

public void configureBackend(Configuration config)
                      throws ConfigException
Configure this backend based on the information in the provided configuration.

Specified by:
configureBackend in class Backend
Parameters:
config - The configuration of this backend.
Throws:
ConfigException - If there is an error in the configuration.

initializeBackend

public void initializeBackend()
                       throws ConfigException,
                              InitializationException
Initializes this backend based on the information provided when the backend was configured.

Specified by:
initializeBackend in class Backend
Throws:
ConfigException - If an unrecoverable problem arises in the process of performing the initialization.
InitializationException - If a problem occurs during initialization that is not related to the server configuration.
See Also:
Backend.configureBackend(org.opends.server.admin.Configuration)

finalizeBackend

public void finalizeBackend()
Performs any necessary work to finalize this backend, including closing any underlying databases or connections and deregistering any suffixes that it manages with the Directory Server. This may be called during the Directory Server shutdown process or if a backend is disabled with the server online. It must not return until the backend is closed.

This method may not throw any exceptions. If any problems are encountered, then they may be logged but the closure should progress as completely as possible.

Specified by:
finalizeBackend in class Backend

getBaseDNs

public DN[] getBaseDNs()
Retrieves the set of base-level DNs that may be used within this backend.

Specified by:
getBaseDNs in class Backend
Returns:
The set of base-level DNs that may be used within this backend.

getEntryCount

public long getEntryCount()
Retrieves the total number of entries contained in this backend, if that information is available.

Specified by:
getEntryCount in class Backend
Returns:
The total number of entries contained in this backend, or -1 if that information is not available.

isLocal

public boolean isLocal()
Indicates whether the data associated with this backend may be considered local (i.e., in a repository managed by the Directory Server) rather than remote (i.e., in an external repository accessed by the Directory Server but managed through some other means).

Specified by:
isLocal in class Backend
Returns:
true if the data associated with this backend may be considered local, or false if it is remote.

isIndexed

public boolean isIndexed(AttributeType attributeType,
                         IndexType indexType)
Indicates whether search operations which target the specified attribute in the indicated manner would be considered indexed in this backend. The operation should be considered indexed only if the specified operation can be completed efficiently within the backend.

Note that this method should return a general result that covers all values of the specified attribute. If a the specified attribute is indexed in the indicated manner but some particular values may still be treated as unindexed (e.g., if the number of entries with that attribute value exceeds some threshold), then this method should still return true for the specified attribute and index type.

Specified by:
isIndexed in class Backend
Parameters:
attributeType - The attribute type for which to make the determination.
indexType - The index type for which to make the determination.
Returns:
true if search operations targeting the specified attribute in the indicated manner should be considered indexed, or false if not.

getEntry

public Entry getEntry(DN entryDN)
Retrieves the requested entry from this backend. Note that the caller must hold a read or write lock on the specified DN.

Specified by:
getEntry in class Backend
Parameters:
entryDN - The distinguished name of the entry to retrieve.
Returns:
The requested entry, or null if the entry does not exist.

entryExists

public boolean entryExists(DN entryDN)
Indicates whether an entry with the specified DN exists in the backend. The default implementation obtains a read lock and calls getEntry, but backend implementations may override this with a more efficient version that does not require a lock. The caller is not required to hold any locks on the specified DN.

Overrides:
entryExists in class Backend
Parameters:
entryDN - The DN of the entry for which to determine existence.
Returns:
true if the specified entry exists in this backend, or false if it does not.

addEntry

public void addEntry(Entry entry,
                     AddOperation addOperation)
              throws DirectoryException
Adds the provided entry to this backend. This method must ensure that the entry is appropriate for the backend and that no entry already exists with the same DN. The caller must hold a write lock on the DN of the provided entry.

Specified by:
addEntry in class Backend
Parameters:
entry - The entry to add to this backend.
addOperation - The add operation with which the new entry is associated. This may be null for adds performed internally.
Throws:
DirectoryException - If a problem occurs while trying to add the entry.

deleteEntry

public void deleteEntry(DN entryDN,
                        DeleteOperation deleteOperation)
                 throws DirectoryException
Removes the specified entry from this backend. This method must ensure that the entry exists and that it does not have any subordinate entries (unless the backend supports a subtree delete operation and the client included the appropriate information in the request). The caller must hold a write lock on the provided entry DN.

Specified by:
deleteEntry in class Backend
Parameters:
entryDN - The DN of the entry to remove from this backend.
deleteOperation - The delete operation with which this action is associated. This may be null for deletes performed internally.
Throws:
DirectoryException - If a problem occurs while trying to remove the entry.

replaceEntry

public void replaceEntry(Entry entry,
                         ModifyOperation modifyOperation)
                  throws DirectoryException
Replaces the specified entry with the provided entry in this backend. The backend must ensure that an entry already exists with the same DN as the provided entry. The caller must hold a write lock on the DN of the provided entry.

Specified by:
replaceEntry in class Backend
Parameters:
entry - The new entry to use in place of the existing entry with the same DN.
modifyOperation - The modify operation with which this action is associated. This may be null for modifications performed internally.
Throws:
DirectoryException - If a problem occurs while trying to replace the entry.

renameEntry

public void renameEntry(DN currentDN,
                        Entry entry,
                        ModifyDNOperation modifyDNOperation)
                 throws DirectoryException
Moves and/or renames the provided entry in this backend, altering any subordinate entries as necessary. This must ensure that an entry already exists with the provided current DN, and that no entry exists with the target DN of the provided entry. The caller must hold write locks on both the current DN and the new DN for the entry.

Specified by:
renameEntry in class Backend
Parameters:
currentDN - The current DN of the entry to be replaced.
entry - The new content to use for the entry.
modifyDNOperation - The modify DN operation with which this action is associated. This may be null for modify DN operations performed internally.
Throws:
DirectoryException - If a problem occurs while trying to perform the rename.

getSupportedControls

public java.util.HashSet<java.lang.String> getSupportedControls()
Retrieves the OIDs of the controls that may be supported by this backend.

Specified by:
getSupportedControls in class Backend
Returns:
The OIDs of the controls that may be supported by this backend.

getSupportedFeatures

public java.util.HashSet<java.lang.String> getSupportedFeatures()
Retrieves the OIDs of the features that may be supported by this backend.

Specified by:
getSupportedFeatures in class Backend
Returns:
The OIDs of the features that may be supported by this backend.

supportsLDIFExport

public boolean supportsLDIFExport()
Indicates whether this backend provides a mechanism to export the data it contains to an LDIF file.

Specified by:
supportsLDIFExport in class Backend
Returns:
true if this backend provides an LDIF export mechanism, or false if not.

exportLDIF

public void exportLDIF(LDIFExportConfig exportConfig)
                throws DirectoryException
Exports the contents of this backend to LDIF. This method should only be called if supportsLDIFExport returns true. Note that the server will not explicitly initialize this backend before calling this method.

Specified by:
exportLDIF in class Backend
Parameters:
exportConfig - The configuration to use when performing the export.
Throws:
DirectoryException - If a problem occurs while performing the LDIF export.

supportsLDIFImport

public boolean supportsLDIFImport()
Indicates whether this backend provides a mechanism to import its data from an LDIF file.

Specified by:
supportsLDIFImport in class Backend
Returns:
true if this backend provides an LDIF import mechanism, or false if not.

importLDIF

public LDIFImportResult importLDIF(LDIFImportConfig importConfig)
                            throws DirectoryException
Imports information from an LDIF file into this backend. This method should only be called if supportsLDIFImport returns true. Note that the server will not explicitly initialize this backend before calling this method.

Specified by:
importLDIF in class Backend
Parameters:
importConfig - The configuration to use when performing the import.
Returns:
Information about the result of the import processing.
Throws:
DirectoryException - If a problem occurs while performing the LDIF import.

supportsBackup

public boolean supportsBackup()
Indicates whether this backend provides a backup mechanism of any kind. This method is used by the backup process when backing up all backends to determine whether this backend is one that should be skipped. It should only return true for backends that it is not possible to archive directly (e.g., those that don't store their data locally, but rather pass through requests to some other repository).

Specified by:
supportsBackup in class Backend
Returns:
true if this backend provides any kind of backup mechanism, or false if it does not.

supportsBackup

public boolean supportsBackup(BackupConfig backupConfig,
                              java.lang.StringBuilder unsupportedReason)
Indicates whether this backend provides a mechanism to perform a backup of its contents in a form that can be restored later, based on the provided configuration.

Specified by:
supportsBackup in class Backend
Parameters:
backupConfig - The configuration of the backup for which to make the determination.
unsupportedReason - A buffer to which a message can be appended explaining why the requested backup is not supported.
Returns:
true if this backend provides a mechanism for performing backups with the provided configuration, or false if not.

createBackup

public void createBackup(BackupConfig backupConfig)
                  throws DirectoryException
Creates a backup of the contents of this backend in a form that may be restored at a later date if necessary. This method should only be called if supportsBackup returns true. Note that the server will not explicitly initialize this backend before calling this method.

Specified by:
createBackup in class Backend
Parameters:
backupConfig - The configuration to use when performing the backup.
Throws:
DirectoryException - If a problem occurs while performing the backup.

removeBackup

public void removeBackup(BackupDirectory backupDirectory,
                         java.lang.String backupID)
                  throws DirectoryException
Removes the specified backup if it is possible to do so.

Specified by:
removeBackup in class Backend
Parameters:
backupDirectory - The backup directory structure with which the specified backup is associated.
backupID - The backup ID for the backup to be removed.
Throws:
DirectoryException - If it is not possible to remove the specified backup for some reason (e.g., no such backup exists or there are other backups that are dependent upon it).

supportsRestore

public boolean supportsRestore()
Indicates whether this backend provides a mechanism to restore a backup.

Specified by:
supportsRestore in class Backend
Returns:
true if this backend provides a mechanism for restoring backups, or false if not.

restoreBackup

public void restoreBackup(RestoreConfig restoreConfig)
                   throws DirectoryException
Restores a backup of the contents of this backend. This method should only be called if supportsRestore returns true. Note that the server will not explicitly initialize this backend before calling this method.

Specified by:
restoreBackup in class Backend
Parameters:
restoreConfig - The configuration to use when performing the restore.
Throws:
DirectoryException - If a problem occurs while performing the restore.

numSubordinates

public long numSubordinates(DN entryDN,
                            boolean subtree)
                     throws DirectoryException
Retrieves the number of subordinates for the requested entry.

Specified by:
numSubordinates in class Backend
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 for the requested entry or -1 if it can not be determined.
Throws:
DirectoryException - If a problem occurs while trying to retrieve the entry.

hasSubordinates

public ConditionResult hasSubordinates(DN entryDN)
                                throws DirectoryException
Indicates whether the requested entry has any subordinates.

Specified by:
hasSubordinates in class Backend
Parameters:
entryDN - The distinguished name of the entry.
Returns:
ConditionResult.TRUE if the entry has one or more subordinates or ConditionResult.FALSE otherwise or ConditionResult.UNDEFINED if it can not be determined.
Throws:
DirectoryException - If a problem occurs while trying to retrieve the entry.

setServer

public void setServer(ReplicationServer server)
Set the replication server associated with this backend.

Parameters:
server - The replication server.

search

public void search(SearchOperation searchOperation)
            throws DirectoryException
Processes the specified search in this backend. Matching entries should be provided back to the core server using the SearchOperation.returnEntry method. The caller is not required to have any locks when calling this operation.

Specified by:
search in class Backend
Parameters:
searchOperation - The search operation to be processed.
Throws:
DirectoryException - If a problem occurs while processing the search.

preloadEntryCache

public void preloadEntryCache()
                       throws java.lang.UnsupportedOperationException
Attempts to pre-load all the entries stored within this backend into the entry cache. Note that the caller must ensure that the backend stays in read-only state until this method returns as no entry locking is performed during this operation. Also note that any backend implementing this method should implement pre- load progress reporting and error handling specific to its own implementation.

Specified by:
preloadEntryCache in class Backend
Throws:
java.lang.UnsupportedOperationException - if backend does not support this operation.