Package org.opends.server.api
Class LocalBackend<C extends Configuration>
- java.lang.Object
-
- org.opends.server.api.Backend<C>
-
- org.opends.server.api.LocalBackend<C>
-
- Type Parameters:
C- the type of the BackendCfg for the current backend
- All Implemented Interfaces:
RequestHandler,HealthStatusProvider
- Direct Known Subclasses:
BackendImpl,ChangelogBackend,ConfigurationBackend,LDIFBackend,MemoryBackend,MonitorBackend,NullBackend,RootDSEBackend,SchemaBackend,TaskBackend
@PublicAPI(stability=VOLATILE, mayExtend=true) public abstract class LocalBackend<C extends Configuration> extends Backend<C>
This class defines the set of methods and structures that must be implemented for a Directory Server backend.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLocalBackend.BackendOperationEnumeration of optional backend operations.
-
Constructor Summary
Constructors Constructor Description LocalBackend()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voidaddEntry(Entry entry, AddOperation addOperation)Adds the provided entry to this backend.voidcloseBackend()Performs any necessary work to finally close this backend, particularly closing any underlying databases or connections and deregistering any suffixes that it manages with the Directory Server.abstract voiddeleteEntry(Dn entryDN, DeleteOperation deleteOperation)Removes the specified entry from this backend.voidderegisterBackendMonitor()Deregisters the backend monitor of this backend.booleanentryExists(Dn entryDN)Indicates whether an entry with the specified DN exists in the backend.voidexportLDIF(LDIFExportConfig exportConfig)Exports the contents of this backend to LDIF.voidfinalizeBackend()Performs any necessary work to finalize this backend.Collection<ChangeRecord>getAndClearOfflineChanges()Returns any changes that have been applied to this backend while the server was offline.abstract EntrygetEntry(Dn entryDN)Retrieves the requested entry from this backend.abstract longgetEntryCount()Retrieves the total number of entries contained in this backend, if that information is available.protected LocalBackendMonitor<?>getLocalBackendMonitor()Returns the local backend monitor associated with this backend.abstract longgetNumberOfChildren(Dn parentDN)Retrieves the number of subordinates immediately below the requested entry.abstract longgetNumberOfEntriesInBaseDN(Dn baseDN)Retrieves the number of entries for the specified base DN including all entries from the requested entry to the lowest level in the tree.Queue<PersistentSearch>getPersistentSearches()Returns the persistent searches currently active against this local backend.WritabilityModegetWritabilityMode()Retrieves the writability mode for this backend.Flowable<Response>handle(org.forgerock.services.context.Context context, Request request)Processes the provided request in a reactive way within this backend.booleanhandlesEntry(Dn entryDN)Indicates whether this backend should be used to handle operations for the provided entry.static booleanhandlesEntry(Dn entryDN, Collection<Dn> baseDNs, Collection<Dn> excludeDNs)Indicates whether a backend should be used to handle operations for the provided entry given the set of base DNs and exclude DNs.abstract ConditionResulthasSubordinates(Dn entryDN)Indicates whether the requested entry has any subordinates.LDIFImportResultimportLDIF(LDIFImportConfig importConfig, ServerContext serverContext)Imports information from an LDIF file into this backend.booleanisIndexed(Filter filter)Indicates whether a subtree search using the provided filter would be indexed in this backend.abstract booleanisIndexed(AttributeType attributeType, MatchingRule matchingRule)Indicates whether extensible match search operations that target the specified attribute with the given matching rule should be considered indexed in this backend.abstract booleanisIndexed(AttributeType attributeType, IndexType indexType)Indicates whether search operations which target the specified attribute in the indicated manner would be considered indexed in this backend.abstract voidopenBackend()Opens this backend based on the information provided when the backend was configured.voidrebuildBackend(RebuildConfig rebuildConfig, ServerContext serverContext, BiConsumer<Long,Long> progressCallback)Rebuild indexes in the backend instance.voidregisterBackendMonitor()Registers a backend monitor for this backend.voidregisterPersistentSearch(PersistentSearch persistentSearch)Registers the provided persistent search operation with this backend so that it will be notified of any add, delete, modify, or modify DN operations that are performed.abstract voidrenameEntry(Dn currentDN, Entry entry, ModifyDnOperation modifyDNOperation)Moves and/or renames the provided entry in this backend, altering any subordinate entries as necessary.abstract voidreplaceEntry(Entry oldEntry, Entry newEntry, ModifyOperation modifyOperation)Replaces the specified entry with the provided entry in this backend.voidsampleEntries(Consumer<Entry> consumer, Dn baseDn)Consumes all or a subset of entries contained in this backend under the provided base DN.abstract voidsearch(SearchOperation searchOperation)Processes the specified search in this backend.voidsetWritabilityMode(WritabilityMode writabilityMode)Specifies the writability mode for this backend.booleansupports(LocalBackend.BackendOperation backendOperation)Indicates whether this backend supports the provided backend operation.booleansupportsControl(String controlOID)Indicates whether this backend supports the specified control.longverifyBackend(VerifyConfig verifyConfig)Verify the integrity of the backend instance.-
Methods inherited from class org.opends.server.api.Backend
configureBackend, getBackendID, getBaseDNs, getHealthStatus, getServerContext, getSupportedControls, getSupportedFeatures, isConfigurationAcceptable, isPublicBackend, setBackendID, toString
-
-
-
-
Method Detail
-
sampleEntries
public void sampleEntries(Consumer<Entry> consumer, Dn baseDn) throws LdapException
Consumes all or a subset of entries contained in this backend under the provided base DN. Intent is to consume a restricted set of entries (for backend having more than a small number of entries) which would allow to differentiate two instances of the same backend containing different entries, without having to compare every entries contained in the backend. The sample always contains the entry corresponding to the provided base DN. All other entries being consumed and the order at which they're consumed is not defined but it is guaranteed that a backend implementation will consume the exact same set of entries in the exact same order while the backend contains the exact same set of entries.- Parameters:
consumer- the consumer of entry to process the data samplebaseDn- the base DN of the domain- Throws:
LdapException- if an error occurs
-
handle
public Flowable<Response> handle(org.forgerock.services.context.Context context, Request request) throws Exception
Processes the provided request in a reactive way within this backend.- Parameters:
context- The context to process the request, which is expected to contain aRequestDJContextand aClientContextrequest- The request to process.- Returns:
- a stream of responses
- Throws:
Exception- If an error occurs
-
openBackend
public abstract void openBackend() throws ConfigException, InitializationExceptionOpens this backend based on the information provided when the backend was configured. It also should open any underlying storage and register all suffixes with the server.- Specified by:
openBackendin classBackend<C extends Configuration>- Throws:
ConfigException- If an unrecoverable problem arises while opening the backend.InitializationException- If a problem occurs during opening that is not related to the server configuration.- See Also:
Backend.configureBackend(C, org.opends.server.core.ServerContext)
-
finalizeBackend
public void finalizeBackend()
Description copied from class:BackendPerforms any necessary work to finalize this backend. The backend must be an opened backend, so do not use this method on backends where onlyconfigureBackend()has been called. 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:
finalizeBackendin classBackend<C extends Configuration>
-
closeBackend
public void closeBackend()
Performs any necessary work to finally close this backend, particularly closing any underlying databases or connections and deregistering any suffixes that it manages with the Directory Server.It will be called as final step of
finalizeBackend(), so subclasses might override it.
-
isIndexed
public abstract 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 returntruefor the specified attribute and index type.- Parameters:
attributeType- The attribute type for which to make the determination.indexType- The index type for which to make the determination.- Returns:
trueif search operations targeting the specified attribute in the indicated manner should be considered indexed, orfalseif not.
-
isIndexed
public abstract boolean isIndexed(AttributeType attributeType, MatchingRule matchingRule)
Indicates whether extensible match search operations that target the specified attribute with the given matching rule should be considered indexed in this backend.- Parameters:
attributeType- The attribute type for which to make the determination.matchingRule- The matching rule for which to make the determination.- Returns:
trueif extensible match search operations targeting the specified attribute with the given matching rule should be considered indexed, orfalseif not.
-
isIndexed
public boolean isIndexed(Filter filter)
Indicates whether a subtree search using the provided filter would be indexed in this backend. This default implementation uses a rough set of logic that makes a best-effort determination. Subclasses that provide a more complete indexing mechanism may wish to override this method and provide a more accurate result.- Parameters:
filter- The search filter for which to make the determination.- Returns:
trueif it is believed that the provided filter would be indexed in this backend, orfalseif not.
-
hasSubordinates
public abstract ConditionResult hasSubordinates(Dn entryDN) throws LdapException
Indicates whether the requested entry has any subordinates.- Parameters:
entryDN- The distinguished name of the entry.- Returns:
ConditionResult.TRUEif the entry has one or more subordinates orConditionResult.FALSEotherwise orConditionResult.UNDEFINEDif it can not be determined.- Throws:
LdapException- If a problem occurs while trying to retrieve the entry.
-
getNumberOfChildren
public abstract long getNumberOfChildren(Dn parentDN) throws LdapException
Retrieves the number of subordinates immediately below the requested entry.- Parameters:
parentDN- The distinguished name of the parent.- Returns:
- The number of subordinate entries for the requested entry.
- Throws:
LdapException- If baseDN isn't a base dn managed by this backend or if a problem occurs while trying to retrieve the entry.NullPointerException- if baseDN is null.
-
getNumberOfEntriesInBaseDN
public abstract long getNumberOfEntriesInBaseDN(Dn baseDN) throws LdapException
Retrieves the number of entries for the specified base DN including all entries from the requested entry to the lowest level in the tree.- Parameters:
baseDN- The base distinguished name.- Returns:
- The number of subordinate entries including the base dn.
- Throws:
LdapException- If baseDN isn't a base dn managed by this backend or if a problem occurs while trying to retrieve the entry.NullPointerException- if baseDN is null.
-
entryExists
public boolean entryExists(Dn entryDN) throws LdapException
Indicates whether an entry with the specified DN exists in the backend. The default implementation callsgetEntry, but backend implementations may override this with a more efficient version. The caller is not required to hold any locks on the specified DN.- Parameters:
entryDN- The DN of the entry for which to determine existence.- Returns:
trueif the specified entry exists in this backend, orfalseif it does not.- Throws:
LdapException- If a problem occurs while trying to make the determination.
-
getEntry
public abstract Entry getEntry(Dn entryDN) throws LdapException
Retrieves the requested entry from this backend. The caller is not required to hold any locks on the specified DN.- Parameters:
entryDN- The distinguished name of the entry to retrieve.- Returns:
- The requested entry, or
nullif the entry does not exist. - Throws:
LdapException- If a problem occurs while trying to retrieve the entry.
-
addEntry
public abstract void addEntry(Entry entry, AddOperation addOperation) throws LdapException, CancelledResultException
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.- Parameters:
entry- The entry to add to this backend.addOperation- The add operation with which the new entry is associated. This may benullfor adds performed internally.- Throws:
LdapException- If a problem occurs while trying to add the entry.CancelledResultException- If this backend noticed and reacted to a request to cancel or abandon the add operation.
-
deleteEntry
public abstract void deleteEntry(Dn entryDN, DeleteOperation deleteOperation) throws LdapException, CancelledResultException
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.- Parameters:
entryDN- The DN of the entry to remove from this backend.deleteOperation- The delete operation with which this action is associated. This may benullfor deletes performed internally.- Throws:
LdapException- If a problem occurs while trying to remove the entry.CancelledResultException- If this backend noticed and reacted to a request to cancel or abandon the delete operation.
-
replaceEntry
public abstract void replaceEntry(Entry oldEntry, Entry newEntry, ModifyOperation modifyOperation) throws LdapException, CancelledResultException
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.- 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.modifyOperation- The modify operation with which this action is associated.- Throws:
LdapException- If a problem occurs while trying to replace the entry.CancelledResultException- If this backend noticed and reacted to a request to cancel or abandon the modify operation.
-
renameEntry
public abstract void renameEntry(Dn currentDN, Entry entry, ModifyDnOperation modifyDNOperation) throws LdapException, CancelledResultException
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.- Parameters:
currentDN- The current DN of the entry to be moved/renamed.entry- The new content to use for the entry.modifyDNOperation- The modify DN operation with which this action is associated. This may benullfor modify DN operations performed internally.- Throws:
LdapException- If a problem occurs while trying to perform the rename.CancelledResultException- If this backend noticed and reacted to a request to cancel or abandon the modify DN operation.
-
search
public abstract void search(SearchOperation searchOperation) throws LdapException, CancelledResultException
Processes the specified search in this backend. Matching entries should be provided back to the core server using theSearchOperation.returnEntrymethod. The caller is not required to have any locks when calling this operation.- Parameters:
searchOperation- The search operation to be processed.- Throws:
LdapException- If a problem occurs while processing the search.CancelledResultException- If this backend noticed and reacted to a request to cancel or abandon the search operation.
-
supports
public boolean supports(LocalBackend.BackendOperation backendOperation)
Indicates whether this backend supports the provided backend operation.- Parameters:
backendOperation- the backend operation- Returns:
trueif this backend supports the provided backend operation,falseotherwise.
-
exportLDIF
public void exportLDIF(LDIFExportConfig exportConfig) throws LdapException
Exports the contents of this backend to LDIF. This method should only be called ifsupports(BackendOperation)withLocalBackend.BackendOperation.LDIF_EXPORTreturnstrue.Note that the server will not explicitly initialize this backend before calling this method.
- Parameters:
exportConfig- The configuration to use when performing the export.- Throws:
LdapException- If a problem occurs while performing the LDIF export.
-
importLDIF
public LDIFImportResult importLDIF(LDIFImportConfig importConfig, ServerContext serverContext) throws LdapException
Imports information from an LDIF file into this backend. This method should only be called ifsupports(BackendOperation)withLocalBackend.BackendOperation.LDIF_IMPORTreturnstrue.Note that the server will not explicitly initialize this backend before calling this method.
- Parameters:
importConfig- The configuration to use when performing the import.serverContext- The server context- Returns:
- Information about the result of the import processing.
- Throws:
LdapException- If a problem occurs while performing the LDIF import.
-
verifyBackend
public long verifyBackend(VerifyConfig verifyConfig) throws InitializationException, ConfigException, LdapException
Verify the integrity of the backend instance.- Parameters:
verifyConfig- The verify configuration.- Returns:
- The results of the operation.
- Throws:
ConfigException- If an unrecoverable problem arises during initialization.InitializationException- If a problem occurs during initialization that is not related to the server configuration.LdapException- If a Directory Server error occurs.
-
rebuildBackend
public void rebuildBackend(RebuildConfig rebuildConfig, ServerContext serverContext, BiConsumer<Long,Long> progressCallback) throws InitializationException, ConfigException, LdapException
Rebuild indexes in the backend instance. Note that the server will not explicitly initialize this backend before calling this method.- Parameters:
rebuildConfig- The rebuild configuration.serverContext- The server context for this instanceprogressCallback- Callback to be notified about progress made. First argument isdone, second one istotal. Rebuild is done whendone == total.- Throws:
ConfigException- If an unrecoverable problem arises during initialization.InitializationException- If a problem occurs during initialization that is not related to the server configuration.LdapException- If a Directory Server error occurs.
-
getWritabilityMode
public final WritabilityMode getWritabilityMode()
Retrieves the writability mode for this backend.- Returns:
- The writability mode for this backend.
-
setWritabilityMode
public final void setWritabilityMode(WritabilityMode writabilityMode)
Specifies the writability mode for this backend.- Parameters:
writabilityMode- The writability mode for this backend.
-
registerPersistentSearch
public void registerPersistentSearch(PersistentSearch persistentSearch) throws LdapException
Registers the provided persistent search operation with this backend so that it will be notified of any add, delete, modify, or modify DN operations that are performed.- Parameters:
persistentSearch- The persistent search operation to register with this backend- Throws:
LdapException- If a problem occurs while registering the persistent search
-
getPersistentSearches
public Queue<PersistentSearch> getPersistentSearches()
Returns the persistent searches currently active against this local backend.- Returns:
- the list of persistent searches currently active against this local backend
-
getEntryCount
public abstract long getEntryCount()
Retrieves the total number of entries contained in this backend, if that information is available.- Returns:
- The total number of entries contained in this backend, or -1 if that information is not available.
-
handlesEntry
public final boolean handlesEntry(Dn entryDN)
Indicates whether this backend should be used to handle operations for the provided entry.- Parameters:
entryDN- The DN of the entry for which to make the determination.- Returns:
trueif this backend handles operations for the provided entry, orfalseif it does not.
-
registerBackendMonitor
public void registerBackendMonitor()
Description copied from class:BackendRegisters a backend monitor for this backend.- Overrides:
registerBackendMonitorin classBackend<C extends Configuration>
-
getLocalBackendMonitor
protected LocalBackendMonitor<?> getLocalBackendMonitor()
Returns the local backend monitor associated with this backend.Implementations may override this method in order to provide custom implementations.
- Returns:
- The local backend monitor associated with this backend.
-
deregisterBackendMonitor
public void deregisterBackendMonitor()
Description copied from class:BackendDeregisters the backend monitor of this backend.- Overrides:
deregisterBackendMonitorin classBackend<C extends Configuration>
-
supportsControl
public final boolean supportsControl(String controlOID)
Indicates whether this backend supports the specified control.- Parameters:
controlOID- The OID of the control for which to make the determination.- Returns:
trueif this backends supports the control with the specified OID, orfalseif it does not.
-
handlesEntry
public static boolean handlesEntry(Dn entryDN, Collection<Dn> baseDNs, Collection<Dn> excludeDNs)
Indicates whether a backend should be used to handle operations for the provided entry given the set of base DNs and exclude DNs.- Parameters:
entryDN- The DN of the entry for which to make the determination.baseDNs- The set of base DNs for the backend.excludeDNs- The set of DNs that should be excluded from the backend.- Returns:
trueif the backend should handle operations for the provided entry, orfalseif it does not.
-
getAndClearOfflineChanges
public Collection<ChangeRecord> getAndClearOfflineChanges()
Returns any changes that have been applied to this backend while the server was offline. This method should only be called ifsupports(BackendOperation)withLocalBackend.BackendOperation.OFFLINE_CHANGESreturnstrue. This method is called on startup in order to synchronize the offline changes to the rest of the topology if the backend is replicated. On return, the backend should clear the offline changes.- Returns:
- A list of zero or more changes that were made while the server was offline.
-
-