Search in sources :

Example 1 with CachingBlobStore

use of com.enonic.xp.blob.CachingBlobStore in project xp by enonic.

the class NodeVersionServiceImpl method getFromBlob.

private NodeVersion getFromBlob(final NodeVersionKey nodeVersionKey, final InternalContext context) {
    final Segment nodeSegment = RepositorySegmentUtils.toSegment(context.getRepositoryId(), NodeConstants.NODE_SEGMENT_LEVEL);
    final BlobRecord nodeBlobRecord = blobStore.getRecord(nodeSegment, nodeVersionKey.getNodeBlobKey());
    if (nodeBlobRecord == null) {
        throw new IllegalArgumentException("Cannot get node blob with blobKey: " + nodeVersionKey.getNodeBlobKey() + ": blob is null");
    }
    final Segment indexConfigSegment = RepositorySegmentUtils.toSegment(context.getRepositoryId(), NodeConstants.INDEX_CONFIG_SEGMENT_LEVEL);
    final BlobRecord indexConfigBlobRecord = blobStore.getRecord(indexConfigSegment, nodeVersionKey.getIndexConfigBlobKey());
    if (indexConfigBlobRecord == null) {
        throw new IllegalArgumentException("Cannot get index config blob with blobKey: " + nodeVersionKey.getIndexConfigBlobKey() + ": blob is null");
    }
    final Segment accessControlSegment = RepositorySegmentUtils.toSegment(context.getRepositoryId(), NodeConstants.ACCESS_CONTROL_SEGMENT_LEVEL);
    final BlobRecord accessControlBlobRecord = blobStore.getRecord(accessControlSegment, nodeVersionKey.getAccessControlBlobKey());
    if (accessControlBlobRecord == null) {
        throw new IllegalArgumentException("Cannot get access control blob with blobKey: " + nodeVersionKey.getAccessControlBlobKey() + ": blob is null");
    }
    try {
        final byte[] nodeString = nodeBlobRecord.getBytes().read();
        final byte[] indexConfigString = indexConfigBlobRecord.getBytes().read();
        final byte[] accessControlString = accessControlBlobRecord.getBytes().read();
        return this.nodeVersionJsonSerializer.toNodeVersion(nodeString, indexConfigString, accessControlString);
    } catch (IOException e) {
        if (blobStore instanceof CachingBlobStore) {
            ((CachingBlobStore) blobStore).invalidate(indexConfigSegment, nodeBlobRecord.getKey());
            ((CachingBlobStore) blobStore).invalidate(indexConfigSegment, indexConfigBlobRecord.getKey());
            ((CachingBlobStore) blobStore).invalidate(indexConfigSegment, accessControlBlobRecord.getKey());
        }
        throw new RuntimeException("Failed to load blobs with keys: " + nodeBlobRecord.getKey() + ", " + indexConfigBlobRecord.getKey() + ", " + accessControlBlobRecord.getKey(), e);
    }
}
Also used : BlobRecord(com.enonic.xp.blob.BlobRecord) IOException(java.io.IOException) CachingBlobStore(com.enonic.xp.blob.CachingBlobStore) Segment(com.enonic.xp.blob.Segment)

Aggregations

BlobRecord (com.enonic.xp.blob.BlobRecord)1 CachingBlobStore (com.enonic.xp.blob.CachingBlobStore)1 Segment (com.enonic.xp.blob.Segment)1 IOException (java.io.IOException)1