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 int
BINARY_GC_TX_TIMEOUT_SEC
protected BlobDispatcher
blobDispatcher
static String
BLOBS_CANDIDATE_FOR_DELETION_EVENT
Event fired to GC blobs candidates for deletion.static String
BLOBS_DELETED_DOMAIN_EVENT
Event fired to record blob deletion.protected static String
DOC_WITH_BLOB_KEYS_IN_QUERY
static String
MAIN_BLOB_XPATH
protected static String
XP
-
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 void
checkCanDeleteBlob(String repositoryName)
Checks that blobs can be safely deleted for the given repository.boolean
deleteBlob(String repositoryName, String key, boolean dryRun)
Deletes the blob associated to the given key.protected static void
denormalizeKeySuffix(Set<String> queryBlobKeys)
For any suffixed key in the given set, also add the unsuffixed key.protected void
findBlobs(Object value, List<String> split, List<ManagedBlob> blobs)
void
freezeVersion(Document doc)
Freezes the blobs' versions on a document version when it is created via a check in.protected void
freezeVersion(Document.BlobAccessor accessor, Document doc)
BinaryManagerStatus
garbageCollectBinaries(boolean delete)
Garbage collect the unused binaries.protected ManagedBlob
getBlob(Document doc, String xpath)
protected BlobDispatcher
getBlobDispatcher()
protected String
getBlobKeyReplacement(ManagedBlob blob)
A key may have been replaced by an async digest computation, use the new one.protected String
getBlobKeyReplacement(ManagedBlob blob, boolean addPrefix)
protected BlobProvider
getBlobProvider(String providerId)
protected BlobProvider
getBlobProvider(String key, String repositoryName)
InputStream
getConvertedStream(Blob blob, String mimeType, DocumentModel doc)
Gets anInputStream
for a conversion to the given MIME type.protected DocumentBlobProvider
getDocumentBlobProvider(Blob blob)
protected List<BinaryGarbageCollector>
getGarbageCollectors()
protected ManagedBlob
getMainBlob(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()
boolean
hasSharedStorage()
Compute if there are shared storage.boolean
isBinariesGarbageCollectionInProgress()
Checks if a garbage collection of the binaries in progress.boolean
isUseRepositoryName()
Are the blobs from a repository stored in a provider with the same name.void
notifyAfterCopy(Document doc)
Notifies the blob manager that the document has been copied.void
notifyBeforeRemove(Document doc)
Notifies the blob manager that the document is about to be removed.void
notifyChanges(Document doc, Set<String> xpaths)
Notifies the blob manager that a set of xpaths have changed on a document.void
notifyMakeRecord(Document doc)
Notifies the blob manager that the document was made a record.void
notifySetLegalHold(Document doc, boolean hold)
Notifies the blob manager that the document's legal hold status was changed.void
notifySetRetainUntil(Document doc, Calendar retainUntil)
Notifies the blob manager that the document's retention date was changed.Blob
readBlob(BlobInfo blobInfo, String repositoryName)
Deprecated.since 11.1, usereadBlob(BlobInfo, Document, String)
insteadBlob
readBlob(BlobInfo blobInfo, Document doc, String xpath)
Reads aBlob
from storage.protected Blob
readBlob(BlobInfo blobInfo, Document doc, String xpath, String repositoryName)
void
registerContribution(Object contribution, String extensionPoint, ComponentInstance contributor)
protected <R> R
runInTransaction(Supplier<R> supplier, int timeout)
Runs the givenSupplier
in a transaction with the giventimeout
.protected String
stripBlobKeyPrefix(String key)
void
unregisterContribution(Object contribution, String extensionPoint, ComponentInstance contributor)
protected void
updateBlob(ManagedBlob blob, Consumer<BlobUpdateContext> contextFiller)
void
updateBlob(Document doc, Consumer<BlobUpdateContext> contextFiller)
Update main blob of the doc.protected void
updateRetainedBlobs(Document doc, Consumer<BlobUpdateContext> contextFiller)
String
writeBlob(Blob blob, Document doc, String xpath)
Writes aBlob
to 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:
registerContribution
in classDefaultComponent
-
unregisterContribution
public void unregisterContribution(Object contribution, String extensionPoint, ComponentInstance contributor)
- Overrides:
unregisterContribution
in 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 aBlob
from 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:
readBlob
in 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 aBlob
from 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:
readBlob
in 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 aBlob
to storage and returns its key.The passed blob may be
null
, in which case anull
key 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:
writeBlob
in 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:DocumentBlobManager
Gets anInputStream
for 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:
getConvertedStream
in interfaceDocumentBlobManager
- Parameters:
blob
- the blobmimeType
- the MIME type to convert todoc
- the document that holds the blob- Returns:
- the stream, or
null
if 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:DocumentBlobManager
Freezes the blobs' versions on a document version when it is created via a check in.- Specified by:
freezeVersion
in interfaceDocumentBlobManager
- Parameters:
doc
- the new document version
-
notifyChanges
public void notifyChanges(Document doc, Set<String> xpaths)
Description copied from interface:DocumentBlobManager
Notifies the blob manager that a set of xpaths have changed on a document.- Specified by:
notifyChanges
in interfaceDocumentBlobManager
- Parameters:
doc
- the documentxpaths
- the set of changed xpaths
-
notifyMakeRecord
public void notifyMakeRecord(Document doc)
Description copied from interface:DocumentBlobManager
Notifies the blob manager that the document was made a record.- Specified by:
notifyMakeRecord
in interfaceDocumentBlobManager
- Parameters:
doc
- the document
-
notifyAfterCopy
public void notifyAfterCopy(Document doc)
Description copied from interface:DocumentBlobManager
Notifies the blob manager that the document has been copied.- Specified by:
notifyAfterCopy
in interfaceDocumentBlobManager
- Parameters:
doc
- the new document, the result of the copy
-
notifyBeforeRemove
public void notifyBeforeRemove(Document doc)
Description copied from interface:DocumentBlobManager
Notifies the blob manager that the document is about to be removed.- Specified by:
notifyBeforeRemove
in interfaceDocumentBlobManager
- Parameters:
doc
- the document
-
notifySetRetainUntil
public void notifySetRetainUntil(Document doc, Calendar retainUntil)
Description copied from interface:DocumentBlobManager
Notifies the blob manager that the document's retention date was changed.- Specified by:
notifySetRetainUntil
in interfaceDocumentBlobManager
- Parameters:
doc
- the document
-
notifySetLegalHold
public void notifySetLegalHold(Document doc, boolean hold)
Description copied from interface:DocumentBlobManager
Notifies the blob manager that the document's legal hold status was changed.- Specified by:
notifySetLegalHold
in 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:DocumentBlobManager
Checks 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:
checkCanDeleteBlob
in interfaceDocumentBlobManager
- Parameters:
repositoryName
- the repositoryName
-
deleteBlob
public boolean deleteBlob(String repositoryName, String key, boolean dryRun) throws IOException
Description copied from interface:DocumentBlobManager
Deletes 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_KEYS
capability (i.e. ecm:blobKeys populated).- Specified by:
deleteBlob
in 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:DocumentBlobManager
Compute if there are shared storage.- Specified by:
hasSharedStorage
in 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:DocumentBlobManager
Garbage collect the unused binaries.- Specified by:
garbageCollectBinaries
in interfaceDocumentBlobManager
- Parameters:
delete
- iffalse
don't actually delete the garbage collected binaries (but still return statistics about them), iftrue
delete them- Returns:
- a status about the number of garbage collected binaries
-
runInTransaction
protected <R> R runInTransaction(Supplier<R> supplier, int timeout)
Runs the givenSupplier
in a transaction with the giventimeout
.- Since:
- 11.1
-
isBinariesGarbageCollectionInProgress
public boolean isBinariesGarbageCollectionInProgress()
Description copied from interface:DocumentBlobManager
Checks if a garbage collection of the binaries in progress.- Specified by:
isBinariesGarbageCollectionInProgress
in interfaceDocumentBlobManager
- Returns:
true
if a garbage collection of the binaries is in progress
-
isUseRepositoryName
public boolean isUseRepositoryName()
Description copied from interface:DocumentBlobManager
Are the blobs from a repository stored in a provider with the same name.- Specified by:
isUseRepositoryName
in 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:DocumentBlobManager
Gets the list of the provider ids that are used by the given repository.- Specified by:
getProviderIds
in interfaceDocumentBlobManager
- Parameters:
repository
- the repository name- Returns:
- the list of provider ids where blob can be dispatched for the given repository
-
-