Package org.nuxeo.ecm.core.blob
Class DocumentBlobManagerComponent
- java.lang.Object
-
- org.nuxeo.runtime.model.DefaultComponent
-
- org.nuxeo.ecm.core.blob.DocumentBlobManagerComponent
-
- All Implemented Interfaces:
DocumentBlobManager,Adaptable,Component,Extensible,TimestampedService
public class DocumentBlobManagerComponent extends DefaultComponent implements DocumentBlobManager
- Since:
- 9.2
-
-
Field Summary
Fields Modifier and Type Field Description protected static intBINARY_GC_TX_TIMEOUT_SECprotected BlobDispatcherblobDispatcherstatic StringBLOBS_CANDIDATE_FOR_DELETION_EVENTEvent fired to GC blobs candidates for deletion.static StringBLOBS_DELETED_DOMAIN_EVENTEvent fired to record blob deletion.protected static StringDOC_WITH_BLOB_KEYS_IN_QUERYstatic StringMAIN_BLOB_XPATHprotected static StringXP-
Fields inherited from class org.nuxeo.runtime.model.DefaultComponent
lastModified, name
-
-
Constructor Summary
Constructors Constructor Description DocumentBlobManagerComponent()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidcheckCanDeleteBlob(String repositoryName)Checks that blobs can be safely deleted for the given repository.booleandeleteBlob(String repositoryName, String key, boolean dryRun)Deletes the blob associated to the given key.protected static voiddenormalizeKeySuffix(Set<String> queryBlobKeys)For any suffixed key in the given set, also add the unsuffixed key.protected voidfindBlobs(Object value, List<String> split, List<ManagedBlob> blobs)voidfreezeVersion(Document doc)Freezes the blobs' versions on a document version when it is created via a check in.protected voidfreezeVersion(Document.BlobAccessor accessor, Document doc)BinaryManagerStatusgarbageCollectBinaries(boolean delete)Garbage collect the unused binaries.protected ManagedBlobgetBlob(Document doc, String xpath)protected BlobDispatchergetBlobDispatcher()protected StringgetBlobKeyReplacement(ManagedBlob blob)A key may have been replaced by an async digest computation, use the new one.protected StringgetBlobKeyReplacement(ManagedBlob blob, boolean addPrefix)protected BlobProvidergetBlobProvider(String providerId)protected BlobProvidergetBlobProvider(String key, String repositoryName)InputStreamgetConvertedStream(Blob blob, String mimeType, DocumentModel doc)Gets anInputStreamfor a conversion to the given MIME type.protected DocumentBlobProvidergetDocumentBlobProvider(Blob blob)protected List<BinaryGarbageCollector>getGarbageCollectors()protected ManagedBlobgetMainBlob(Document doc)Collection<String>getProviderIds(String repository)Gets the list of the provider ids that are used by the given repository.List<ManagedBlob>getRetainableBlobs(Document doc)protected List<String>getSharedStorage()booleanhasSharedStorage()Compute if there are shared storage.booleanisBinariesGarbageCollectionInProgress()Checks if a garbage collection of the binaries in progress.booleanisUseRepositoryName()Are the blobs from a repository stored in a provider with the same name.voidnotifyAfterCopy(Document doc)Notifies the blob manager that the document has been copied.voidnotifyBeforeRemove(Document doc)Notifies the blob manager that the document is about to be removed.voidnotifyChanges(Document doc, Set<String> xpaths)Notifies the blob manager that a set of xpaths have changed on a document.voidnotifyMakeRecord(Document doc)Notifies the blob manager that the document was made a record.voidnotifySetLegalHold(Document doc, boolean hold)Notifies the blob manager that the document's legal hold status was changed.voidnotifySetRetainUntil(Document doc, Calendar retainUntil)Notifies the blob manager that the document's retention date was changed.BlobreadBlob(BlobInfo blobInfo, String repositoryName)Deprecated.since 11.1, usereadBlob(BlobInfo, Document, String)insteadBlobreadBlob(BlobInfo blobInfo, Document doc, String xpath)Reads aBlobfrom storage.protected BlobreadBlob(BlobInfo blobInfo, Document doc, String xpath, String repositoryName)voidregisterContribution(Object contribution, String extensionPoint, ComponentInstance contributor)protected <R> RrunInTransaction(Supplier<R> supplier, int timeout)Runs the givenSupplierin a transaction with the giventimeout.protected StringstripBlobKeyPrefix(String key)voidunregisterContribution(Object contribution, String extensionPoint, ComponentInstance contributor)protected voidupdateBlob(ManagedBlob blob, Consumer<BlobUpdateContext> contextFiller)voidupdateBlob(Document doc, Consumer<BlobUpdateContext> contextFiller)Update main blob of the doc.protected voidupdateRetainedBlobs(Document doc, Consumer<BlobUpdateContext> contextFiller)StringwriteBlob(Blob blob, Document doc, String xpath)Writes aBlobto storage and returns its key.-
Methods inherited from class org.nuxeo.runtime.model.DefaultComponent
activate, addRuntimeMessage, addRuntimeMessage, deactivate, getAdapter, getDescriptor, getDescriptors, getLastModified, getRegistry, register, registerExtension, setLastModified, setModifiedNow, setName, start, stop, unregister, unregisterExtension
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.nuxeo.runtime.model.Component
applicationStarted, getApplicationStartedOrder
-
-
-
-
Field Detail
-
XP
protected static final String XP
- See Also:
- Constant Field Values
-
BINARY_GC_TX_TIMEOUT_SEC
protected static final int BINARY_GC_TX_TIMEOUT_SEC
- See Also:
- Constant Field Values
-
BLOBS_CANDIDATE_FOR_DELETION_EVENT
public static final String BLOBS_CANDIDATE_FOR_DELETION_EVENT
Event fired to GC blobs candidates for deletion.- Since:
- 2023
- See Also:
- Constant Field Values
-
BLOBS_DELETED_DOMAIN_EVENT
public static final String BLOBS_DELETED_DOMAIN_EVENT
Event fired to record blob deletion.- Since:
- 2023
- See Also:
- Constant Field Values
-
DOC_WITH_BLOB_KEYS_IN_QUERY
protected static final String DOC_WITH_BLOB_KEYS_IN_QUERY
- See Also:
- Constant Field Values
-
MAIN_BLOB_XPATH
public static final String MAIN_BLOB_XPATH
- See Also:
- Constant Field Values
-
blobDispatcher
protected volatile BlobDispatcher blobDispatcher
-
-
Method Detail
-
registerContribution
public void registerContribution(Object contribution, String extensionPoint, ComponentInstance contributor)
- Overrides:
registerContributionin classDefaultComponent
-
unregisterContribution
public void unregisterContribution(Object contribution, String extensionPoint, ComponentInstance contributor)
- Overrides:
unregisterContributionin classDefaultComponent
-
getBlobDispatcher
protected BlobDispatcher getBlobDispatcher()
-
getBlobProvider
protected BlobProvider getBlobProvider(String providerId)
-
getDocumentBlobProvider
protected DocumentBlobProvider getDocumentBlobProvider(Blob blob)
-
readBlob
public Blob readBlob(BlobInfo blobInfo, Document doc, String xpath) throws IOException
Reads aBlobfrom storage.The
BlobInfo(coming from the database) contains the blob key, which may or may not be prefixed by a blob provider id.- Specified by:
readBlobin interfaceDocumentBlobManager- Parameters:
blobInfo- the blob informationdoc- the document to which this blob belongsxpath- the xpath of the blob in the document- Returns:
- a managed blob
- Throws:
IOException
-
readBlob
protected Blob readBlob(BlobInfo blobInfo, Document doc, String xpath, String repositoryName) throws IOException
- Throws:
IOException
-
readBlob
@Deprecated public Blob readBlob(BlobInfo blobInfo, String repositoryName) throws IOException
Deprecated.since 11.1, usereadBlob(BlobInfo, Document, String)insteadReads aBlobfrom storage.The
BlobInfo(coming from the database) contains the blob key, which may or may not be prefixed by a blob provider id.- Specified by:
readBlobin interfaceDocumentBlobManager- Parameters:
blobInfo- the blob informationrepositoryName- the repository to which this blob belongs- Returns:
- a managed blob
- Throws:
IOException
-
getBlobProvider
protected BlobProvider getBlobProvider(String key, String repositoryName)
-
writeBlob
public String writeBlob(Blob blob, Document doc, String xpath) throws IOException
Writes aBlobto storage and returns its key.The passed blob may be
null, in which case anullkey is returned after checking that deleting this blob is allowed.If the blob is managed and already uses the provider that's expected for this blob and document, there is no need to recompute a key. Otherwise, go through the blob provider.
- Specified by:
writeBlobin interfaceDocumentBlobManager- Parameters:
blob- the blobdoc- the document to which this blob belongsxpath- the xpath of blob in doc- Returns:
- the blob key
- Throws:
IOException
-
getBlobKeyReplacement
protected String getBlobKeyReplacement(ManagedBlob blob)
A key may have been replaced by an async digest computation, use the new one.
-
getBlobKeyReplacement
protected String getBlobKeyReplacement(ManagedBlob blob, boolean addPrefix)
-
getConvertedStream
public InputStream getConvertedStream(Blob blob, String mimeType, DocumentModel doc) throws IOException
Description copied from interface:DocumentBlobManagerGets anInputStreamfor a conversion to the given MIME type.Like all
InputStream, the result must be closed when done with it to avoid resource leaks.- Specified by:
getConvertedStreamin interfaceDocumentBlobManager- Parameters:
blob- the blobmimeType- the MIME type to convert todoc- the document that holds the blob- Returns:
- the stream, or
nullif no conversion is available for the given MIME type - Throws:
IOException
-
freezeVersion
protected void freezeVersion(Document.BlobAccessor accessor, Document doc)
-
freezeVersion
public void freezeVersion(Document doc)
Description copied from interface:DocumentBlobManagerFreezes the blobs' versions on a document version when it is created via a check in.- Specified by:
freezeVersionin interfaceDocumentBlobManager- Parameters:
doc- the new document version
-
notifyChanges
public void notifyChanges(Document doc, Set<String> xpaths)
Description copied from interface:DocumentBlobManagerNotifies the blob manager that a set of xpaths have changed on a document.- Specified by:
notifyChangesin interfaceDocumentBlobManager- Parameters:
doc- the documentxpaths- the set of changed xpaths
-
notifyMakeRecord
public void notifyMakeRecord(Document doc)
Description copied from interface:DocumentBlobManagerNotifies the blob manager that the document was made a record.- Specified by:
notifyMakeRecordin interfaceDocumentBlobManager- Parameters:
doc- the document
-
notifyAfterCopy
public void notifyAfterCopy(Document doc)
Description copied from interface:DocumentBlobManagerNotifies the blob manager that the document has been copied.- Specified by:
notifyAfterCopyin interfaceDocumentBlobManager- Parameters:
doc- the new document, the result of the copy
-
notifyBeforeRemove
public void notifyBeforeRemove(Document doc)
Description copied from interface:DocumentBlobManagerNotifies the blob manager that the document is about to be removed.- Specified by:
notifyBeforeRemovein interfaceDocumentBlobManager- Parameters:
doc- the document
-
notifySetRetainUntil
public void notifySetRetainUntil(Document doc, Calendar retainUntil)
Description copied from interface:DocumentBlobManagerNotifies the blob manager that the document's retention date was changed.- Specified by:
notifySetRetainUntilin interfaceDocumentBlobManager- Parameters:
doc- the document
-
notifySetLegalHold
public void notifySetLegalHold(Document doc, boolean hold)
Description copied from interface:DocumentBlobManagerNotifies the blob manager that the document's legal hold status was changed.- Specified by:
notifySetLegalHoldin interfaceDocumentBlobManager- Parameters:
doc- the document
-
getRetainableBlobs
public List<ManagedBlob> getRetainableBlobs(Document doc)
-
findBlobs
protected void findBlobs(Object value, List<String> split, List<ManagedBlob> blobs)
-
updateRetainedBlobs
protected void updateRetainedBlobs(Document doc, Consumer<BlobUpdateContext> contextFiller)
-
updateBlob
protected void updateBlob(ManagedBlob blob, Consumer<BlobUpdateContext> contextFiller)
- Since:
- 2023
-
updateBlob
public void updateBlob(Document doc, Consumer<BlobUpdateContext> contextFiller)
Update main blob of the doc.
-
getMainBlob
protected ManagedBlob getMainBlob(Document doc)
-
getBlob
protected ManagedBlob getBlob(Document doc, String xpath)
-
getGarbageCollectors
protected List<BinaryGarbageCollector> getGarbageCollectors()
-
checkCanDeleteBlob
public void checkCanDeleteBlob(String repositoryName)
Description copied from interface:DocumentBlobManagerChecks that blobs can be safely deleted for the given repository. If the call returns without throwing an Exception, blobs can be safely deleted callingDocumentBlobManager.deleteBlob(String, String, boolean).- Specified by:
checkCanDeleteBlobin interfaceDocumentBlobManager- Parameters:
repositoryName- the repositoryName
-
deleteBlob
public boolean deleteBlob(String repositoryName, String key, boolean dryRun) throws IOException
Description copied from interface:DocumentBlobManagerDeletes the blob associated to the given key. The method checks that the blob key is not referenced by any document of the given repository.The repositories must have the
Repository.CAPABILITY_QUERY_BLOB_KEYScapability (i.e. ecm:blobKeys populated).- Specified by:
deleteBlobin interfaceDocumentBlobManager- Parameters:
repositoryName- the repository where the blob key comes fromkey- the blob keydryRun- if false, effectively deletes the blob, dry run otherwise- Returns:
- true if the blob has been deleted, false if the blob is referenced and cannot be deleted
- Throws:
IOException- when reading/deleting the blob from the underlying blob provider
-
denormalizeKeySuffix
protected static void denormalizeKeySuffix(Set<String> queryBlobKeys)
For any suffixed key in the given set, also add the unsuffixed key.["key1@version1"] transformed into ["key1", "key1@version1"]
-
hasSharedStorage
public boolean hasSharedStorage()
Description copied from interface:DocumentBlobManagerCompute if there are shared storage.- Specified by:
hasSharedStoragein interfaceDocumentBlobManager- Returns:
- true if at least 2 providers points to the same store, false otherwise
-
garbageCollectBinaries
public BinaryManagerStatus garbageCollectBinaries(boolean delete)
Description copied from interface:DocumentBlobManagerGarbage collect the unused binaries.- Specified by:
garbageCollectBinariesin interfaceDocumentBlobManager- Parameters:
delete- iffalsedon't actually delete the garbage collected binaries (but still return statistics about them), iftruedelete them- Returns:
- a status about the number of garbage collected binaries
-
runInTransaction
protected <R> R runInTransaction(Supplier<R> supplier, int timeout)
Runs the givenSupplierin a transaction with the giventimeout.- Since:
- 11.1
-
isBinariesGarbageCollectionInProgress
public boolean isBinariesGarbageCollectionInProgress()
Description copied from interface:DocumentBlobManagerChecks if a garbage collection of the binaries in progress.- Specified by:
isBinariesGarbageCollectionInProgressin interfaceDocumentBlobManager- Returns:
trueif a garbage collection of the binaries is in progress
-
isUseRepositoryName
public boolean isUseRepositoryName()
Description copied from interface:DocumentBlobManagerAre the blobs from a repository stored in a provider with the same name.- Specified by:
isUseRepositoryNamein interfaceDocumentBlobManager- Returns:
- true if the blobs are dispatched to the provider with the same name than the repository
-
getProviderIds
public Collection<String> getProviderIds(String repository)
Description copied from interface:DocumentBlobManagerGets the list of the provider ids that are used by the given repository.- Specified by:
getProviderIdsin interfaceDocumentBlobManager- Parameters:
repository- the repository name- Returns:
- the list of provider ids where blob can be dispatched for the given repository
-
-