Skip to content

Commit

Permalink
improve LowLevelCacheEntry externalID for ISPN and Composite stores
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed May 6, 2013
1 parent ce22135 commit 9cf9aa3
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 15 deletions.
Expand Up @@ -164,13 +164,16 @@ protected Set<LowLevelCacheEntry> getLowLevelCacheEntriesFromStore(final Composi
Iterator<Map.Entry<String,BinaryStore>> it = compositeStore.getNamedStoreIterator();

while(it.hasNext()) {
BinaryStore bs = it.next().getValue();
Map.Entry<String,BinaryStore> entry = it.next();

BinaryStore bs = entry.getValue();

if(bs.hasBinary(key)) {

final Set<LowLevelCacheEntry> binaryBlobs = getLowLevelCacheEntriesFromStore(bs, key);

for(LowLevelCacheEntry e : binaryBlobs) {
e.setExternalId(entry.getKey());
blobs.add(e);
}
}
Expand Down
Expand Up @@ -11,6 +11,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Field;
import java.net.URI;
import java.security.MessageDigest;
import java.util.Properties;
Expand All @@ -25,6 +26,7 @@
import org.modeshape.jcr.value.BinaryKey;
import org.modeshape.jcr.value.binary.BinaryStore;
import org.modeshape.jcr.value.binary.BinaryStoreException;
import org.modeshape.jcr.value.binary.FileSystemBinaryStore;
import org.modeshape.jcr.value.binary.infinispan.InfinispanBinaryStore;
import org.slf4j.Logger;

Expand All @@ -38,19 +40,23 @@ public class LowLevelCacheEntry {

private final CacheStore cacheStore;

private String externalId;

private final BinaryKey key;

public LowLevelCacheEntry(final BinaryStore store,
final CacheStore lowLevelStore, final BinaryKey key) {
this.store = store;
cacheStore = lowLevelStore;
this.key = key;
this.externalId = "";
}

public LowLevelCacheEntry(final BinaryStore store, final BinaryKey key) {
this.store = store;
cacheStore = null;
this.key = key;
this.externalId = "";
}

@Override
Expand Down Expand Up @@ -99,9 +105,11 @@ public String getExternalIdentifier() {

if (store instanceof InfinispanBinaryStore) {

final InfinispanBinaryStore ispnStore = (InfinispanBinaryStore)store;

final CacheStoreConfig config = cacheStore.getCacheStoreConfig();

String externalId = null;
String ispnExternalId = null;
if (config instanceof AbstractCacheStoreConfig) {
final Properties properties =
((AbstractCacheStoreConfig) config).getProperties();
Expand All @@ -111,20 +119,34 @@ public String getExternalIdentifier() {

}

if (externalId == null && config instanceof FileCacheStoreConfig) {
externalId = ((FileCacheStoreConfig) config).getLocation();
if (config instanceof FileCacheStoreConfig) {
ispnExternalId = ((FileCacheStoreConfig) config).getLocation();
}

if (externalId == null) {
externalId = config.toString();
if (ispnExternalId == null) {
ispnExternalId = config.toString();
}

return store.getClass().getName() + ":" +
cacheStore.getCacheStoreConfig().getCacheLoaderClassName() +
":" + externalId;

String blobCacheName = "";
try {
Field blobCacheNameField = ispnStore.getClass().getDeclaredField("blobCacheName");
blobCacheNameField.setAccessible(true);
blobCacheName = (String)blobCacheNameField.get(ispnStore);
} catch (IllegalAccessException e) {
logger.warn("Got exception doing some questionable reflection to get the blob cache name", e);
} catch (NoSuchFieldException e) {
logger.warn("Got exception doing some questionable reflection to get the blob cache name", e);
}


return getExternalId() + "/" + store.getClass().getName() + ":" + blobCacheName + ":" +
config.getCacheLoaderClassName() +
":" + ispnExternalId;
} else if ( store instanceof FileSystemBinaryStore) {
final FileSystemBinaryStore fsStore = (FileSystemBinaryStore)store;
return getExternalId() + "/" + store.getClass().getName() + ":" + ((FileSystemBinaryStore) store).getDirectory().toPath();
} else {
return store.toString();
return getExternalId() + "/" + store.toString();
}
}

Expand Down Expand Up @@ -173,4 +195,12 @@ public FixityResult checkFixity(final URI checksum, final long size,

return result;
}

public void setExternalId(String externalId) {
this.externalId = externalId;
}

public String getExternalId() {
return externalId;
}
}
Expand Up @@ -41,8 +41,8 @@ public void testGetExternalIdentifier() throws Exception {

final LowLevelCacheEntry cs =
new LowLevelCacheEntry(store, new BinaryKey("asd"));
assertEquals("org.modeshape.jcr.value.binary.TransientBinaryStore", cs
.getExternalIdentifier().split("@")[0]);
assertEquals("/org.modeshape.jcr.value.binary.TransientBinaryStore", cs
.getExternalIdentifier().split(":")[0]);
}

@Test
Expand Down Expand Up @@ -137,7 +137,7 @@ public void testGetExternalIdentifierWithInfinispan() throws Exception {
final LowLevelCacheEntry cs =
new LowLevelCacheEntry(store, ispn, new BinaryKey("asd"));
assertEquals(
"org.modeshape.jcr.value.binary.infinispan.InfinispanBinaryStore:org.infinispan.loaders.file.FileCacheStore:target/FedoraRepository/storage",
"/org.modeshape.jcr.value.binary.infinispan.InfinispanBinaryStore:FedoraRepository:org.infinispan.loaders.file.FileCacheStore:target/FedoraRepository/storage",
cs.getExternalIdentifier());
}

Expand Down
Expand Up @@ -132,7 +132,7 @@ public void testGetBinaryBlobs() throws RepositoryException {
testObj.setGetBinaryKey(mockKeyFunc);
testObj.setRepository(mockRepo);
final Set<LowLevelCacheEntry> actual = testObj.getLowLevelCacheEntries(mockNode);
assertEquals("foo", actual.iterator().next().getExternalIdentifier());
assertEquals("/foo", actual.iterator().next().getExternalIdentifier());
}

@Test
Expand Down

0 comments on commit 9cf9aa3

Please sign in to comment.