Search in sources :

Example 1 with BlobStore

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

the class BlobStoreFactory method execute.

BlobStore execute() {
    final BlobStore providerStore = provider.get();
    final ProviderConfig config = provider.config();
    final BlobStore builtStore = populateWithReadThroughIfApplicable(config, providerStore);
    if (!this.config.cache()) {
        return builtStore;
    }
    return CachedBlobStore.create().memoryCapacity(this.config.memoryCapacity()).sizeTreshold(this.config.cacheSizeThreshold()).blobStore(builtStore).build();
}
Also used : ProviderConfig(com.enonic.xp.blob.ProviderConfig) CachedBlobStore(com.enonic.xp.internal.blobstore.cache.CachedBlobStore) ReadThroughBlobStore(com.enonic.xp.internal.blobstore.readthrough.ReadThroughBlobStore) BlobStore(com.enonic.xp.blob.BlobStore)

Example 2 with BlobStore

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

the class BlobStoreActivator method doRegister.

private void doRegister() {
    final String name = config.providerName();
    LOG.info("Waiting for blobstore-provider [" + name + "]");
    final BlobStoreProvider blobStoreProvider = this.providers.get(name);
    if (blobStoreProvider == null) {
        return;
    }
    LOG.info("Found blobstore-provider [" + name + "]");
    if (blobStoreProvider.config().readThroughEnabled()) {
        final String readThroughProviderName = blobStoreProvider.config().readThroughProvider();
        if (this.providers.get(readThroughProviderName) == null) {
            LOG.info("Waiting for readThrough-provider [" + readThroughProviderName + "]");
            return;
        }
    }
    if (blobStoreProvider.get() != null) {
        final BlobStore blobStore = BlobStoreFactory.create().config(this.config).provider(blobStoreProvider).providers(this.providers).build().execute();
        this.blobStoreReg = this.context.registerService(BlobStore.class, blobStore, null);
        LOG.info("Registered blobstore [" + this.config.providerName() + "] successfully");
    }
}
Also used : BlobStoreProvider(com.enonic.xp.blob.BlobStoreProvider) BlobStore(com.enonic.xp.blob.BlobStore)

Example 3 with BlobStore

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

the class BlobStoreFactoryTest method doTestProviderStore.

private void doTestProviderStore(final boolean cache) {
    final MemoryBlobStore memory1 = new MemoryBlobStore();
    final MemoryBlobStoreProvider provider1 = new MemoryBlobStoreProvider("memory1", memory1, createProviderConfig("memory2", true));
    final MemoryBlobStore memory2 = new MemoryBlobStore();
    final MemoryBlobStoreProvider provider2 = new MemoryBlobStoreProvider("memory2", memory2, createProviderConfig(null, false));
    final BlobStoreProviders blobStoreProviders = new BlobStoreProviders();
    blobStoreProviders.add(provider2);
    final BlobStore finalBlobStore = BlobStoreFactory.create().provider(provider1).config(createBlobstoreConfig(cache)).providers(blobStoreProviders).build().execute();
    assertNotNull(finalBlobStore);
    final Segment segment = Segment.from("test", "blob");
    final BlobRecord record = finalBlobStore.addRecord(segment, ByteSource.wrap("hei".getBytes()));
    assertEquals(finalBlobStore.getRecord(segment, record.getKey()), memory1.getRecord(segment, record.getKey()));
    assertEquals(finalBlobStore.getRecord(segment, record.getKey()), memory2.getRecord(segment, record.getKey()));
}
Also used : BlobRecord(com.enonic.xp.blob.BlobRecord) BlobStore(com.enonic.xp.blob.BlobStore) Segment(com.enonic.xp.blob.Segment)

Example 4 with BlobStore

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

the class BlobStoreFactoryTest method no_cache_no_provider.

@Test
public void no_cache_no_provider() throws Exception {
    final MemoryBlobStore blobStore = new MemoryBlobStore();
    final MemoryBlobStoreProvider memoryBlobStoreProvider = new MemoryBlobStoreProvider("memory", blobStore, createProviderConfig("none", false));
    final BlobStore finalBlobStore = BlobStoreFactory.create().provider(memoryBlobStoreProvider).config(createBlobstoreConfig(false)).build().execute();
    assertNotNull(finalBlobStore);
    final Segment segment = Segment.from("test", "blob");
    final BlobRecord record = finalBlobStore.addRecord(segment, ByteSource.wrap("hei".getBytes()));
    assertEquals(finalBlobStore.getRecord(segment, record.getKey()), blobStore.getRecord(segment, record.getKey()));
}
Also used : BlobRecord(com.enonic.xp.blob.BlobRecord) BlobStore(com.enonic.xp.blob.BlobStore) Segment(com.enonic.xp.blob.Segment) Test(org.junit.jupiter.api.Test)

Aggregations

BlobStore (com.enonic.xp.blob.BlobStore)4 BlobRecord (com.enonic.xp.blob.BlobRecord)2 Segment (com.enonic.xp.blob.Segment)2 BlobStoreProvider (com.enonic.xp.blob.BlobStoreProvider)1 ProviderConfig (com.enonic.xp.blob.ProviderConfig)1 CachedBlobStore (com.enonic.xp.internal.blobstore.cache.CachedBlobStore)1 ReadThroughBlobStore (com.enonic.xp.internal.blobstore.readthrough.ReadThroughBlobStore)1 Test (org.junit.jupiter.api.Test)1