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();
}
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");
}
}
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()));
}
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()));
}
Aggregations