You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ss...@apache.org on 2014/03/05 13:24:16 UTC
[01/21] started working on cleaner cache API for KiWi
Repository: marmotta
Updated Branches:
refs/heads/MARMOTTA-450 [created] 766bef0a7
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/externalizer/ExternalizerTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/externalizer/ExternalizerTest.java b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/externalizer/ExternalizerTest.java
deleted file mode 100644
index 9e57267..0000000
--- a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/externalizer/ExternalizerTest.java
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.kiwi.test.externalizer;
-
-import org.apache.commons.lang3.RandomStringUtils;
-import org.apache.marmotta.kiwi.caching.*;
-import org.apache.marmotta.kiwi.model.rdf.KiWiAnonResource;
-import org.apache.marmotta.kiwi.model.rdf.KiWiIntLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiStringLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
-import org.apache.marmotta.kiwi.test.TestValueFactory;
-import org.infinispan.commons.marshall.AdvancedExternalizer;
-import org.infinispan.commons.marshall.StreamingMarshaller;
-import org.infinispan.configuration.cache.CacheMode;
-import org.infinispan.configuration.cache.Configuration;
-import org.infinispan.configuration.cache.ConfigurationBuilder;
-import org.infinispan.configuration.global.GlobalConfiguration;
-import org.infinispan.configuration.global.GlobalConfigurationBuilder;
-import org.infinispan.manager.DefaultCacheManager;
-import org.infinispan.manager.EmbeddedCacheManager;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.openrdf.model.Value;
-import org.openrdf.model.ValueFactory;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.*;
-import java.util.Random;
-
-/**
- * Test the different externalizer implementations we provide for Infinispan
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class ExternalizerTest {
-
- private static ValueFactory valueFactory = new TestValueFactory();
-
- private static Random rnd = new Random();
-
- private static Logger log = LoggerFactory.getLogger(ExternalizerTest.class);
-
- private static StreamingMarshaller marshaller;
-
-
- @BeforeClass
- public static void setup() {
- AdvancedExternalizer[] externalizers = new AdvancedExternalizer[] {
- new UriExternalizer(),
- new BNodeExternalizer(),
- new StringLiteralExternalizer(),
- new DateLiteralExternalizer(),
- new BooleanLiteralExternalizer(),
- new IntLiteralExternalizer(),
- new DoubleLiteralExternalizer()
- };
-
-
- GlobalConfiguration globalConfiguration = new GlobalConfigurationBuilder()
- .transport()
- .defaultTransport()
- .serialization()
- .addAdvancedExternalizer(externalizers)
- .build();
-
- Configuration defaultConfiguration = new ConfigurationBuilder()
- .clustering()
- .cacheMode(CacheMode.DIST_ASYNC)
- .build();
-
- EmbeddedCacheManager cacheManager = new DefaultCacheManager(globalConfiguration, defaultConfiguration, true);
-
- marshaller = cacheManager.getCache().getAdvancedCache().getComponentRegistry().getCacheMarshaller();
-
- }
-
-
- @Test
- public void testUriResource() throws Exception {
- marshall((KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8)), new UriExternalizer());
- }
-
- @Test
- public void testBNode() throws Exception {
- marshall((KiWiAnonResource) valueFactory.createBNode(), new BNodeExternalizer());
- }
-
- @Test
- public void testStringLiteral() throws Exception {
- marshall((KiWiStringLiteral) valueFactory.createLiteral(RandomStringUtils.randomAscii(40)), new StringLiteralExternalizer());
- }
-
- @Test
- public void testLangLiteral() throws Exception {
- marshall((KiWiStringLiteral) valueFactory.createLiteral(RandomStringUtils.randomAscii(40),"en"), new StringLiteralExternalizer());
- }
-
- @Test
- public void testTypeLiteral() throws Exception {
- marshall((KiWiStringLiteral) valueFactory.createLiteral(RandomStringUtils.randomAscii(40),valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8))), new StringLiteralExternalizer());
- }
-
-
- @Test
- public void testIntLiteral() throws Exception {
- marshall((KiWiIntLiteral) valueFactory.createLiteral(rnd.nextInt()), new IntLiteralExternalizer());
- }
-
-
- /**
- * Run the given object through the marshaller using an in-memory stream.
- * @param origin
- * @param <T>
- * @return
- */
- private <T> void marshall(T origin, AdvancedExternalizer<T> externalizer) throws IOException, ClassNotFoundException, InterruptedException {
- log.info("- testing externalizer directly ...");
- ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
- ObjectOutputStream out = new ObjectOutputStream(outBytes);
-
- externalizer.writeObject(out, origin);
- out.close();
-
- log.info(" object {}: serialized with {} bytes", origin, outBytes.size());
-
- ByteArrayInputStream inBytes = new ByteArrayInputStream(outBytes.toByteArray());
- ObjectInputStream in = new ObjectInputStream(inBytes);
-
- T destination1 = externalizer.readObject(in);
-
- Assert.assertEquals(origin,destination1);
-
- log.info("- testing externalizer with infinispan marshaller ...");
-
- byte[] bytes = marshaller.objectToByteBuffer(origin);
- log.info(" object {}: serialized with {} bytes", origin, bytes.length);
-
- Object destination2 = marshaller.objectFromByteBuffer(bytes);
-
- Assert.assertEquals(origin, destination2);
-
- }
-
-
- /**
- * Return a random RDF value, either a reused object (10% chance) or of any other kind.
- * @return
- */
- protected Value randomNode() {
- Value object;
- switch(rnd.nextInt(6)) {
- case 0: object = valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
- break;
- case 1: object = valueFactory.createBNode();
- break;
- case 2: object = valueFactory.createLiteral(RandomStringUtils.randomAscii(40));
- break;
- case 3: object = valueFactory.createLiteral(rnd.nextInt());
- break;
- case 4: object = valueFactory.createLiteral(rnd.nextDouble());
- break;
- case 5: object = valueFactory.createLiteral(rnd.nextBoolean());
- break;
- default: object = valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
- break;
-
- }
- return object;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/pom.xml
----------------------------------------------------------------------
diff --git a/libraries/kiwi/pom.xml b/libraries/kiwi/pom.xml
index 9e7aa42..c244567 100644
--- a/libraries/kiwi/pom.xml
+++ b/libraries/kiwi/pom.xml
@@ -111,6 +111,8 @@
<modules>
<module>kiwi-triplestore</module>
+ <module>kiwi-caching-infinispan</module>
+ <module>kiwi-caching-hazelcast</module>
<module>kiwi-versioning</module>
<module>kiwi-reasoner</module>
<module>kiwi-sparql</module>
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 4c03406..f2c11d6 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -1049,6 +1049,14 @@
<version>6.0.1.Final</version>
</dependency>
+
+ <dependency>
+ <groupId>com.hazelcast</groupId>
+ <artifactId>hazelcast</artifactId>
+ <version>3.1.6</version>
+ </dependency>
+
+
<!-- use stable versions for some dependencies -->
<dependency>
<groupId>org.jboss.spec.javax.annotation</groupId>
[13/21] git commit: cleanups and simplifications
Posted by ss...@apache.org.
cleanups and simplifications
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/89763d1c
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/89763d1c
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/89763d1c
Branch: refs/heads/MARMOTTA-450
Commit: 89763d1c0c626aad9a8d8d19b99d10f0a8e466fc
Parents: 2f22f5c
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Tue Mar 4 17:46:34 2014 +0100
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Tue Mar 4 17:46:34 2014 +0100
----------------------------------------------------------------------
.../caching/HazelcastCacheManager.java | 9 --
.../InfinispanEmbeddedCacheManager.java | 52 ++++------
.../remote/InfinispanRemoteCacheManager.java | 15 +++
.../marmotta/kiwi/infinispan/util/AsyncMap.java | 102 +++++++++++++++++++
.../marmotta/kiwi/test/EmbeddedClusterTest.java | 37 +++++++
.../kiwi/test/InfinispanClusterTest.java | 37 -------
.../marmotta/kiwi/caching/CacheManager.java | 10 ++
.../marmotta/kiwi/config/KiWiConfiguration.java | 29 ++++--
8 files changed, 206 insertions(+), 85 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/89763d1c/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/caching/HazelcastCacheManager.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/caching/HazelcastCacheManager.java b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/caching/HazelcastCacheManager.java
index cc037c9..b2b03a8 100644
--- a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/caching/HazelcastCacheManager.java
+++ b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/caching/HazelcastCacheManager.java
@@ -41,15 +41,6 @@ import java.util.Map;
*/
public class HazelcastCacheManager implements CacheManager {
- public static final String TRIPLE_CACHE = "triple-cache";
- public static final String URI_CACHE = "uri-cache";
- public static final String BNODE_CACHE = "bnode-cache";
- public static final String LITERAL_CACHE = "literal-cache";
- public static final String NODE_CACHE = "node-cache";
- public static final String NS_PREFIX_CACHE = "ns-prefix-cache";
- public static final String NS_URI_CACHE = "ns-uri-cache";
- public static final String REGISTRY_CACHE = "registry-cache";
-
private static Logger log = LoggerFactory.getLogger(HazelcastCacheManager.class);
private KiWiConfiguration configuration;
http://git-wip-us.apache.org/repos/asf/marmotta/blob/89763d1c/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/embedded/InfinispanEmbeddedCacheManager.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/embedded/InfinispanEmbeddedCacheManager.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/embedded/InfinispanEmbeddedCacheManager.java
index 5cf5953..6076577 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/embedded/InfinispanEmbeddedCacheManager.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/embedded/InfinispanEmbeddedCacheManager.java
@@ -21,6 +21,7 @@ import org.apache.commons.io.IOUtils;
import org.apache.marmotta.kiwi.caching.CacheManager;
import org.apache.marmotta.kiwi.config.KiWiConfiguration;
import org.apache.marmotta.kiwi.infinispan.externalizer.*;
+import org.apache.marmotta.kiwi.infinispan.util.AsyncMap;
import org.infinispan.Cache;
import org.infinispan.commons.CacheException;
import org.infinispan.commons.marshall.AdvancedExternalizer;
@@ -40,6 +41,7 @@ import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.Iterator;
+import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
@@ -52,16 +54,6 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
private static Logger log = LoggerFactory.getLogger(InfinispanEmbeddedCacheManager.class);
- public static final String NODE_CACHE = "node-cache";
- public static final String TRIPLE_CACHE = "triple-cache";
- public static final String URI_CACHE = "uri-cache";
- public static final String BNODE_CACHE = "bnode-cache";
- public static final String LITERAL_CACHE = "literal-cache";
- public static final String NAMESPACE_URI_CACHE = "namespace-uri-cache";
- public static final String NAMESPACE_PREFIX_CACHE = "namespace-prefix-cache";
- public static final String LOADER_CACHE = "loader-cache";
- public static final String REGISTRY_CACHE = "registry-cache";
-
private EmbeddedCacheManager cacheManager;
// default configuration: distributed cache, 100000 entries, 300 seconds expiration, 60 seconds idle
@@ -69,7 +61,7 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
private KiWiConfiguration config;
- private Cache nodeCache, tripleCache, uriCache, literalCache, bnodeCache, nsPrefixCache, nsUriCache, registryCache;
+ private Map nodeCache, tripleCache, uriCache, literalCache, bnodeCache, nsPrefixCache, nsUriCache, registryCache;
/**
@@ -258,7 +250,7 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
*
* @return an EHCache Cache instance containing the node id -> node mappings
*/
- public Cache getNodeCache() {
+ public Map getNodeCache() {
if(nodeCache == null) {
Configuration nodeConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
.eviction()
@@ -269,7 +261,7 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
.build();
cacheManager.defineConfiguration(NODE_CACHE, nodeConfiguration);
- nodeCache = cacheManager.getCache(NODE_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
+ nodeCache = new AsyncMap(cacheManager.getCache(NODE_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP));
}
return nodeCache;
@@ -281,7 +273,7 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
*
* @return
*/
- public Cache getTripleCache() {
+ public Map getTripleCache() {
if(tripleCache == null) {
Configuration tripleConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
.clustering()
@@ -294,7 +286,7 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
.build();
cacheManager.defineConfiguration(TRIPLE_CACHE, tripleConfiguration);
- tripleCache = cacheManager.getCache(TRIPLE_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
+ tripleCache = new AsyncMap(cacheManager.getCache(TRIPLE_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP));
}
return tripleCache;
}
@@ -306,7 +298,7 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
*
* @return
*/
- public Cache getUriCache() {
+ public Map getUriCache() {
if(uriCache == null) {
Configuration uriConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
.eviction()
@@ -314,7 +306,7 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
.build();
cacheManager.defineConfiguration(URI_CACHE, uriConfiguration);
- uriCache = cacheManager.getCache(URI_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
+ uriCache = new AsyncMap(cacheManager.getCache(URI_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP));
}
return uriCache;
}
@@ -326,7 +318,7 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
*
* @return
*/
- public Cache getBNodeCache() {
+ public Map getBNodeCache() {
if(bnodeCache == null) {
Configuration bnodeConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
.eviction()
@@ -334,7 +326,7 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
.build();
cacheManager.defineConfiguration(BNODE_CACHE, bnodeConfiguration);
- bnodeCache = cacheManager.getCache(BNODE_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
+ bnodeCache = new AsyncMap(cacheManager.getCache(BNODE_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP));
}
return bnodeCache;
}
@@ -346,7 +338,7 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
* @see org.apache.marmotta.commons.sesame.model.LiteralCommons#createCacheKey(String, java.util.Locale, String)
* @return
*/
- public Cache getLiteralCache() {
+ public Map getLiteralCache() {
if(literalCache == null) {
Configuration literalConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
.eviction()
@@ -354,7 +346,7 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
.build();
cacheManager.defineConfiguration(LITERAL_CACHE, literalConfiguration);
- literalCache = cacheManager.getCache(LITERAL_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
+ literalCache = new AsyncMap(cacheManager.getCache(LITERAL_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP));
}
return literalCache;
}
@@ -364,7 +356,7 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
* Return the URI -> namespace cache from the cache manager. Used for looking up namespaces
* @return
*/
- public Cache getNamespaceUriCache() {
+ public Map getNamespaceUriCache() {
if(nsUriCache == null) {
if(isClustered()) {
Configuration nsuriConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
@@ -375,7 +367,7 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
.expiration()
.lifespan(1, TimeUnit.DAYS)
.build();
- cacheManager.defineConfiguration(NAMESPACE_URI_CACHE, nsuriConfiguration);
+ cacheManager.defineConfiguration(NS_URI_CACHE, nsuriConfiguration);
} else {
Configuration nsuriConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
.eviction()
@@ -383,10 +375,10 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
.expiration()
.lifespan(1, TimeUnit.HOURS)
.build();
- cacheManager.defineConfiguration(NAMESPACE_URI_CACHE, nsuriConfiguration);
+ cacheManager.defineConfiguration(NS_URI_CACHE, nsuriConfiguration);
}
- nsUriCache = cacheManager.getCache(NAMESPACE_URI_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
+ nsUriCache = new AsyncMap(cacheManager.getCache(NS_URI_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP));
}
return nsUriCache;
}
@@ -395,7 +387,7 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
* Return the prefix -> namespace cache from the cache manager. Used for looking up namespaces
* @return
*/
- public Cache getNamespacePrefixCache() {
+ public Map getNamespacePrefixCache() {
if(nsPrefixCache == null) {
if(isClustered()) {
Configuration nsprefixConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
@@ -406,7 +398,7 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
.expiration()
.lifespan(1, TimeUnit.DAYS)
.build();
- cacheManager.defineConfiguration(NAMESPACE_PREFIX_CACHE, nsprefixConfiguration);
+ cacheManager.defineConfiguration(NS_PREFIX_CACHE, nsprefixConfiguration);
} else {
Configuration nsprefixConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
@@ -415,10 +407,10 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
.expiration()
.lifespan(1, TimeUnit.HOURS)
.build();
- cacheManager.defineConfiguration(NAMESPACE_PREFIX_CACHE, nsprefixConfiguration);
+ cacheManager.defineConfiguration(NS_PREFIX_CACHE, nsprefixConfiguration);
}
- nsPrefixCache = cacheManager.getCache(NAMESPACE_PREFIX_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
+ nsPrefixCache = cacheManager.getCache(NS_PREFIX_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
}
return nsPrefixCache;
}
@@ -431,7 +423,7 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
* cache and should be used with care.
* @return
*/
- public Cache getRegistryCache() {
+ public Map getRegistryCache() {
if(registryCache == null) {
if(isClustered()) {
Configuration registryConfiguration = new ConfigurationBuilder()
http://git-wip-us.apache.org/repos/asf/marmotta/blob/89763d1c/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/InfinispanRemoteCacheManager.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/InfinispanRemoteCacheManager.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/InfinispanRemoteCacheManager.java
index a4a4e38..0090387 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/InfinispanRemoteCacheManager.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/InfinispanRemoteCacheManager.java
@@ -20,6 +20,9 @@ package org.apache.marmotta.kiwi.infinispan.remote;
import org.apache.marmotta.kiwi.caching.CacheManager;
import org.apache.marmotta.kiwi.config.KiWiConfiguration;
import org.apache.marmotta.kiwi.model.rdf.*;
+import org.infinispan.client.hotrod.RemoteCacheManager;
+import org.infinispan.client.hotrod.configuration.Configuration;
+import org.infinispan.client.hotrod.configuration.ConfigurationBuilder;
import java.util.Map;
@@ -32,8 +35,20 @@ public class InfinispanRemoteCacheManager implements CacheManager {
private KiWiConfiguration configuration;
+ private RemoteCacheManager cacheManager;
+
+ private Map nodeCache, tripleCache, uriCache, literalCache, bnodeCache, nsPrefixCache, nsUriCache, registryCache;
+
+
public InfinispanRemoteCacheManager(KiWiConfiguration configuration) {
this.configuration = configuration;
+
+ Configuration remoteCfg = new ConfigurationBuilder()
+ .addServers(configuration.getClusterAddress())
+ .marshaller(new CustomJBossMarshaller())
+ .build();
+
+ cacheManager = new RemoteCacheManager(remoteCfg);
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/89763d1c/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/util/AsyncMap.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/util/AsyncMap.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/util/AsyncMap.java
new file mode 100644
index 0000000..150af7d
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/util/AsyncMap.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.infinispan.util;
+
+import org.infinispan.commons.api.BasicCache;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A Map wrapper mapping write methods to their asynchronous equivalents in Infinispan.
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class AsyncMap<K,V> implements Map<K,V> {
+
+ private BasicCache<K,V> delegate;
+
+ public AsyncMap(BasicCache<K, V> delegate) {
+ this.delegate = delegate;
+ }
+
+ @Override
+ public int size() {
+ return delegate.size();
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return delegate.isEmpty();
+ }
+
+ @Override
+ public boolean containsKey(Object o) {
+ return delegate.containsKey(o);
+ }
+
+ @Override
+ public boolean containsValue(Object o) {
+ return delegate.containsValue(o);
+ }
+
+ @Override
+ public V get(Object o) {
+ return delegate.get(o);
+ }
+
+ @Override
+ public V put(K k, V v) {
+ delegate.putAsync(k,v);
+ return null;
+ }
+
+ @Override
+ public V remove(Object o) {
+ delegate.removeAsync((K)o);
+ return null;
+ }
+
+ @Override
+ public void putAll(Map<? extends K, ? extends V> map) {
+ for(Entry<? extends K, ? extends V> entry : map.entrySet()) {
+ delegate.putAsync(entry.getKey(),entry.getValue());
+ }
+ }
+
+ @Override
+ public void clear() {
+ delegate.clear();
+ }
+
+ @Override
+ public Set<K> keySet() {
+ return delegate.keySet();
+ }
+
+ @Override
+ public Collection<V> values() {
+ return delegate.values();
+ }
+
+ @Override
+ public Set<Entry<K, V>> entrySet() {
+ return delegate.entrySet();
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/89763d1c/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/EmbeddedClusterTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/EmbeddedClusterTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/EmbeddedClusterTest.java
new file mode 100644
index 0000000..17bc3cf
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/EmbeddedClusterTest.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.test;
+
+import org.apache.marmotta.kiwi.config.CacheManagerType;
+import org.apache.marmotta.kiwi.test.cluster.BaseClusterTest;
+import org.junit.BeforeClass;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class EmbeddedClusterTest extends BaseClusterTest {
+
+
+ @BeforeClass
+ public static void setup() {
+ ClusterTestSupport s = new ClusterTestSupport(CacheManagerType.INFINISPAN_CLUSTERED);
+ s.setup();
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/89763d1c/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/InfinispanClusterTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/InfinispanClusterTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/InfinispanClusterTest.java
deleted file mode 100644
index c35a492..0000000
--- a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/InfinispanClusterTest.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.kiwi.test;
-
-import org.apache.marmotta.kiwi.config.CacheManagerType;
-import org.apache.marmotta.kiwi.test.cluster.BaseClusterTest;
-import org.junit.BeforeClass;
-
-/**
- * Add file description here!
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class InfinispanClusterTest extends BaseClusterTest {
-
-
- @BeforeClass
- public static void setup() {
- ClusterTestSupport s = new ClusterTestSupport(CacheManagerType.INFINISPAN_CLUSTERED);
- s.setup();
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/89763d1c/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/CacheManager.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/CacheManager.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/CacheManager.java
index 167b0c9..fbce98e 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/CacheManager.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/CacheManager.java
@@ -29,6 +29,16 @@ import java.util.Map;
*/
public interface CacheManager {
+ // cache name constants
+ public static final String NODE_CACHE = "node-cache";
+ public static final String TRIPLE_CACHE = "triple-cache";
+ public static final String URI_CACHE = "uri-cache";
+ public static final String BNODE_CACHE = "bnode-cache";
+ public static final String LITERAL_CACHE = "literal-cache";
+ public static final String NS_URI_CACHE = "namespace-uri-cache";
+ public static final String NS_PREFIX_CACHE = "namespace-prefix-cache";
+ public static final String REGISTRY_CACHE = "registry-cache";
+
/**
* Return the node id -> node cache from the cache manager. This cache is heavily used to lookup
http://git-wip-us.apache.org/repos/asf/marmotta/blob/89763d1c/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java
index fb9fb2c..2db24f2 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java
@@ -520,7 +520,7 @@ public class KiWiConfiguration {
* used by JGroups to distribute and receive cache synchronization updates. Triplestores with different
* data should use different ports or addresses,
* <p/>
- * Only used in case isClustered() is true
+ * Only used in case isClustered() is true and the cache mode is not client-server.
*
* @return
*/
@@ -533,7 +533,7 @@ public class KiWiConfiguration {
* used by JGroups to distribute and receive cache synchronization updates. Triplestores with different
* data should use different ports or addresses.
* <p/>
- * Only used in case isClustered() is true
+ * Only used in case isClustered() is true and the cache mode is not client-server.
*
* @return
*/
@@ -542,10 +542,15 @@ public class KiWiConfiguration {
}
/**
- * Return the multicast address used by the cache cluster this triplestore belongs to. This address is
- * used by JGroups to distribute and receive cache synchronization updates. Triplestores with different
- * data should use different ports or addresses,
- * <p/>
+ * The cluster address serves two purposes, depending on the kind of caching used.
+ * <ul>
+ * <li>for distributed clusters (Infinispan, Hazelcast, ...), it specifies the multicast address used by the
+ * cache cluster this triplestore belongs to. This address is used by JGroups to distribute and receive cache
+ * synchronization updates. Triplestores with different data should use different ports or addresses,</li>
+ * <li>for client-server caches (Infinispan Remote, Memcached, ...), it specifies the list of cache servers
+ * to connect to.</li>
+ * </ul>
+ *
* Only used in case isClustered() is true
*
* @return
@@ -555,9 +560,15 @@ public class KiWiConfiguration {
}
/**
- * Change the multicast address used by the cache cluster this triplestore belongs to. This address is
- * used by JGroups to distribute and receive cache synchronization updates. Triplestores with different
- * data should use different ports or addresses,
+ * The cluster address serves two purposes, depending on the kind of caching used.
+ * <ul>
+ * <li>for distributed clusters (Infinispan, Hazelcast, ...), it specifies the multicast address used by the
+ * cache cluster this triplestore belongs to. This address is used by JGroups to distribute and receive cache
+ * synchronization updates. Triplestores with different data should use different ports or addresses,</li>
+ * <li>for client-server caches (Infinispan Remote, Memcached, ...), it specifies the list of cache servers
+ * to connect to.</li>
+ * </ul>
+ *
* <p/>
* Only used in case isClustered() is true
*
[17/21] added repository tests to other cache implementations
Posted by ss...@apache.org.
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/cluster/BaseClusterTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/cluster/BaseClusterTest.java b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/cluster/BaseClusterTest.java
index d2e12ef..d5f7e16 100644
--- a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/cluster/BaseClusterTest.java
+++ b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/cluster/BaseClusterTest.java
@@ -20,6 +20,8 @@ package org.apache.marmotta.kiwi.test.cluster;
import org.apache.marmotta.kiwi.caching.CacheManager;
import org.apache.marmotta.kiwi.config.CacheManagerType;
import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+import org.apache.marmotta.kiwi.model.rdf.KiWiAnonResource;
+import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
import org.apache.marmotta.kiwi.persistence.h2.H2Dialect;
import org.apache.marmotta.kiwi.sail.KiWiStore;
import org.junit.AfterClass;
@@ -59,11 +61,11 @@ public abstract class BaseClusterTest {
@Test
- public void testClusteredCacheSync() throws InterruptedException, RepositoryException {
+ public void testClusteredCacheUri() throws InterruptedException, RepositoryException {
log.info("testing cache synchronization ...");
- URI u = repositorySync1.getValueFactory().createURI("http://localhost/test1");
+ KiWiUriResource u = (KiWiUriResource) repositorySync1.getValueFactory().createURI("http://localhost/test1");
// give the cluster some time to performance asynchronous balancing
@@ -71,18 +73,49 @@ public abstract class BaseClusterTest {
log.debug("test if resource is in cache where it was created ...");
- URI u1 = (URI) cacheManagerSync1.getUriCache().get("http://localhost/test1");
+ KiWiUriResource u1 = cacheManagerSync1.getUriCache().get("http://localhost/test1");
+
+ Assert.assertNotNull(u1);
+ Assert.assertEquals(u, u1);
+ Assert.assertEquals(u.getId(), u1.getId());
+
+ log.debug("test if resource has been synced to other cache in cluster ...");
+ KiWiUriResource u2 = cacheManagerSync2.getUriCache().get("http://localhost/test1");
+
+ Assert.assertNotNull(u2);
+ Assert.assertEquals(u, u2);
+ Assert.assertEquals(u.getId(), u2.getId());
+ }
+
+
+ @Test
+ public void testClusteredCacheBNode() throws InterruptedException, RepositoryException {
+
+ log.info("testing cache synchronization ...");
+
+ KiWiAnonResource u = (KiWiAnonResource) repositorySync1.getValueFactory().createBNode();
+
+
+ // give the cluster some time to performance asynchronous balancing
+ Thread.sleep(100);
+
+
+ log.debug("test if resource is in cache where it was created ...");
+ KiWiAnonResource u1 = cacheManagerSync1.getBNodeCache().get(u.getID());
Assert.assertNotNull(u1);
Assert.assertEquals(u,u1);
+ Assert.assertEquals(u.getId(), u1.getId());
log.debug("test if resource has been synced to other cache in cluster ...");
- URI u2 = (URI) cacheManagerSync2.getUriCache().get("http://localhost/test1");
+ KiWiAnonResource u2 = cacheManagerSync2.getBNodeCache().get(u.getID());
Assert.assertNotNull(u2);
- Assert.assertEquals(u,u2);
+ Assert.assertEquals(u, u2);
+ Assert.assertEquals(u.getId(), u2.getId());
}
+
@Test
public void testDisjointClusters() throws InterruptedException, RepositoryException {
[07/21] git commit: copied serializers to Hazelcast backend
Posted by ss...@apache.org.
copied serializers to Hazelcast backend
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/4d26a1be
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/4d26a1be
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/4d26a1be
Branch: refs/heads/MARMOTTA-450
Commit: 4d26a1be6ad78aef2b565b837918485ada6e305d
Parents: 27a9c26
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Mon Mar 3 18:37:35 2014 +0100
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Mon Mar 3 18:37:35 2014 +0100
----------------------------------------------------------------------
.../caching/HazelcastCacheManager.java | 26 ++++
.../caching/HazelcastCacheManagerFactory.java | 26 ++++
.../hazelcast/serializer/BNodeSerializer.java | 72 +++++++++
.../serializer/BooleanLiteralSerializer.java | 71 +++++++++
.../serializer/DateLiteralSerializer.java | 71 +++++++++
.../serializer/DoubleLiteralSerializer.java | 70 +++++++++
.../hazelcast/serializer/ExternalizerIds.java | 43 ++++++
.../serializer/IntLiteralSerializer.java | 71 +++++++++
.../serializer/StringLiteralSerializer.java | 78 ++++++++++
.../hazelcast/serializer/TripleSerializer.java | 148 +++++++++++++++++++
.../hazelcast/serializer/UriSerializer.java | 134 +++++++++++++++++
.../apache/marmotta/kiwi/test/ClusterTest.java | 4 +-
.../marmotta/kiwi/caching/CacheManagerType.java | 58 ++++++++
.../marmotta/kiwi/config/KiWiConfiguration.java | 11 +-
.../kiwi/persistence/KiWiPersistence.java | 4 +-
15 files changed, 878 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/4d26a1be/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/caching/HazelcastCacheManager.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/caching/HazelcastCacheManager.java b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/caching/HazelcastCacheManager.java
new file mode 100644
index 0000000..83ba267
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/caching/HazelcastCacheManager.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.hazelcast.caching;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class HazelcastCacheManager {
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/4d26a1be/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/caching/HazelcastCacheManagerFactory.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/caching/HazelcastCacheManagerFactory.java b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/caching/HazelcastCacheManagerFactory.java
new file mode 100644
index 0000000..dee0b13
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/caching/HazelcastCacheManagerFactory.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.hazelcast.caching;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class HazelcastCacheManagerFactory {
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/4d26a1be/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/BNodeSerializer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/BNodeSerializer.java b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/BNodeSerializer.java
new file mode 100644
index 0000000..4462537
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/BNodeSerializer.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.hazelcast.serializer;
+
+import com.hazelcast.nio.ObjectDataInput;
+import com.hazelcast.nio.ObjectDataOutput;
+import com.hazelcast.nio.serialization.StreamSerializer;
+import org.apache.marmotta.kiwi.model.rdf.KiWiAnonResource;
+
+import java.io.IOException;
+import java.util.Date;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class BNodeSerializer implements StreamSerializer<KiWiAnonResource> {
+
+
+
+ @Override
+ public int getTypeId() {
+ return ExternalizerIds.BNODE;
+ }
+
+ @Override
+ public void write(ObjectDataOutput output, KiWiAnonResource object) throws IOException {
+ output.writeLong(object.getId());
+ output.writeInt(object.stringValue().length());
+ output.writeChars(object.stringValue());
+ output.writeLong(object.getCreated().getTime());
+ }
+
+ @Override
+ public KiWiAnonResource read(ObjectDataInput input) throws IOException {
+ long id = input.readLong();
+ int len = input.readInt();
+
+ char[] anonId = new char[len];
+ for(int i=0; i<len; i++) {
+ anonId[i] = input.readChar();
+ }
+
+ Date created = new Date(input.readLong());
+
+ KiWiAnonResource r = new KiWiAnonResource(new String(anonId),created);
+ r.setId(id);
+
+ return r;
+ }
+
+ @Override
+ public void destroy() {
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/4d26a1be/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/BooleanLiteralSerializer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/BooleanLiteralSerializer.java b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/BooleanLiteralSerializer.java
new file mode 100644
index 0000000..0246e35
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/BooleanLiteralSerializer.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.hazelcast.serializer;
+
+import com.hazelcast.nio.ObjectDataInput;
+import com.hazelcast.nio.ObjectDataOutput;
+import com.hazelcast.nio.serialization.StreamSerializer;
+import org.apache.marmotta.kiwi.model.rdf.KiWiBooleanLiteral;
+import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
+
+import java.io.IOException;
+import java.util.Date;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class BooleanLiteralSerializer implements StreamSerializer<KiWiBooleanLiteral> {
+
+
+ @Override
+ public int getTypeId() {
+ return ExternalizerIds.BOOL_LITERAL;
+ }
+
+ @Override
+ public void write(ObjectDataOutput output, KiWiBooleanLiteral object) throws IOException {
+ output.writeLong(object.getId());
+ output.writeBoolean(object.booleanValue());
+ output.writeObject(object.getDatatype());
+
+ output.writeLong(object.getCreated().getTime());
+
+ }
+
+ @Override
+ public KiWiBooleanLiteral read(ObjectDataInput input) throws IOException {
+ long id = input.readLong();
+ boolean content = input.readBoolean();
+
+ KiWiUriResource dtype = (KiWiUriResource) input.readObject();
+
+ Date created = new Date(input.readLong());
+
+ KiWiBooleanLiteral r = new KiWiBooleanLiteral(content, dtype, created);
+ r.setId(id);
+
+ return r;
+ }
+
+ @Override
+ public void destroy() {
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/4d26a1be/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/DateLiteralSerializer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/DateLiteralSerializer.java b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/DateLiteralSerializer.java
new file mode 100644
index 0000000..1ddd75d
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/DateLiteralSerializer.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.hazelcast.serializer;
+
+import com.hazelcast.nio.ObjectDataInput;
+import com.hazelcast.nio.ObjectDataOutput;
+import com.hazelcast.nio.serialization.StreamSerializer;
+import org.apache.marmotta.kiwi.model.rdf.KiWiDateLiteral;
+import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
+
+import java.io.IOException;
+import java.util.Date;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class DateLiteralSerializer implements StreamSerializer<KiWiDateLiteral> {
+
+
+ @Override
+ public int getTypeId() {
+ return ExternalizerIds.DATE_LITERAL;
+ }
+
+ @Override
+ public void write(ObjectDataOutput output, KiWiDateLiteral object) throws IOException {
+ output.writeLong(object.getId());
+ output.writeLong(object.getDateContent().getTime());
+ output.writeObject(object.getDatatype());
+
+ output.writeLong(object.getCreated().getTime());
+
+ }
+
+ @Override
+ public KiWiDateLiteral read(ObjectDataInput input) throws IOException {
+ long id = input.readLong();
+ Date content = new Date(input.readLong());
+
+ KiWiUriResource dtype = (KiWiUriResource) input.readObject();
+
+ Date created = new Date(input.readLong());
+
+ KiWiDateLiteral r = new KiWiDateLiteral(content, dtype, created);
+ r.setId(id);
+
+ return r;
+ }
+
+ @Override
+ public void destroy() {
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/4d26a1be/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/DoubleLiteralSerializer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/DoubleLiteralSerializer.java b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/DoubleLiteralSerializer.java
new file mode 100644
index 0000000..61ba8e4
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/DoubleLiteralSerializer.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.hazelcast.serializer;
+
+import com.hazelcast.nio.ObjectDataInput;
+import com.hazelcast.nio.ObjectDataOutput;
+import com.hazelcast.nio.serialization.StreamSerializer;
+import org.apache.marmotta.kiwi.model.rdf.KiWiDoubleLiteral;
+import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
+
+import java.io.IOException;
+import java.util.Date;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class DoubleLiteralSerializer implements StreamSerializer<KiWiDoubleLiteral> {
+
+ @Override
+ public int getTypeId() {
+ return ExternalizerIds.DOUBLE_LITERAL;
+ }
+
+ @Override
+ public void write(ObjectDataOutput output, KiWiDoubleLiteral object) throws IOException {
+ output.writeLong(object.getId());
+ output.writeDouble(object.getDoubleContent());
+ output.writeObject(object.getDatatype());
+
+ output.writeLong(object.getCreated().getTime());
+
+ }
+
+ @Override
+ public KiWiDoubleLiteral read(ObjectDataInput input) throws IOException {
+ long id = input.readLong();
+ double content = input.readDouble();
+
+ KiWiUriResource dtype = (KiWiUriResource) input.readObject();
+
+ Date created = new Date(input.readLong());
+
+ KiWiDoubleLiteral r = new KiWiDoubleLiteral(content, dtype, created);
+ r.setId(id);
+
+ return r;
+ }
+
+ @Override
+ public void destroy() {
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/4d26a1be/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/ExternalizerIds.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/ExternalizerIds.java b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/ExternalizerIds.java
new file mode 100644
index 0000000..641beca
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/ExternalizerIds.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.hazelcast.serializer;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class ExternalizerIds {
+
+ public static final int TRIPLE = 13;
+
+ public static final int URI = 17;
+
+ public static final int BNODE = 23;
+
+ public static final int STRING_LITERAL = 19;
+
+ public static final int INT_LITERAL = 39;
+
+ public static final int DOUBLE_LITERAL = 37;
+
+ public static final int DATE_LITERAL = 29;
+
+ public static final int BOOL_LITERAL = 31;
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/4d26a1be/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/IntLiteralSerializer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/IntLiteralSerializer.java b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/IntLiteralSerializer.java
new file mode 100644
index 0000000..12d49b4
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/IntLiteralSerializer.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.hazelcast.serializer;
+
+import com.hazelcast.nio.ObjectDataInput;
+import com.hazelcast.nio.ObjectDataOutput;
+import com.hazelcast.nio.serialization.StreamSerializer;
+import org.apache.marmotta.kiwi.model.rdf.KiWiIntLiteral;
+import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
+
+import java.io.IOException;
+import java.util.Date;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class IntLiteralSerializer implements StreamSerializer<KiWiIntLiteral> {
+
+
+ @Override
+ public int getTypeId() {
+ return ExternalizerIds.INT_LITERAL;
+ }
+
+ @Override
+ public void write(ObjectDataOutput output, KiWiIntLiteral object) throws IOException {
+ output.writeLong(object.getId());
+ output.writeLong(object.getIntContent());
+ output.writeObject(object.getDatatype());
+
+ output.writeLong(object.getCreated().getTime());
+
+ }
+
+ @Override
+ public KiWiIntLiteral read(ObjectDataInput input) throws IOException {
+ long id = input.readLong();
+ long content = input.readLong();
+
+ KiWiUriResource dtype = (KiWiUriResource) input.readObject();
+
+ Date created = new Date(input.readLong());
+
+ KiWiIntLiteral r = new KiWiIntLiteral(content, dtype, created);
+ r.setId(id);
+
+ return r;
+ }
+
+ @Override
+ public void destroy() {
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/4d26a1be/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/StringLiteralSerializer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/StringLiteralSerializer.java b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/StringLiteralSerializer.java
new file mode 100644
index 0000000..6531aa0
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/StringLiteralSerializer.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.hazelcast.serializer;
+
+import com.hazelcast.nio.ObjectDataInput;
+import com.hazelcast.nio.ObjectDataOutput;
+import com.hazelcast.nio.serialization.StreamSerializer;
+import org.apache.marmotta.commons.io.DataIO;
+import org.apache.marmotta.kiwi.model.rdf.KiWiStringLiteral;
+import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
+
+import java.io.IOException;
+import java.util.Date;
+import java.util.Locale;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class StringLiteralSerializer implements StreamSerializer<KiWiStringLiteral> {
+
+
+ @Override
+ public int getTypeId() {
+ return ExternalizerIds.STRING_LITERAL;
+ }
+
+ @Override
+ public void write(ObjectDataOutput output, KiWiStringLiteral object) throws IOException {
+ output.writeLong(object.getId());
+
+ DataIO.writeString(output, object.getContent());
+ DataIO.writeString(output, object.getLanguage());
+
+ output.writeObject(object.getDatatype());
+
+ output.writeLong(object.getCreated().getTime());
+
+ }
+
+ @Override
+ public KiWiStringLiteral read(ObjectDataInput input) throws IOException {
+ long id = input.readLong();
+
+ String content = DataIO.readString(input);
+ String lang = DataIO.readString(input);
+
+ KiWiUriResource dtype = (KiWiUriResource) input.readObject();
+
+ Date created = new Date(input.readLong());
+
+ KiWiStringLiteral r = new KiWiStringLiteral(content, lang != null ? Locale.forLanguageTag(lang) : null, dtype, created);
+ r.setId(id);
+
+ return r;
+ }
+
+ @Override
+ public void destroy() {
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/4d26a1be/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/TripleSerializer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/TripleSerializer.java b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/TripleSerializer.java
new file mode 100644
index 0000000..cb2de2a
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/TripleSerializer.java
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.hazelcast.serializer;
+
+import com.hazelcast.nio.ObjectDataInput;
+import com.hazelcast.nio.ObjectDataOutput;
+import com.hazelcast.nio.serialization.StreamSerializer;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.marmotta.commons.io.DataIO;
+import org.apache.marmotta.kiwi.model.rdf.KiWiNode;
+import org.apache.marmotta.kiwi.model.rdf.KiWiResource;
+import org.apache.marmotta.kiwi.model.rdf.KiWiTriple;
+import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
+
+import java.io.IOException;
+import java.util.Date;
+
+/**
+ * An externalizer for Infinispan allowing to more efficiently transport triples by only serializing the node
+ * IDs instead of the whole nodes.
+ */
+public class TripleSerializer implements StreamSerializer<KiWiTriple> {
+
+
+ public static final int MODE_DEFAULT = 1;
+ public static final int MODE_PREFIX = 2;
+
+
+
+ @Override
+ public int getTypeId() {
+ return ExternalizerIds.TRIPLE;
+ }
+
+ @Override
+ public void write(ObjectDataOutput output, KiWiTriple object) throws IOException {
+ output.writeLong(object.getId());
+
+ // in case subject and object are both uris we use a special prefix-compressed mode
+ if(object.getSubject().isUriResource() && object.getObject().isUriResource()) {
+ String sUri = object.getSubject().stringValue();
+ String oUri = object.getObject().stringValue();
+
+ String prefix = StringUtils.getCommonPrefix(sUri,oUri);
+
+ output.writeByte(MODE_PREFIX);
+ DataIO.writeString(output,prefix);
+
+ output.writeLong(object.getSubject().getId());
+ DataIO.writeString(output, sUri.substring(prefix.length()));
+ output.writeLong(object.getSubject().getCreated().getTime());
+
+ output.writeObject(object.getPredicate());
+
+ output.writeLong(object.getObject().getId());
+ DataIO.writeString(output, oUri.substring(prefix.length()));
+ output.writeLong(object.getObject().getCreated().getTime());
+ } else {
+ output.writeByte(MODE_DEFAULT);
+
+ output.writeObject(object.getSubject());
+ output.writeObject(object.getPredicate());
+ output.writeObject(object.getObject());
+ }
+
+ output.writeObject(object.getContext());
+ output.writeObject(object.getCreator());
+ output.writeBoolean(object.isDeleted());
+ output.writeBoolean(object.isInferred());
+ output.writeBoolean(object.isNewTriple());
+ output.writeLong(object.getCreated().getTime());
+ if(object.getDeletedAt() != null) {
+ output.writeLong(object.getDeletedAt().getTime());
+ } else {
+ output.writeLong(0);
+ }
+ }
+
+ @Override
+ public KiWiTriple read(ObjectDataInput input) throws IOException {
+
+ KiWiTriple result = new KiWiTriple();
+ result.setId(input.readLong());
+
+ int mode = input.readByte();
+ if(mode == MODE_PREFIX) {
+ String prefix = DataIO.readString(input);
+
+ long sId = input.readLong();
+ String sUri = prefix + DataIO.readString(input);
+ long sTime = input.readLong();
+ KiWiUriResource s = new KiWiUriResource(sUri);
+ s.setId(sId);
+ s.setCreated(new Date(sTime));
+ result.setSubject(s);
+
+ result.setPredicate((KiWiUriResource) input.readObject());
+
+ long oId = input.readLong();
+ String oUri = prefix + DataIO.readString(input);
+ long oTime = input.readLong();
+ KiWiUriResource o = new KiWiUriResource(oUri);
+ o.setId(oId);
+ o.setCreated(new Date(oTime));
+ result.setObject(o);
+
+ } else {
+ result.setSubject((KiWiResource) input.readObject());
+ result.setPredicate((KiWiUriResource) input.readObject());
+ result.setObject((KiWiNode) input.readObject());
+ }
+ result.setContext((KiWiResource) input.readObject());
+ result.setCreator((KiWiResource) input.readObject());
+ result.setDeleted(input.readBoolean());
+ result.setInferred(input.readBoolean());
+ result.setNewTriple(input.readBoolean());
+
+ result.setCreated(new Date(input.readLong()));
+
+ long deletedAt = input.readLong();
+ if(deletedAt > 0) {
+ result.setDeletedAt(new Date(deletedAt));
+ }
+
+
+ return result;
+ }
+
+ @Override
+ public void destroy() {
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/4d26a1be/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/UriSerializer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/UriSerializer.java b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/UriSerializer.java
new file mode 100644
index 0000000..0f235d5
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/UriSerializer.java
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.hazelcast.serializer;
+
+import com.hazelcast.nio.ObjectDataInput;
+import com.hazelcast.nio.ObjectDataOutput;
+import com.hazelcast.nio.serialization.StreamSerializer;
+import org.apache.marmotta.commons.io.DataIO;
+import org.apache.marmotta.commons.vocabulary.XSD;
+import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
+import org.openrdf.model.vocabulary.*;
+
+import java.io.IOException;
+import java.util.Date;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class UriSerializer implements StreamSerializer<KiWiUriResource> {
+
+ private static final int PREFIX_UNKNOWN = 0;
+ private static final int PREFIX_XSD = 1;
+ private static final int PREFIX_RDF = 2;
+ private static final int PREFIX_RDFS = 3;
+ private static final int PREFIX_SKOS = 4;
+ private static final int PREFIX_DC = 5;
+ private static final int PREFIX_DCT = 6;
+ private static final int PREFIX_OWL = 7;
+
+
+ @Override
+ public int getTypeId() {
+ return ExternalizerIds.URI;
+ }
+
+ @Override
+ public void write(ObjectDataOutput output, KiWiUriResource object) throws IOException {
+ output.writeLong(object.getId());
+
+ // compression for commonly used constant prefixes
+ if(object.stringValue().startsWith(XSD.NAMESPACE)) {
+ output.writeByte(PREFIX_XSD);
+ DataIO.writeString(output, object.stringValue().substring(XSD.NAMESPACE.length()));
+ } else if(object.stringValue().startsWith(RDF.NAMESPACE)) {
+ output.writeByte(PREFIX_RDF);
+ DataIO.writeString(output, object.stringValue().substring(RDF.NAMESPACE.length()));
+ } else if(object.stringValue().startsWith(RDFS.NAMESPACE)) {
+ output.writeByte(PREFIX_RDFS);
+ DataIO.writeString(output, object.stringValue().substring(RDFS.NAMESPACE.length()));
+ } else if(object.stringValue().startsWith(SKOS.NAMESPACE)) {
+ output.writeByte(PREFIX_SKOS);
+ DataIO.writeString(output, object.stringValue().substring(SKOS.NAMESPACE.length()));
+ } else if(object.stringValue().startsWith(DC.NAMESPACE)) {
+ output.writeByte(PREFIX_DC);
+ DataIO.writeString(output, object.stringValue().substring(DC.NAMESPACE.length()));
+ } else if(object.stringValue().startsWith(DCTERMS.NAMESPACE)) {
+ output.writeByte(PREFIX_DCT);
+ DataIO.writeString(output, object.stringValue().substring(DCTERMS.NAMESPACE.length()));
+ } else if(object.stringValue().startsWith(OWL.NAMESPACE)) {
+ output.writeByte(PREFIX_OWL);
+ DataIO.writeString(output, object.stringValue().substring(OWL.NAMESPACE.length()));
+ } else {
+ output.writeByte(PREFIX_UNKNOWN);
+ DataIO.writeString(output, object.stringValue());
+ }
+
+ output.writeLong(object.getCreated().getTime());
+ }
+
+ @Override
+ public KiWiUriResource read(ObjectDataInput input) throws IOException {
+ long id = input.readLong();
+
+ int prefixMode = input.readByte();
+ String uriPrefix = "";
+ String uriSuffix = DataIO.readString(input);
+
+ switch (prefixMode) {
+ case PREFIX_XSD:
+ uriPrefix = XSD.NAMESPACE;
+ break;
+ case PREFIX_RDF:
+ uriPrefix = RDF.NAMESPACE;
+ break;
+ case PREFIX_RDFS:
+ uriPrefix = RDFS.NAMESPACE;
+ break;
+ case PREFIX_SKOS:
+ uriPrefix = SKOS.NAMESPACE;
+ break;
+ case PREFIX_DC:
+ uriPrefix = DC.NAMESPACE;
+ break;
+ case PREFIX_DCT:
+ uriPrefix = DCTERMS.NAMESPACE;
+ break;
+ case PREFIX_OWL:
+ uriPrefix = OWL.NAMESPACE;
+ break;
+ default:
+ uriPrefix = "";
+ break;
+ }
+
+ Date created = new Date(input.readLong());
+
+ KiWiUriResource r = new KiWiUriResource(uriPrefix + uriSuffix,created);
+ r.setId(id);
+
+ return r;
+ }
+
+ @Override
+ public void destroy() {
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/4d26a1be/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/ClusterTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/ClusterTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/ClusterTest.java
index 0b6823c..981e595 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/ClusterTest.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/ClusterTest.java
@@ -58,7 +58,7 @@ public class ClusterTest {
new H2Dialect());
config1.setDatacenterId(1);
config1.setClustered(true);
- config1.setCacheManagerFactory(InfinispanEmbeddedCacheManagerFactory.class.getName());
+ config1.setCacheManager(InfinispanEmbeddedCacheManagerFactory.class.getName());
config2 = new KiWiConfiguration(
"default-H2",
@@ -67,7 +67,7 @@ public class ClusterTest {
new H2Dialect());
config2.setDatacenterId(2);
config2.setClustered(true);
- config2.setCacheManagerFactory(InfinispanEmbeddedCacheManagerFactory.class.getName());
+ config2.setCacheManager(InfinispanEmbeddedCacheManagerFactory.class.getName());
http://git-wip-us.apache.org/repos/asf/marmotta/blob/4d26a1be/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/CacheManagerType.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/CacheManagerType.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/CacheManagerType.java
new file mode 100644
index 0000000..25dc7b8
--- /dev/null
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/CacheManagerType.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.caching;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public enum CacheManagerType {
+
+ /**
+ * Simple in-memory cache backend using the Guava library; no clustering support
+ */
+ GUAVA("org.apache.marmotta.kiwi.caching.GuavaCacheManagerFactory"),
+
+ /**
+ * Cache backend based on Infinispan using a dynamic cluster setup (UDP multicast)
+ */
+ INFINISPAN_CLUSTERED("org.apache.marmotta.kiwi.embedded.InfinispanEmbeddedCacheManagerFactory"),
+
+ /**
+ * Cache backend based on Infinispan using a client-server setup (Hotrod)
+ */
+ INFINISPAN_HOTROD("org.apache.marmotta.kiwi.remote.InfinispanRemoteCacheManagerFactory"),
+
+
+ /**
+ * Cache backend based on Hazelcast using a dynamic cluster setup
+ */
+ HAZELCAST("org.apache.marmotta.kiwi.hazelcast.caching.HazelcastCacheManagerFactory");
+
+
+ CacheManagerType(String factoryClass) {
+ this.factoryClass = factoryClass;
+ }
+
+ private String factoryClass;
+
+ public String getFactoryClass() {
+ return factoryClass;
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/4d26a1be/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java
index a445112..7ffee6a 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java
@@ -17,6 +17,7 @@
*/
package org.apache.marmotta.kiwi.config;
+import org.apache.marmotta.kiwi.caching.CacheManagerType;
import org.apache.marmotta.kiwi.persistence.KiWiDialect;
import java.util.ArrayList;
@@ -95,7 +96,7 @@ public class KiWiConfiguration {
* Fully qualified class name of the cache manager factory to use. Falls back to the Guava
* cache manager if not found
*/
- private String cacheManagerFactory = "org.apache.marmotta.kiwi.caching.GuavaCacheManagerFactory";
+ private CacheManagerType cacheManager = CacheManagerType.GUAVA;
private int nodeCacheSize = 1000000;
@@ -300,16 +301,16 @@ public class KiWiConfiguration {
* Fully qualified class name of the cache manager factory to use. Falls back to the Guava
* cache manager if not found
*/
- public String getCacheManagerFactory() {
- return cacheManagerFactory;
+ public CacheManagerType getCacheManager() {
+ return cacheManager;
}
/**
* Fully qualified class name of the cache manager factory to use. Falls back to the Guava
* cache manager if not found
*/
- public void setCacheManagerFactory(String cacheManagerFactory) {
- this.cacheManagerFactory = cacheManagerFactory;
+ public void setCacheManager(CacheManagerType cacheManager) {
+ this.cacheManager = cacheManager;
}
/**
http://git-wip-us.apache.org/repos/asf/marmotta/blob/4d26a1be/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiPersistence.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiPersistence.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiPersistence.java
index 6d81065..54e60a9 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiPersistence.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiPersistence.java
@@ -131,10 +131,10 @@ public class KiWiPersistence {
private void initCachePool() {
try {
- Class factory = Class.forName(configuration.getCacheManagerFactory());
+ Class factory = Class.forName(configuration.getCacheManager().getFactoryClass());
cacheManager = ((CacheManagerFactory)factory.newInstance()).createCacheManager(configuration);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
- log.warn("cache manager factory {} not found on classpath (error: {}); falling back to Guava in-memory cache backend!", configuration.getCacheManagerFactory(), e.getMessage());
+ log.warn("cache manager factory {} not found on classpath (error: {}); falling back to Guava in-memory cache backend!", configuration.getCacheManager(), e.getMessage());
CacheManagerFactory factory = new GuavaCacheManagerFactory();
cacheManager = factory.createCacheManager(configuration);
[03/21] git commit: started working on cleaner cache API for KiWi
Posted by ss...@apache.org.
started working on cleaner cache API for KiWi
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/c6d0cc13
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/c6d0cc13
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/c6d0cc13
Branch: refs/heads/MARMOTTA-450
Commit: c6d0cc1336fe9649be572383a423979a1dda915b
Parents: e2e23ef
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Mon Mar 3 16:24:00 2014 +0100
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Mon Mar 3 16:24:00 2014 +0100
----------------------------------------------------------------------
libraries/kiwi/kiwi-caching-hazelcast/pom.xml | 53 ++
libraries/kiwi/kiwi-caching-infinispan/pom.xml | 113 ++++
.../InfinispanEmbeddedCacheManager.java | 505 ++++++++++++++++++
.../InfinispanEmbeddedCacheManagerFactory.java | 44 ++
.../kiwi/externalizer/BNodeExternalizer.java | 74 +++
.../BooleanLiteralExternalizer.java | 72 +++
.../externalizer/DateLiteralExternalizer.java | 72 +++
.../externalizer/DoubleLiteralExternalizer.java | 72 +++
.../kiwi/externalizer/ExternalizerIds.java | 41 ++
.../externalizer/IntLiteralExternalizer.java | 72 +++
.../externalizer/StringLiteralExternalizer.java | 95 ++++
.../kiwi/externalizer/TripleExternalizer.java | 127 +++++
.../kiwi/externalizer/UriExternalizer.java | 72 +++
.../remote/InfinispanRemoteCacheManager.java | 40 ++
.../InfinispanRemoteCacheManagerFactory.java | 44 ++
...he.marmotta.kiwi.caching.CacheManagerFactory | 2 +
.../test/externalizer/ExternalizerTest.java | 187 +++++++
libraries/kiwi/kiwi-triplestore/pom.xml | 5 -
.../kiwi/caching/BNodeExternalizer.java | 74 ---
.../caching/BooleanLiteralExternalizer.java | 72 ---
.../marmotta/kiwi/caching/CacheManager.java | 124 +++++
.../kiwi/caching/CacheManagerFactory.java | 37 ++
.../kiwi/caching/DateLiteralExternalizer.java | 72 ---
.../kiwi/caching/DoubleLiteralExternalizer.java | 72 ---
.../marmotta/kiwi/caching/ExternalizerIds.java | 41 --
.../kiwi/caching/GuavaCacheManager.java | 233 ++++++++
.../kiwi/caching/GuavaCacheManagerFactory.java | 42 ++
.../kiwi/caching/IntLiteralExternalizer.java | 72 ---
.../marmotta/kiwi/caching/KiWiCacheManager.java | 528 -------------------
.../kiwi/caching/StringLiteralExternalizer.java | 95 ----
.../kiwi/caching/TripleExternalizer.java | 127 -----
.../marmotta/kiwi/caching/UriExternalizer.java | 72 ---
.../marmotta/kiwi/config/KiWiConfiguration.java | 39 ++
.../kiwi/persistence/KiWiConnection.java | 50 +-
.../kiwi/persistence/KiWiPersistence.java | 43 +-
.../registry/CacheTripleRegistry.java | 9 +-
.../apache/marmotta/kiwi/sail/KiWiStore.java | 5 -
...he.marmotta.kiwi.caching.CacheManagerFactory | 1 +
.../test/externalizer/ExternalizerTest.java | 188 -------
libraries/kiwi/pom.xml | 2 +
parent/pom.xml | 8 +
41 files changed, 2209 insertions(+), 1487 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-caching-hazelcast/pom.xml
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/pom.xml b/libraries/kiwi/kiwi-caching-hazelcast/pom.xml
new file mode 100644
index 0000000..833fece
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-hazelcast/pom.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.marmotta</groupId>
+ <artifactId>kiwi-parent</artifactId>
+ <version>3.2.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>kiwi-caching-hazelcast</artifactId>
+ <packaging>jar</packaging>
+
+ <name>KiWi Triplestore: Hazelcast Cache Backend</name>
+ <description>
+ Hazelcast cache implementation for the KiWi triplestore. Useful for more complex cluster
+ configurations with shared caches.
+ </description>
+
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.marmotta</groupId>
+ <artifactId>kiwi-triplestore</artifactId>
+ </dependency>
+
+ <!-- Caching -->
+ <dependency>
+ <groupId>com.hazelcast</groupId>
+ <artifactId>hazelcast</artifactId>
+ </dependency>
+ </dependencies>
+
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-caching-infinispan/pom.xml
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/pom.xml b/libraries/kiwi/kiwi-caching-infinispan/pom.xml
new file mode 100644
index 0000000..7ec7dc1
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/pom.xml
@@ -0,0 +1,113 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.marmotta</groupId>
+ <artifactId>kiwi-parent</artifactId>
+ <version>3.2.0-SNAPSHOT</version>
+ <relativePath>../</relativePath>
+ </parent>
+
+ <artifactId>kiwi-caching-infinispan</artifactId>
+ <packaging>jar</packaging>
+
+ <name>KiWi Triplestore: Infinispan Cache Backend</name>
+ <description>
+ Infinispan cache implementation for the KiWi triplestore. Useful for more complex cluster
+ configurations with shared caches.
+ </description>
+
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.marmotta</groupId>
+ <artifactId>kiwi-triplestore</artifactId>
+ </dependency>
+
+ <!-- Caching -->
+ <dependency>
+ <groupId>org.infinispan</groupId>
+ <artifactId>infinispan-core</artifactId>
+ </dependency>
+
+
+ <!-- Testing -->
+ <dependency>
+ <artifactId>junit</artifactId>
+ <groupId>junit</groupId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.marmotta</groupId>
+ <artifactId>kiwi-triplestore</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <artifactId>hamcrest-core</artifactId>
+ <groupId>org.hamcrest</groupId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <artifactId>hamcrest-library</artifactId>
+ <groupId>org.hamcrest</groupId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.postgresql</groupId>
+ <artifactId>postgresql</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ <scope>test</scope>
+ <optional>true</optional> <!-- GPL licensed, no dependency -->
+ </dependency>
+ <dependency>
+ <groupId>org.openrdf.sesame</groupId>
+ <artifactId>sesame-rio-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.openrdf.sesame</groupId>
+ <artifactId>sesame-rio-rdfxml</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/embedded/InfinispanEmbeddedCacheManager.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/embedded/InfinispanEmbeddedCacheManager.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/embedded/InfinispanEmbeddedCacheManager.java
new file mode 100644
index 0000000..35c2018
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/embedded/InfinispanEmbeddedCacheManager.java
@@ -0,0 +1,505 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.marmotta.kiwi.embedded;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.marmotta.kiwi.caching.CacheManager;
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+import org.apache.marmotta.kiwi.externalizer.*;
+import org.apache.marmotta.kiwi.persistence.KiWiPersistence;
+import org.infinispan.Cache;
+import org.infinispan.commons.CacheException;
+import org.infinispan.commons.marshall.AdvancedExternalizer;
+import org.infinispan.configuration.cache.CacheMode;
+import org.infinispan.configuration.cache.Configuration;
+import org.infinispan.configuration.cache.ConfigurationBuilder;
+import org.infinispan.configuration.global.GlobalConfiguration;
+import org.infinispan.configuration.global.GlobalConfigurationBuilder;
+import org.infinispan.context.Flag;
+import org.infinispan.distribution.ch.SyncConsistentHashFactory;
+import org.infinispan.eviction.EvictionStrategy;
+import org.infinispan.lifecycle.ComponentStatus;
+import org.infinispan.manager.DefaultCacheManager;
+import org.infinispan.manager.EmbeddedCacheManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.marmotta.kiwi.config.CacheMode.DISTRIBUTED;
+import static org.apache.marmotta.kiwi.config.CacheMode.REPLICATED;
+
+/**
+ * A class for managing the different caches that are used by the triple store.
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class InfinispanEmbeddedCacheManager implements CacheManager {
+
+ private static Logger log = LoggerFactory.getLogger(InfinispanEmbeddedCacheManager.class);
+
+ public static final String NODE_CACHE = "node-cache";
+ public static final String TRIPLE_CACHE = "triple-cache";
+ public static final String URI_CACHE = "uri-cache";
+ public static final String BNODE_CACHE = "bnode-cache";
+ public static final String LITERAL_CACHE = "literal-cache";
+ public static final String NAMESPACE_URI_CACHE = "namespace-uri-cache";
+ public static final String NAMESPACE_PREFIX_CACHE = "namespace-prefix-cache";
+ public static final String LOADER_CACHE = "loader-cache";
+ public static final String REGISTRY_CACHE = "registry-cache";
+
+ private EmbeddedCacheManager cacheManager;
+
+ private GlobalConfiguration globalConfiguration;
+
+ // default configuration: distributed cache, 100000 entries, 300 seconds expiration, 60 seconds idle
+ private Configuration defaultConfiguration;
+
+ private boolean clustered, embedded;
+
+ private KiWiConfiguration kiWiConfiguration;
+
+ private KiWiPersistence persistence;
+
+
+ private Cache nodeCache, tripleCache, uriCache, literalCache, bnodeCache, nsPrefixCache, nsUriCache, loaderCache, registryCache;
+
+
+ /**
+ * Create a new cache manager with its own automatically created Infinispan instance.
+ *
+ * @param config
+ */
+ public InfinispanEmbeddedCacheManager(KiWiConfiguration config) {
+
+ this.clustered = config.isClustered();
+ this.kiWiConfiguration = config;
+
+ if(clustered && (config.getCacheMode() == DISTRIBUTED || config.getCacheMode() == REPLICATED)) {
+ try {
+ String jgroupsXml = IOUtils.toString(InfinispanEmbeddedCacheManager.class.getResourceAsStream("/jgroups-kiwi.xml"));
+
+ jgroupsXml = jgroupsXml.replaceAll("mcast_addr=\"[0-9.]+\"", String.format("mcast_addr=\"%s\"", config.getClusterAddress()));
+ jgroupsXml = jgroupsXml.replaceAll("mcast_port=\"[0-9]+\"", String.format("mcast_port=\"%d\"", config.getClusterPort()));
+
+
+ globalConfiguration = new GlobalConfigurationBuilder()
+ .classLoader(InfinispanEmbeddedCacheManager.class.getClassLoader())
+ .transport()
+ .defaultTransport()
+ .clusterName(config.getClusterName())
+ .machineId("instance-" + config.getDatacenterId())
+ .addProperty("configurationXml", jgroupsXml)
+ .globalJmxStatistics()
+ .jmxDomain("org.apache.marmotta.kiwi")
+ .allowDuplicateDomains(true)
+ .serialization()
+ .addAdvancedExternalizer(getExternalizers())
+ .build();
+ } catch (IOException ex) {
+ log.warn("error loading JGroups configuration from archive: {}", ex.getMessage());
+ log.warn("some configuration options will not be available");
+
+ globalConfiguration = new GlobalConfigurationBuilder()
+ .classLoader(InfinispanEmbeddedCacheManager.class.getClassLoader())
+ .transport()
+ .defaultTransport()
+ .clusterName(config.getClusterName())
+ .machineId("instance-" + config.getDatacenterId())
+ .addProperty("configurationFile", "jgroups-kiwi.xml")
+ .globalJmxStatistics()
+ .jmxDomain("org.apache.marmotta.kiwi")
+ .allowDuplicateDomains(true)
+ .serialization()
+ .addAdvancedExternalizer(getExternalizers())
+ .build();
+
+ }
+
+ if(config.getCacheMode() == DISTRIBUTED) {
+ defaultConfiguration = new ConfigurationBuilder()
+ .clustering()
+ .cacheMode(CacheMode.DIST_ASYNC)
+ .async()
+ .asyncMarshalling()
+ .l1()
+ .lifespan(5, TimeUnit.MINUTES)
+ .hash()
+ .numOwners(2)
+ .numSegments(40)
+ .consistentHashFactory(new SyncConsistentHashFactory())
+ .stateTransfer()
+ .fetchInMemoryState(false)
+ .eviction()
+ .strategy(EvictionStrategy.LIRS)
+ .maxEntries(100000)
+ .expiration()
+ .lifespan(30, TimeUnit.MINUTES)
+ .maxIdle(10, TimeUnit.MINUTES)
+ .build();
+ } else {
+ defaultConfiguration = new ConfigurationBuilder()
+ .clustering()
+ .cacheMode(CacheMode.REPL_ASYNC)
+ .async()
+ .asyncMarshalling()
+ .stateTransfer()
+ .fetchInMemoryState(false)
+ .eviction()
+ .strategy(EvictionStrategy.LIRS)
+ .maxEntries(100000)
+ .expiration()
+ .lifespan(30, TimeUnit.MINUTES)
+ .maxIdle(10, TimeUnit.MINUTES)
+ .build();
+ }
+ } else {
+ globalConfiguration = new GlobalConfigurationBuilder()
+ .classLoader(InfinispanEmbeddedCacheManager.class.getClassLoader())
+ .globalJmxStatistics()
+ .jmxDomain("org.apache.marmotta.kiwi")
+ .allowDuplicateDomains(true)
+ .build();
+
+ defaultConfiguration = new ConfigurationBuilder()
+ .clustering()
+ .cacheMode(CacheMode.LOCAL)
+ .eviction()
+ .strategy(EvictionStrategy.LIRS)
+ .maxEntries(100000)
+ .expiration()
+ .lifespan(5, TimeUnit.MINUTES)
+ .maxIdle(1, TimeUnit.MINUTES)
+ .build();
+
+ }
+
+
+ cacheManager = new DefaultCacheManager(globalConfiguration, defaultConfiguration, true);
+
+ log.info("initialised Infinispan cache manager ({})", globalConfiguration.isClustered() ? "cluster name: "+globalConfiguration.transport().clusterName() : "single host");
+
+ this.embedded = true;
+ }
+
+
+ private AdvancedExternalizer[] getExternalizers() {
+ return new AdvancedExternalizer[] {
+ new TripleExternalizer(persistence),
+ new UriExternalizer(),
+ new BNodeExternalizer(),
+ new StringLiteralExternalizer(),
+ new DateLiteralExternalizer(),
+ new BooleanLiteralExternalizer(),
+ new IntLiteralExternalizer(),
+ new DoubleLiteralExternalizer()
+ };
+ }
+
+ /**
+ * Return the node id -> node cache from the cache manager. This cache is heavily used to lookup
+ * nodes when querying or loading triples and should therefore have a decent size (default 500.000 elements).
+ *
+ * @return an EHCache Cache instance containing the node id -> node mappings
+ */
+ public Cache getNodeCache() {
+ if(nodeCache == null) {
+ Configuration nodeConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
+ .eviction()
+ .maxEntries(1000000)
+ .expiration()
+ .lifespan(60, TimeUnit.MINUTES)
+ .maxIdle(30, TimeUnit.MINUTES)
+ .build();
+ cacheManager.defineConfiguration(NODE_CACHE, nodeConfiguration);
+
+ nodeCache = cacheManager.getCache(NODE_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
+ }
+
+ return nodeCache;
+ }
+
+ /**
+ * Return the triple id -> triple cache from the cache manager. This cache is used for speeding up the
+ * construction of query results.
+ *
+ * @return
+ */
+ public Cache getTripleCache() {
+ if(tripleCache == null) {
+ Configuration tripleConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
+ .clustering()
+ .cacheMode(CacheMode.LOCAL)
+ .eviction()
+ .maxEntries(kiWiConfiguration.getTripleCacheSize())
+ .expiration()
+ .lifespan(60, TimeUnit.MINUTES)
+ .maxIdle(30, TimeUnit.MINUTES)
+ .build();
+ cacheManager.defineConfiguration(TRIPLE_CACHE, tripleConfiguration);
+
+ tripleCache = cacheManager.getCache(TRIPLE_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
+ }
+ return tripleCache;
+ }
+
+
+ /**
+ * Return the uri -> KiWiUriResource cache from the cache manager. This cache is used when constructing new
+ * KiWiUriResources to avoid a database lookup.
+ *
+ * @return
+ */
+ public Cache getUriCache() {
+ if(uriCache == null) {
+ Configuration uriConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
+ .eviction()
+ .maxEntries(kiWiConfiguration.getUriCacheSize())
+ .build();
+ cacheManager.defineConfiguration(URI_CACHE, uriConfiguration);
+
+ uriCache = cacheManager.getCache(URI_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
+ }
+ return uriCache;
+ }
+
+
+ /**
+ * Return the anonId -> KiWiAnonResource cache from the cache manager. This cache is used when constructing new
+ * KiWiAnonResources to avoid a database lookup.
+ *
+ * @return
+ */
+ public Cache getBNodeCache() {
+ if(bnodeCache == null) {
+ Configuration bnodeConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
+ .eviction()
+ .maxEntries(kiWiConfiguration.getBNodeCacheSize())
+ .build();
+ cacheManager.defineConfiguration(BNODE_CACHE, bnodeConfiguration);
+
+ bnodeCache = cacheManager.getCache(BNODE_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
+ }
+ return bnodeCache;
+ }
+
+ /**
+ * Return the literal cache key -> KiWiLiteral cache from the cache manager. This cache is used when constructing new
+ * KiWiLiterals to avoid a database lookup.
+ *
+ * @see org.apache.marmotta.commons.sesame.model.LiteralCommons#createCacheKey(String, java.util.Locale, String)
+ * @return
+ */
+ public Cache getLiteralCache() {
+ if(literalCache == null) {
+ Configuration literalConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
+ .eviction()
+ .maxEntries(kiWiConfiguration.getLiteralCacheSize())
+ .build();
+ cacheManager.defineConfiguration(LITERAL_CACHE, literalConfiguration);
+
+ literalCache = cacheManager.getCache(LITERAL_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
+ }
+ return literalCache;
+ }
+
+
+ /**
+ * Return the URI -> namespace cache from the cache manager. Used for looking up namespaces
+ * @return
+ */
+ public Cache getNamespaceUriCache() {
+ if(nsUriCache == null) {
+ if(clustered) {
+ Configuration nsuriConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
+ .clustering()
+ .cacheMode(CacheMode.REPL_ASYNC)
+ .eviction()
+ .maxEntries(kiWiConfiguration.getNamespaceCacheSize())
+ .expiration()
+ .lifespan(1, TimeUnit.DAYS)
+ .build();
+ cacheManager.defineConfiguration(NAMESPACE_URI_CACHE, nsuriConfiguration);
+ } else {
+ Configuration nsuriConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
+ .eviction()
+ .maxEntries(kiWiConfiguration.getNamespaceCacheSize())
+ .expiration()
+ .lifespan(1, TimeUnit.HOURS)
+ .build();
+ cacheManager.defineConfiguration(NAMESPACE_URI_CACHE, nsuriConfiguration);
+ }
+
+ nsUriCache = cacheManager.getCache(NAMESPACE_URI_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
+ }
+ return nsUriCache;
+ }
+
+ /**
+ * Return the prefix -> namespace cache from the cache manager. Used for looking up namespaces
+ * @return
+ */
+ public Cache getNamespacePrefixCache() {
+ if(nsPrefixCache == null) {
+ if(clustered) {
+ Configuration nsprefixConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
+ .clustering()
+ .cacheMode(CacheMode.REPL_ASYNC)
+ .eviction()
+ .maxEntries(kiWiConfiguration.getNamespaceCacheSize())
+ .expiration()
+ .lifespan(1, TimeUnit.DAYS)
+ .build();
+ cacheManager.defineConfiguration(NAMESPACE_PREFIX_CACHE, nsprefixConfiguration);
+
+ } else {
+ Configuration nsprefixConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
+ .eviction()
+ .maxEntries(kiWiConfiguration.getNamespaceCacheSize())
+ .expiration()
+ .lifespan(1, TimeUnit.HOURS)
+ .build();
+ cacheManager.defineConfiguration(NAMESPACE_PREFIX_CACHE, nsprefixConfiguration);
+
+ }
+ nsPrefixCache = cacheManager.getCache(NAMESPACE_PREFIX_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
+ }
+ return nsPrefixCache;
+ }
+
+
+
+
+ /**
+ * Create and return the cache used by the CacheTripleRegistry. This is an unlimited synchronous replicated
+ * cache and should be used with care.
+ * @return
+ */
+ public Cache getRegistryCache() {
+ if(registryCache == null) {
+ if(clustered) {
+ Configuration registryConfiguration = new ConfigurationBuilder()
+ .clustering()
+ .cacheMode(CacheMode.REPL_SYNC)
+ .sync()
+ .replTimeout(15, TimeUnit.SECONDS)
+ .eviction()
+ .strategy(EvictionStrategy.NONE)
+ .build();
+ cacheManager.defineConfiguration(REGISTRY_CACHE, registryConfiguration);
+ } else {
+ Configuration registryConfiguration = new ConfigurationBuilder()
+ .clustering()
+ .cacheMode(CacheMode.LOCAL)
+ .eviction()
+ .strategy(EvictionStrategy.NONE)
+ .build();
+ cacheManager.defineConfiguration(REGISTRY_CACHE, registryConfiguration);
+ }
+
+ registryCache = cacheManager.getCache(REGISTRY_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
+ }
+ return registryCache;
+ }
+
+ /**
+ * Get the cache with the given name from the cache manager. Can be used to request additional
+ * caches from the cache manager that are not covered by explicit methods.
+ *
+ * @param name
+ * @return
+ */
+ public synchronized Cache getCacheByName(String name) {
+ if(!cacheManager.cacheExists(name)) {
+ cacheManager.defineConfiguration(name, new ConfigurationBuilder().read(defaultConfiguration).build());
+ }
+ return cacheManager.getCache(name).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
+
+ }
+
+ /**
+ * Return the Infinispan cache manager used by the caching infrastructure.
+ *
+ * @return
+ */
+ public EmbeddedCacheManager getCacheManager() {
+ return cacheManager;
+ }
+
+ /**
+ * Return the global cache manager configuration used by the caching infrastructure.
+ * @return
+ */
+ public GlobalConfiguration getGlobalConfiguration() {
+ return globalConfiguration;
+ }
+
+ /**
+ * Return the default cache configuration used by the caching infrastructure.
+ * @return
+ */
+ public Configuration getDefaultConfiguration() {
+ return defaultConfiguration;
+ }
+
+ /**
+ * Clear all caches managed by this cache manager.
+ */
+ public void clear() {
+ Set<String> set = cacheManager.getCacheNames();
+ Iterator<String> iterator = set.iterator();
+ while(iterator.hasNext()){
+ String cacheName = iterator.next();
+ Cache<String,Object> cache = cacheManager.getCache(cacheName);
+ cache.clear();
+ }
+
+ nodeCache = null;
+ tripleCache = null;
+ uriCache = null;
+ literalCache = null;
+ bnodeCache = null;
+ nsPrefixCache = null;
+ nsUriCache = null;
+ loaderCache = null;
+ registryCache = null;
+ }
+
+ /**
+ * Shutdown this cache manager instance. Will shutdown the underlying EHCache cache manager.
+ */
+ public void shutdown() {
+ try {
+ if(embedded && cacheManager.getStatus() == ComponentStatus.RUNNING) {
+ log.warn("shutting down cache manager ...");
+// if(cacheManager.getTransport() != null) {
+// log.info("... shutting down transport ...");
+// cacheManager.getTransport().stop();
+// }
+ log.info("... shutting down main component ...");
+ cacheManager.stop();
+ log.info("... done!");
+ }
+ } catch (CacheException ex) {
+ log.warn("error shutting down cache: {}", ex.getMessage());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/embedded/InfinispanEmbeddedCacheManagerFactory.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/embedded/InfinispanEmbeddedCacheManagerFactory.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/embedded/InfinispanEmbeddedCacheManagerFactory.java
new file mode 100644
index 0000000..13ffcfd
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/embedded/InfinispanEmbeddedCacheManagerFactory.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.embedded;
+
+import org.apache.marmotta.kiwi.caching.CacheManager;
+import org.apache.marmotta.kiwi.caching.CacheManagerFactory;
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class InfinispanEmbeddedCacheManagerFactory implements CacheManagerFactory {
+
+ public InfinispanEmbeddedCacheManagerFactory() {
+ }
+
+ /**
+ * Create a new cache manager instance using the KiWiConfiguration passed as argument.
+ *
+ * @param configuration KiWi configuration used by the underlying triple store
+ * @return a new cache manager instance for this triple store
+ */
+ @Override
+ public CacheManager createCacheManager(KiWiConfiguration configuration) {
+ return new InfinispanEmbeddedCacheManager(configuration);
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/BNodeExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/BNodeExternalizer.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/BNodeExternalizer.java
new file mode 100644
index 0000000..6fd89a5
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/BNodeExternalizer.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.externalizer;
+
+import org.apache.marmotta.kiwi.model.rdf.KiWiAnonResource;
+import org.infinispan.commons.marshall.AdvancedExternalizer;
+import org.infinispan.commons.util.Util;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Date;
+import java.util.Set;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class BNodeExternalizer implements AdvancedExternalizer<KiWiAnonResource> {
+
+
+ @Override
+ public Set<Class<? extends KiWiAnonResource>> getTypeClasses() {
+ return Util.<Class<? extends KiWiAnonResource>>asSet(KiWiAnonResource.class);
+ }
+
+ @Override
+ public Integer getId() {
+ return ExternalizerIds.BNODE;
+ }
+
+ @Override
+ public void writeObject(ObjectOutput output, KiWiAnonResource object) throws IOException {
+ output.writeLong(object.getId());
+ output.writeInt(object.stringValue().length());
+ output.writeChars(object.stringValue());
+ output.writeLong(object.getCreated().getTime());
+ }
+
+ @Override
+ public KiWiAnonResource readObject(ObjectInput input) throws IOException, ClassNotFoundException {
+ long id = input.readLong();
+ int len = input.readInt();
+
+ char[] anonId = new char[len];
+ for(int i=0; i<len; i++) {
+ anonId[i] = input.readChar();
+ }
+
+ Date created = new Date(input.readLong());
+
+ KiWiAnonResource r = new KiWiAnonResource(new String(anonId),created);
+ r.setId(id);
+
+ return r;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/BooleanLiteralExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/BooleanLiteralExternalizer.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/BooleanLiteralExternalizer.java
new file mode 100644
index 0000000..ffb45d3
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/BooleanLiteralExternalizer.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.externalizer;
+
+import org.apache.marmotta.kiwi.model.rdf.KiWiBooleanLiteral;
+import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
+import org.infinispan.commons.marshall.AdvancedExternalizer;
+import org.infinispan.commons.util.Util;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Date;
+import java.util.Set;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class BooleanLiteralExternalizer implements AdvancedExternalizer<KiWiBooleanLiteral> {
+
+ @Override
+ public Set<Class<? extends KiWiBooleanLiteral>> getTypeClasses() {
+ return Util.<Class<? extends KiWiBooleanLiteral>>asSet(KiWiBooleanLiteral.class);
+ }
+
+ @Override
+ public Integer getId() {
+ return ExternalizerIds.BOOL_LITERAL;
+ }
+
+ @Override
+ public void writeObject(ObjectOutput output, KiWiBooleanLiteral object) throws IOException {
+ output.writeLong(object.getId());
+ output.writeBoolean(object.booleanValue());
+ output.writeObject(object.getDatatype());
+
+ output.writeLong(object.getCreated().getTime());
+
+ }
+
+ @Override
+ public KiWiBooleanLiteral readObject(ObjectInput input) throws IOException, ClassNotFoundException {
+ long id = input.readLong();
+ boolean content = input.readBoolean();
+
+ KiWiUriResource dtype = (KiWiUriResource) input.readObject();
+
+ Date created = new Date(input.readLong());
+
+ KiWiBooleanLiteral r = new KiWiBooleanLiteral(content, dtype, created);
+ r.setId(id);
+
+ return r;
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/DateLiteralExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/DateLiteralExternalizer.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/DateLiteralExternalizer.java
new file mode 100644
index 0000000..afe83a4
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/DateLiteralExternalizer.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.externalizer;
+
+import org.apache.marmotta.kiwi.model.rdf.KiWiDateLiteral;
+import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
+import org.infinispan.commons.marshall.AdvancedExternalizer;
+import org.infinispan.commons.util.Util;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Date;
+import java.util.Set;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class DateLiteralExternalizer implements AdvancedExternalizer<KiWiDateLiteral> {
+
+ @Override
+ public Set<Class<? extends KiWiDateLiteral>> getTypeClasses() {
+ return Util.<Class<? extends KiWiDateLiteral>>asSet(KiWiDateLiteral.class);
+ }
+
+ @Override
+ public Integer getId() {
+ return ExternalizerIds.DATE_LITERAL;
+ }
+
+ @Override
+ public void writeObject(ObjectOutput output, KiWiDateLiteral object) throws IOException {
+ output.writeLong(object.getId());
+ output.writeLong(object.getDateContent().getTime());
+ output.writeObject(object.getDatatype());
+
+ output.writeLong(object.getCreated().getTime());
+
+ }
+
+ @Override
+ public KiWiDateLiteral readObject(ObjectInput input) throws IOException, ClassNotFoundException {
+ long id = input.readLong();
+ Date content = new Date(input.readLong());
+
+ KiWiUriResource dtype = (KiWiUriResource) input.readObject();
+
+ Date created = new Date(input.readLong());
+
+ KiWiDateLiteral r = new KiWiDateLiteral(content, dtype, created);
+ r.setId(id);
+
+ return r;
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/DoubleLiteralExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/DoubleLiteralExternalizer.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/DoubleLiteralExternalizer.java
new file mode 100644
index 0000000..d153998
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/DoubleLiteralExternalizer.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.externalizer;
+
+import org.apache.marmotta.kiwi.model.rdf.KiWiDoubleLiteral;
+import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
+import org.infinispan.commons.marshall.AdvancedExternalizer;
+import org.infinispan.commons.util.Util;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Date;
+import java.util.Set;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class DoubleLiteralExternalizer implements AdvancedExternalizer<KiWiDoubleLiteral> {
+
+ @Override
+ public Set<Class<? extends KiWiDoubleLiteral>> getTypeClasses() {
+ return Util.<Class<? extends KiWiDoubleLiteral>>asSet(KiWiDoubleLiteral.class);
+ }
+
+ @Override
+ public Integer getId() {
+ return ExternalizerIds.DOUBLE_LITERAL;
+ }
+
+ @Override
+ public void writeObject(ObjectOutput output, KiWiDoubleLiteral object) throws IOException {
+ output.writeLong(object.getId());
+ output.writeDouble(object.getDoubleContent());
+ output.writeObject(object.getDatatype());
+
+ output.writeLong(object.getCreated().getTime());
+
+ }
+
+ @Override
+ public KiWiDoubleLiteral readObject(ObjectInput input) throws IOException, ClassNotFoundException {
+ long id = input.readLong();
+ double content = input.readDouble();
+
+ KiWiUriResource dtype = (KiWiUriResource) input.readObject();
+
+ Date created = new Date(input.readLong());
+
+ KiWiDoubleLiteral r = new KiWiDoubleLiteral(content, dtype, created);
+ r.setId(id);
+
+ return r;
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/ExternalizerIds.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/ExternalizerIds.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/ExternalizerIds.java
new file mode 100644
index 0000000..880303d
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/ExternalizerIds.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.externalizer;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class ExternalizerIds {
+
+ public static final int URI = 17;
+
+ public static final int BNODE = 23;
+
+ public static final int STRING_LITERAL = 19;
+
+ public static final int INT_LITERAL = 39;
+
+ public static final int DOUBLE_LITERAL = 37;
+
+ public static final int DATE_LITERAL = 29;
+
+ public static final int BOOL_LITERAL = 31;
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/IntLiteralExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/IntLiteralExternalizer.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/IntLiteralExternalizer.java
new file mode 100644
index 0000000..da71798
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/IntLiteralExternalizer.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.externalizer;
+
+import org.apache.marmotta.kiwi.model.rdf.KiWiIntLiteral;
+import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
+import org.infinispan.commons.marshall.AdvancedExternalizer;
+import org.infinispan.commons.util.Util;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Date;
+import java.util.Set;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class IntLiteralExternalizer implements AdvancedExternalizer<KiWiIntLiteral> {
+
+ @Override
+ public Set<Class<? extends KiWiIntLiteral>> getTypeClasses() {
+ return Util.<Class<? extends KiWiIntLiteral>>asSet(KiWiIntLiteral.class);
+ }
+
+ @Override
+ public Integer getId() {
+ return ExternalizerIds.INT_LITERAL;
+ }
+
+ @Override
+ public void writeObject(ObjectOutput output, KiWiIntLiteral object) throws IOException {
+ output.writeLong(object.getId());
+ output.writeLong(object.getIntContent());
+ output.writeObject(object.getDatatype());
+
+ output.writeLong(object.getCreated().getTime());
+
+ }
+
+ @Override
+ public KiWiIntLiteral readObject(ObjectInput input) throws IOException, ClassNotFoundException {
+ long id = input.readLong();
+ long content = input.readLong();
+
+ KiWiUriResource dtype = (KiWiUriResource) input.readObject();
+
+ Date created = new Date(input.readLong());
+
+ KiWiIntLiteral r = new KiWiIntLiteral(content, dtype, created);
+ r.setId(id);
+
+ return r;
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/StringLiteralExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/StringLiteralExternalizer.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/StringLiteralExternalizer.java
new file mode 100644
index 0000000..4e47459
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/StringLiteralExternalizer.java
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.externalizer;
+
+import org.apache.marmotta.kiwi.model.rdf.KiWiStringLiteral;
+import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
+import org.infinispan.commons.marshall.AdvancedExternalizer;
+import org.infinispan.commons.util.Util;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Date;
+import java.util.Locale;
+import java.util.Set;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class StringLiteralExternalizer implements AdvancedExternalizer<KiWiStringLiteral> {
+
+ @Override
+ public Set<Class<? extends KiWiStringLiteral>> getTypeClasses() {
+ return Util.<Class<? extends KiWiStringLiteral>>asSet(KiWiStringLiteral.class);
+ }
+
+ @Override
+ public Integer getId() {
+ return ExternalizerIds.STRING_LITERAL;
+ }
+
+ @Override
+ public void writeObject(ObjectOutput output, KiWiStringLiteral object) throws IOException {
+ output.writeLong(object.getId());
+ output.writeInt(object.getContent().length());
+ output.writeChars(object.getContent());
+ if(object.getLanguage() != null) {
+ output.writeInt(object.getLanguage().length());
+ output.writeChars(object.getLanguage());
+ } else {
+ output.writeInt(0);
+ }
+
+ output.writeObject(object.getDatatype());
+
+ output.writeLong(object.getCreated().getTime());
+
+ }
+
+ @Override
+ public KiWiStringLiteral readObject(ObjectInput input) throws IOException, ClassNotFoundException {
+ long id = input.readLong();
+ int clen = input.readInt();
+ char[] content = new char[clen];
+ for(int i=0; i<clen; i++) {
+ content[i]=input.readChar();
+ }
+
+ int llen = input.readInt();
+ String lang = null;
+ if(llen > 0) {
+ char[] lb = new char[llen];
+ for(int i=0; i<llen; i++) {
+ lb[i] = input.readChar();
+ }
+ lang = new String(lb);
+ }
+
+ KiWiUriResource dtype = (KiWiUriResource) input.readObject();
+
+ Date created = new Date(input.readLong());
+
+ KiWiStringLiteral r = new KiWiStringLiteral(new String(content), lang != null ? Locale.forLanguageTag(lang) : null, dtype, created);
+ r.setId(id);
+
+ return r;
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/TripleExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/TripleExternalizer.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/TripleExternalizer.java
new file mode 100644
index 0000000..e4c584c
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/TripleExternalizer.java
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.externalizer;
+
+import org.apache.marmotta.kiwi.model.rdf.KiWiNode;
+import org.apache.marmotta.kiwi.model.rdf.KiWiResource;
+import org.apache.marmotta.kiwi.model.rdf.KiWiTriple;
+import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
+import org.apache.marmotta.kiwi.persistence.KiWiConnection;
+import org.apache.marmotta.kiwi.persistence.KiWiPersistence;
+import org.infinispan.commons.marshall.AdvancedExternalizer;
+import org.infinispan.commons.util.Util;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.sql.SQLException;
+import java.util.Date;
+import java.util.Set;
+
+/**
+ * An externalizer for Infinispan allowing to more efficiently transport triples by only serializing the node
+ * IDs instead of the whole nodes.
+ */
+public class TripleExternalizer implements AdvancedExternalizer<KiWiTriple> {
+
+ private static Logger log = LoggerFactory.getLogger(TripleExternalizer.class);
+
+ private KiWiPersistence persistence;
+
+ public TripleExternalizer(KiWiPersistence persistence) {
+ this.persistence = persistence;
+ }
+
+ @Override
+ public Set<Class<? extends KiWiTriple>> getTypeClasses() {
+ return Util.<Class<? extends KiWiTriple>>asSet(KiWiTriple.class);
+ }
+
+ @Override
+ public Integer getId() {
+ return 13;
+ }
+
+ @Override
+ public void writeObject(ObjectOutput output, KiWiTriple object) throws IOException {
+ output.writeLong(object.getId());
+ output.writeLong(object.getSubject().getId());
+ output.writeLong(object.getPredicate().getId());
+ output.writeLong(object.getObject().getId());
+ output.writeLong(object.getContext() != null ? object.getContext().getId() : -1L);
+ output.writeLong(object.getCreator() != null ? object.getCreator().getId() : -1L);
+ output.writeBoolean(object.isDeleted());
+ output.writeBoolean(object.isInferred());
+ output.writeBoolean(object.isNewTriple());
+ output.writeLong(object.getCreated().getTime());
+ if(object.getDeletedAt() != null) {
+ output.writeLong(object.getDeletedAt().getTime());
+ } else {
+ output.writeLong(0);
+ }
+ }
+
+ @Override
+ public KiWiTriple readObject(ObjectInput input) throws IOException, ClassNotFoundException {
+ try {
+ KiWiConnection con = persistence.getConnection();
+ try {
+ KiWiTriple result = new KiWiTriple();
+ result.setId(input.readLong());
+
+ long[] nodeIds = new long[5];
+ for(int i=0; i<5; i++) {
+ nodeIds[0] = input.readLong();
+ }
+ KiWiNode[] nodes = con.loadNodesByIds(nodeIds);
+
+ result.setSubject((KiWiResource) nodes[0]);
+ result.setPredicate((KiWiUriResource) nodes[1]);
+ result.setObject(nodes[2]);
+
+ if(nodes[3] != null) {
+ result.setContext((KiWiResource) nodes[3]);
+ }
+ if(nodes[4] != null) {
+ result.setCreator((KiWiResource) nodes[4]);
+ }
+
+ result.setDeleted(input.readBoolean());
+ result.setInferred(input.readBoolean());
+ result.setNewTriple(input.readBoolean());
+
+ result.setCreated(new Date(input.readLong()));
+
+ long deletedAt = input.readLong();
+ if(deletedAt > 0) {
+ result.setDeletedAt(new Date(deletedAt));
+ }
+
+
+ return result;
+ } finally {
+ con.commit();
+ con.close();
+ }
+ } catch (SQLException ex) {
+ throw new IOException(ex);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/UriExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/UriExternalizer.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/UriExternalizer.java
new file mode 100644
index 0000000..0daee45
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/UriExternalizer.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.externalizer;
+
+import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
+import org.infinispan.commons.marshall.AdvancedExternalizer;
+import org.infinispan.commons.util.Util;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Date;
+import java.util.Set;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class UriExternalizer implements AdvancedExternalizer<KiWiUriResource> {
+
+ @Override
+ public Set<Class<? extends KiWiUriResource>> getTypeClasses() {
+ return Util.<Class<? extends KiWiUriResource>>asSet(KiWiUriResource.class);
+ }
+
+ @Override
+ public Integer getId() {
+ return ExternalizerIds.URI;
+ }
+
+ @Override
+ public void writeObject(ObjectOutput output, KiWiUriResource object) throws IOException {
+ output.writeLong(object.getId());
+ output.writeInt(object.stringValue().length());
+ output.writeChars(object.stringValue());
+ output.writeLong(object.getCreated().getTime());
+ }
+
+ @Override
+ public KiWiUriResource readObject(ObjectInput input) throws IOException, ClassNotFoundException {
+ long id = input.readLong();
+ int len = input.readInt();
+
+ char[] uri = new char[len];
+ for(int i=0; i<len; i++) {
+ uri[i] = input.readChar();
+ }
+
+ Date created = new Date(input.readLong());
+
+ KiWiUriResource r = new KiWiUriResource(new String(uri),created);
+ r.setId(id);
+
+ return r;
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/remote/InfinispanRemoteCacheManager.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/remote/InfinispanRemoteCacheManager.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/remote/InfinispanRemoteCacheManager.java
new file mode 100644
index 0000000..c40feb8
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/remote/InfinispanRemoteCacheManager.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.remote;
+
+import org.apache.marmotta.kiwi.caching.CacheManager;
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+
+/**
+ * Implementation of an Infinispan cache manager with a remote (client-server) cache.
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class InfinispanRemoteCacheManager implements CacheManager {
+
+ private KiWiConfiguration configuration;
+
+ public InfinispanRemoteCacheManager(KiWiConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
+
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/remote/InfinispanRemoteCacheManagerFactory.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/remote/InfinispanRemoteCacheManagerFactory.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/remote/InfinispanRemoteCacheManagerFactory.java
new file mode 100644
index 0000000..a0152d1
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/remote/InfinispanRemoteCacheManagerFactory.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.remote;
+
+import org.apache.marmotta.kiwi.caching.CacheManager;
+import org.apache.marmotta.kiwi.caching.CacheManagerFactory;
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class InfinispanRemoteCacheManagerFactory implements CacheManagerFactory {
+
+ public InfinispanRemoteCacheManagerFactory() {
+ }
+
+ /**
+ * Create a new cache manager instance using the KiWiConfiguration passed as argument.
+ *
+ * @param configuration KiWi configuration used by the underlying triple store
+ * @return a new cache manager instance for this triple store
+ */
+ @Override
+ public CacheManager createCacheManager(KiWiConfiguration configuration) {
+ return new InfinispanRemoteCacheManager(configuration);
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-caching-infinispan/src/main/resources/META-INF/services/org.apache.marmotta.kiwi.caching.CacheManagerFactory
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/resources/META-INF/services/org.apache.marmotta.kiwi.caching.CacheManagerFactory b/libraries/kiwi/kiwi-caching-infinispan/src/main/resources/META-INF/services/org.apache.marmotta.kiwi.caching.CacheManagerFactory
new file mode 100644
index 0000000..4fd2bec
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/resources/META-INF/services/org.apache.marmotta.kiwi.caching.CacheManagerFactory
@@ -0,0 +1,2 @@
+org.apache.marmotta.kiwi.embedded.InfinispanEmbeddedCacheManagerFactory
+org.apache.marmotta.kiwi.remote.InfinispanRemoteCacheManagerFactory
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/externalizer/ExternalizerTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/externalizer/ExternalizerTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/externalizer/ExternalizerTest.java
new file mode 100644
index 0000000..fe7b701
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/externalizer/ExternalizerTest.java
@@ -0,0 +1,187 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.test.externalizer;
+
+import org.apache.commons.lang3.RandomStringUtils;
+import org.apache.marmotta.kiwi.model.rdf.KiWiAnonResource;
+import org.apache.marmotta.kiwi.model.rdf.KiWiIntLiteral;
+import org.apache.marmotta.kiwi.model.rdf.KiWiStringLiteral;
+import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
+import org.apache.marmotta.kiwi.test.TestValueFactory;
+import org.infinispan.commons.marshall.AdvancedExternalizer;
+import org.infinispan.commons.marshall.StreamingMarshaller;
+import org.infinispan.configuration.cache.CacheMode;
+import org.infinispan.configuration.cache.Configuration;
+import org.infinispan.configuration.cache.ConfigurationBuilder;
+import org.infinispan.configuration.global.GlobalConfiguration;
+import org.infinispan.configuration.global.GlobalConfigurationBuilder;
+import org.infinispan.manager.DefaultCacheManager;
+import org.infinispan.manager.EmbeddedCacheManager;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.openrdf.model.Value;
+import org.openrdf.model.ValueFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.*;
+import java.util.Random;
+
+/**
+ * Test the different externalizer implementations we provide for Infinispan
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class ExternalizerTest {
+
+ private static ValueFactory valueFactory = new TestValueFactory();
+
+ private static Random rnd = new Random();
+
+ private static Logger log = LoggerFactory.getLogger(ExternalizerTest.class);
+
+ private static StreamingMarshaller marshaller;
+
+
+ @BeforeClass
+ public static void setup() {
+ AdvancedExternalizer[] externalizers = new AdvancedExternalizer[] {
+ new UriExternalizer(),
+ new BNodeExternalizer(),
+ new StringLiteralExternalizer(),
+ new DateLiteralExternalizer(),
+ new BooleanLiteralExternalizer(),
+ new IntLiteralExternalizer(),
+ new DoubleLiteralExternalizer()
+ };
+
+
+ GlobalConfiguration globalConfiguration = new GlobalConfigurationBuilder()
+ .transport()
+ .defaultTransport()
+ .serialization()
+ .addAdvancedExternalizer(externalizers)
+ .build();
+
+ Configuration defaultConfiguration = new ConfigurationBuilder()
+ .clustering()
+ .cacheMode(CacheMode.DIST_ASYNC)
+ .build();
+
+ EmbeddedCacheManager cacheManager = new DefaultCacheManager(globalConfiguration, defaultConfiguration, true);
+
+ marshaller = cacheManager.getCache().getAdvancedCache().getComponentRegistry().getCacheMarshaller();
+
+ }
+
+
+ @Test
+ public void testUriResource() throws Exception {
+ marshall((KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8)), new UriExternalizer());
+ }
+
+ @Test
+ public void testBNode() throws Exception {
+ marshall((KiWiAnonResource) valueFactory.createBNode(), new BNodeExternalizer());
+ }
+
+ @Test
+ public void testStringLiteral() throws Exception {
+ marshall((KiWiStringLiteral) valueFactory.createLiteral(RandomStringUtils.randomAscii(40)), new StringLiteralExternalizer());
+ }
+
+ @Test
+ public void testLangLiteral() throws Exception {
+ marshall((KiWiStringLiteral) valueFactory.createLiteral(RandomStringUtils.randomAscii(40),"en"), new StringLiteralExternalizer());
+ }
+
+ @Test
+ public void testTypeLiteral() throws Exception {
+ marshall((KiWiStringLiteral) valueFactory.createLiteral(RandomStringUtils.randomAscii(40),valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8))), new StringLiteralExternalizer());
+ }
+
+
+ @Test
+ public void testIntLiteral() throws Exception {
+ marshall((KiWiIntLiteral) valueFactory.createLiteral(rnd.nextInt()), new IntLiteralExternalizer());
+ }
+
+
+ /**
+ * Run the given object through the marshaller using an in-memory stream.
+ * @param origin
+ * @param <T>
+ * @return
+ */
+ private <T> void marshall(T origin, AdvancedExternalizer<T> externalizer) throws IOException, ClassNotFoundException, InterruptedException {
+ log.info("- testing externalizer directly ...");
+ ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream(outBytes);
+
+ externalizer.writeObject(out, origin);
+ out.close();
+
+ log.info(" object {}: serialized with {} bytes", origin, outBytes.size());
+
+ ByteArrayInputStream inBytes = new ByteArrayInputStream(outBytes.toByteArray());
+ ObjectInputStream in = new ObjectInputStream(inBytes);
+
+ T destination1 = externalizer.readObject(in);
+
+ Assert.assertEquals(origin,destination1);
+
+ log.info("- testing externalizer with infinispan marshaller ...");
+
+ byte[] bytes = marshaller.objectToByteBuffer(origin);
+ log.info(" object {}: serialized with {} bytes", origin, bytes.length);
+
+ Object destination2 = marshaller.objectFromByteBuffer(bytes);
+
+ Assert.assertEquals(origin, destination2);
+
+ }
+
+
+ /**
+ * Return a random RDF value, either a reused object (10% chance) or of any other kind.
+ * @return
+ */
+ protected Value randomNode() {
+ Value object;
+ switch(rnd.nextInt(6)) {
+ case 0: object = valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
+ break;
+ case 1: object = valueFactory.createBNode();
+ break;
+ case 2: object = valueFactory.createLiteral(RandomStringUtils.randomAscii(40));
+ break;
+ case 3: object = valueFactory.createLiteral(rnd.nextInt());
+ break;
+ case 4: object = valueFactory.createLiteral(rnd.nextDouble());
+ break;
+ case 5: object = valueFactory.createLiteral(rnd.nextBoolean());
+ break;
+ default: object = valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
+ break;
+
+ }
+ return object;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/pom.xml
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/pom.xml b/libraries/kiwi/kiwi-triplestore/pom.xml
index 4f78852..2bbf839 100644
--- a/libraries/kiwi/kiwi-triplestore/pom.xml
+++ b/libraries/kiwi/kiwi-triplestore/pom.xml
@@ -59,11 +59,6 @@
</dependency>
- <!-- Caching -->
- <dependency>
- <groupId>org.infinispan</groupId>
- <artifactId>infinispan-core</artifactId>
- </dependency>
<!-- JDBC connection pooling -->
<dependency>
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/BNodeExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/BNodeExternalizer.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/BNodeExternalizer.java
deleted file mode 100644
index 36212a8..0000000
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/BNodeExternalizer.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.kiwi.caching;
-
-import org.apache.marmotta.kiwi.model.rdf.KiWiAnonResource;
-import org.infinispan.commons.marshall.AdvancedExternalizer;
-import org.infinispan.commons.util.Util;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Date;
-import java.util.Set;
-
-/**
- * Add file description here!
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class BNodeExternalizer implements AdvancedExternalizer<KiWiAnonResource> {
-
-
- @Override
- public Set<Class<? extends KiWiAnonResource>> getTypeClasses() {
- return Util.<Class<? extends KiWiAnonResource>>asSet(KiWiAnonResource.class);
- }
-
- @Override
- public Integer getId() {
- return ExternalizerIds.BNODE;
- }
-
- @Override
- public void writeObject(ObjectOutput output, KiWiAnonResource object) throws IOException {
- output.writeLong(object.getId());
- output.writeInt(object.stringValue().length());
- output.writeChars(object.stringValue());
- output.writeLong(object.getCreated().getTime());
- }
-
- @Override
- public KiWiAnonResource readObject(ObjectInput input) throws IOException, ClassNotFoundException {
- long id = input.readLong();
- int len = input.readInt();
-
- char[] anonId = new char[len];
- for(int i=0; i<len; i++) {
- anonId[i] = input.readChar();
- }
-
- Date created = new Date(input.readLong());
-
- KiWiAnonResource r = new KiWiAnonResource(new String(anonId),created);
- r.setId(id);
-
- return r;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/BooleanLiteralExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/BooleanLiteralExternalizer.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/BooleanLiteralExternalizer.java
deleted file mode 100644
index 5a32cf7..0000000
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/BooleanLiteralExternalizer.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.kiwi.caching;
-
-import org.apache.marmotta.kiwi.model.rdf.KiWiBooleanLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
-import org.infinispan.commons.marshall.AdvancedExternalizer;
-import org.infinispan.commons.util.Util;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Date;
-import java.util.Set;
-
-/**
- * Add file description here!
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class BooleanLiteralExternalizer implements AdvancedExternalizer<KiWiBooleanLiteral> {
-
- @Override
- public Set<Class<? extends KiWiBooleanLiteral>> getTypeClasses() {
- return Util.<Class<? extends KiWiBooleanLiteral>>asSet(KiWiBooleanLiteral.class);
- }
-
- @Override
- public Integer getId() {
- return ExternalizerIds.BOOL_LITERAL;
- }
-
- @Override
- public void writeObject(ObjectOutput output, KiWiBooleanLiteral object) throws IOException {
- output.writeLong(object.getId());
- output.writeBoolean(object.booleanValue());
- output.writeObject(object.getDatatype());
-
- output.writeLong(object.getCreated().getTime());
-
- }
-
- @Override
- public KiWiBooleanLiteral readObject(ObjectInput input) throws IOException, ClassNotFoundException {
- long id = input.readLong();
- boolean content = input.readBoolean();
-
- KiWiUriResource dtype = (KiWiUriResource) input.readObject();
-
- Date created = new Date(input.readLong());
-
- KiWiBooleanLiteral r = new KiWiBooleanLiteral(content, dtype, created);
- r.setId(id);
-
- return r;
- }
-}
[05/21] git commit: work on externalizer
Posted by ss...@apache.org.
work on externalizer
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/1698c6cb
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/1698c6cb
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/1698c6cb
Branch: refs/heads/MARMOTTA-450
Commit: 1698c6cb722eb5dc0db2a382282458fe7b12b321
Parents: 2e324d8
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Mon Mar 3 17:27:19 2014 +0100
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Mon Mar 3 17:27:19 2014 +0100
----------------------------------------------------------------------
.../InfinispanEmbeddedCacheManager.java | 310 ++++++++++---------
.../kiwi/externalizer/TripleExternalizer.java | 120 +++----
.../remote/InfinispanRemoteCacheManager.java | 114 +++++++
.../apache/marmotta/kiwi/test/ClusterTest.java | 160 ++++++++++
.../test/externalizer/ExternalizerTest.java | 27 +-
.../apache/marmotta/kiwi/test/ClusterTest.java | 157 ----------
6 files changed, 521 insertions(+), 367 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/1698c6cb/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/embedded/InfinispanEmbeddedCacheManager.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/embedded/InfinispanEmbeddedCacheManager.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/embedded/InfinispanEmbeddedCacheManager.java
index 35c2018..5818e0b 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/embedded/InfinispanEmbeddedCacheManager.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/embedded/InfinispanEmbeddedCacheManager.java
@@ -21,7 +21,6 @@ import org.apache.commons.io.IOUtils;
import org.apache.marmotta.kiwi.caching.CacheManager;
import org.apache.marmotta.kiwi.config.KiWiConfiguration;
import org.apache.marmotta.kiwi.externalizer.*;
-import org.apache.marmotta.kiwi.persistence.KiWiPersistence;
import org.infinispan.Cache;
import org.infinispan.commons.CacheException;
import org.infinispan.commons.marshall.AdvancedExternalizer;
@@ -44,9 +43,6 @@ import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.TimeUnit;
-import static org.apache.marmotta.kiwi.config.CacheMode.DISTRIBUTED;
-import static org.apache.marmotta.kiwi.config.CacheMode.REPLICATED;
-
/**
* A class for managing the different caches that are used by the triple store.
* <p/>
@@ -68,19 +64,12 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
private EmbeddedCacheManager cacheManager;
- private GlobalConfiguration globalConfiguration;
-
// default configuration: distributed cache, 100000 entries, 300 seconds expiration, 60 seconds idle
private Configuration defaultConfiguration;
- private boolean clustered, embedded;
-
- private KiWiConfiguration kiWiConfiguration;
-
- private KiWiPersistence persistence;
+ private KiWiConfiguration config;
-
- private Cache nodeCache, tripleCache, uriCache, literalCache, bnodeCache, nsPrefixCache, nsUriCache, loaderCache, registryCache;
+ private Cache nodeCache, tripleCache, uriCache, literalCache, bnodeCache, nsPrefixCache, nsUriCache, registryCache;
/**
@@ -90,120 +79,169 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
*/
public InfinispanEmbeddedCacheManager(KiWiConfiguration config) {
- this.clustered = config.isClustered();
- this.kiWiConfiguration = config;
-
- if(clustered && (config.getCacheMode() == DISTRIBUTED || config.getCacheMode() == REPLICATED)) {
- try {
- String jgroupsXml = IOUtils.toString(InfinispanEmbeddedCacheManager.class.getResourceAsStream("/jgroups-kiwi.xml"));
-
- jgroupsXml = jgroupsXml.replaceAll("mcast_addr=\"[0-9.]+\"", String.format("mcast_addr=\"%s\"", config.getClusterAddress()));
- jgroupsXml = jgroupsXml.replaceAll("mcast_port=\"[0-9]+\"", String.format("mcast_port=\"%d\"", config.getClusterPort()));
-
-
- globalConfiguration = new GlobalConfigurationBuilder()
- .classLoader(InfinispanEmbeddedCacheManager.class.getClassLoader())
- .transport()
- .defaultTransport()
- .clusterName(config.getClusterName())
- .machineId("instance-" + config.getDatacenterId())
- .addProperty("configurationXml", jgroupsXml)
- .globalJmxStatistics()
- .jmxDomain("org.apache.marmotta.kiwi")
- .allowDuplicateDomains(true)
- .serialization()
- .addAdvancedExternalizer(getExternalizers())
- .build();
- } catch (IOException ex) {
- log.warn("error loading JGroups configuration from archive: {}", ex.getMessage());
- log.warn("some configuration options will not be available");
-
- globalConfiguration = new GlobalConfigurationBuilder()
- .classLoader(InfinispanEmbeddedCacheManager.class.getClassLoader())
- .transport()
- .defaultTransport()
- .clusterName(config.getClusterName())
- .machineId("instance-" + config.getDatacenterId())
- .addProperty("configurationFile", "jgroups-kiwi.xml")
- .globalJmxStatistics()
- .jmxDomain("org.apache.marmotta.kiwi")
- .allowDuplicateDomains(true)
- .serialization()
- .addAdvancedExternalizer(getExternalizers())
- .build();
- }
+ this.config = config;
- if(config.getCacheMode() == DISTRIBUTED) {
- defaultConfiguration = new ConfigurationBuilder()
- .clustering()
- .cacheMode(CacheMode.DIST_ASYNC)
- .async()
- .asyncMarshalling()
- .l1()
- .lifespan(5, TimeUnit.MINUTES)
- .hash()
- .numOwners(2)
- .numSegments(40)
- .consistentHashFactory(new SyncConsistentHashFactory())
- .stateTransfer()
- .fetchInMemoryState(false)
- .eviction()
- .strategy(EvictionStrategy.LIRS)
- .maxEntries(100000)
- .expiration()
- .lifespan(30, TimeUnit.MINUTES)
- .maxIdle(10, TimeUnit.MINUTES)
- .build();
- } else {
- defaultConfiguration = new ConfigurationBuilder()
- .clustering()
- .cacheMode(CacheMode.REPL_ASYNC)
- .async()
- .asyncMarshalling()
- .stateTransfer()
- .fetchInMemoryState(false)
- .eviction()
- .strategy(EvictionStrategy.LIRS)
- .maxEntries(100000)
- .expiration()
- .lifespan(30, TimeUnit.MINUTES)
- .maxIdle(10, TimeUnit.MINUTES)
- .build();
+ try {
+ switch (config.getCacheMode()) {
+ case DISTRIBUTED:
+ buildDistributedConfiguration(getExternalizers());
+ break;
+ case REPLICATED:
+ buildReplicatedConfiguration(getExternalizers());
+ break;
+ case LOCAL:
+ buildLocalConfiguration();
+ break;
}
- } else {
- globalConfiguration = new GlobalConfigurationBuilder()
- .classLoader(InfinispanEmbeddedCacheManager.class.getClassLoader())
- .globalJmxStatistics()
- .jmxDomain("org.apache.marmotta.kiwi")
- .allowDuplicateDomains(true)
- .build();
+ } catch (IOException ex) {
+ log.warn("error while building cache cluster configuration, reverting to local cache");
+ buildLocalConfiguration();
+ }
- defaultConfiguration = new ConfigurationBuilder()
- .clustering()
- .cacheMode(CacheMode.LOCAL)
- .eviction()
- .strategy(EvictionStrategy.LIRS)
- .maxEntries(100000)
- .expiration()
+
+ }
+
+ /**
+ * Build a local cache configuration.
+ * <p/>
+ * In local cache mode, the cache is not shared among the servers in a cluster. Each machine keeps a local cache.
+ * This allows quick startups and eliminates network traffic in the cluster, but subsequent requests to different
+ * cluster members cannot benefit from the cached data.
+ */
+ protected void buildLocalConfiguration() {
+ GlobalConfiguration globalConfiguration = new GlobalConfigurationBuilder()
+ .classLoader(InfinispanEmbeddedCacheManager.class.getClassLoader())
+ .globalJmxStatistics()
+ .jmxDomain("org.apache.marmotta.kiwi")
+ .allowDuplicateDomains(true)
+ .build();
+
+ defaultConfiguration = new ConfigurationBuilder()
+ .clustering()
+ .cacheMode(CacheMode.LOCAL)
+ .eviction()
+ .strategy(EvictionStrategy.LIRS)
+ .maxEntries(100000)
+ .expiration()
+ .lifespan(5, TimeUnit.MINUTES)
+ .maxIdle(1, TimeUnit.MINUTES)
+ .build();
+ cacheManager = new DefaultCacheManager(globalConfiguration, defaultConfiguration, true);
+
+ log.info("initialised local cache manager");
+ }
+
+ /**
+ * Build a distributed cache configuration.
+ * <p/>
+ * In distributed cache mode, the cluster forms a big hash table used as a cache. This allows to make efficient
+ * use of the large amount of memory available, but requires cache rebalancing and a lot of network transfers,
+ * especially in case cluster members are restarted often.
+ */
+ protected void buildDistributedConfiguration(AdvancedExternalizer...externalizers) throws IOException {
+ String jgroupsXml = IOUtils.toString(InfinispanEmbeddedCacheManager.class.getResourceAsStream("/jgroups-kiwi.xml"));
+
+ jgroupsXml = jgroupsXml.replaceAll("mcast_addr=\"[0-9.]+\"", String.format("mcast_addr=\"%s\"", config.getClusterAddress()));
+ jgroupsXml = jgroupsXml.replaceAll("mcast_port=\"[0-9]+\"", String.format("mcast_port=\"%d\"", config.getClusterPort()));
+
+
+ GlobalConfiguration globalConfiguration = new GlobalConfigurationBuilder()
+ .classLoader(InfinispanEmbeddedCacheManager.class.getClassLoader())
+ .transport()
+ .defaultTransport()
+ .clusterName(config.getClusterName())
+ .machineId("instance-" + config.getDatacenterId())
+ .addProperty("configurationXml", jgroupsXml)
+ .globalJmxStatistics()
+ .jmxDomain("org.apache.marmotta.kiwi")
+ .allowDuplicateDomains(true)
+ .serialization()
+ .addAdvancedExternalizer(externalizers)
+ .build();
+
+ defaultConfiguration = new ConfigurationBuilder()
+ .clustering()
+ .cacheMode(CacheMode.DIST_ASYNC)
+ .async()
+ .asyncMarshalling()
+ .l1()
.lifespan(5, TimeUnit.MINUTES)
- .maxIdle(1, TimeUnit.MINUTES)
- .build();
+ .hash()
+ .numOwners(2)
+ .numSegments(40)
+ .consistentHashFactory(new SyncConsistentHashFactory())
+ .stateTransfer()
+ .fetchInMemoryState(false)
+ .eviction()
+ .strategy(EvictionStrategy.LIRS)
+ .maxEntries(100000)
+ .expiration()
+ .lifespan(30, TimeUnit.MINUTES)
+ .maxIdle(10, TimeUnit.MINUTES)
+ .build();
+ cacheManager = new DefaultCacheManager(globalConfiguration, defaultConfiguration, true);
- }
+ log.info("initialised distributed cache manager (cluster name: {})", globalConfiguration.transport().clusterName());
+ }
+ /**
+ * Build a replicated cache configuration.
+ * <p/>
+ * In replicated cache mode, each node in the cluster has an identical copy of all cache data. This allows
+ * very efficient cache lookups and reduces the rebalancing effort, but requires more memory.
+ */
+ protected void buildReplicatedConfiguration(AdvancedExternalizer...externalizers) throws IOException {
+ String jgroupsXml = IOUtils.toString(InfinispanEmbeddedCacheManager.class.getResourceAsStream("/jgroups-kiwi.xml"));
+
+ jgroupsXml = jgroupsXml.replaceAll("mcast_addr=\"[0-9.]+\"", String.format("mcast_addr=\"%s\"", config.getClusterAddress()));
+ jgroupsXml = jgroupsXml.replaceAll("mcast_port=\"[0-9]+\"", String.format("mcast_port=\"%d\"", config.getClusterPort()));
+
+
+ GlobalConfiguration globalConfiguration = new GlobalConfigurationBuilder()
+ .classLoader(InfinispanEmbeddedCacheManager.class.getClassLoader())
+ .transport()
+ .defaultTransport()
+ .clusterName(config.getClusterName())
+ .machineId("instance-" + config.getDatacenterId())
+ .addProperty("configurationXml", jgroupsXml)
+ .globalJmxStatistics()
+ .jmxDomain("org.apache.marmotta.kiwi")
+ .allowDuplicateDomains(true)
+ .serialization()
+ .addAdvancedExternalizer(externalizers)
+ .build();
+
+ defaultConfiguration = new ConfigurationBuilder()
+ .clustering()
+ .cacheMode(CacheMode.REPL_ASYNC)
+ .async()
+ .asyncMarshalling()
+ .stateTransfer()
+ .fetchInMemoryState(false)
+ .eviction()
+ .strategy(EvictionStrategy.LIRS)
+ .maxEntries(100000)
+ .expiration()
+ .lifespan(30, TimeUnit.MINUTES)
+ .maxIdle(10, TimeUnit.MINUTES)
+ .build();
cacheManager = new DefaultCacheManager(globalConfiguration, defaultConfiguration, true);
- log.info("initialised Infinispan cache manager ({})", globalConfiguration.isClustered() ? "cluster name: "+globalConfiguration.transport().clusterName() : "single host");
+ log.info("initialised replicated cache manager (cluster name: {})", globalConfiguration.transport().clusterName());
+ }
+
- this.embedded = true;
+ protected boolean isClustered() {
+ return config.getCacheMode() == org.apache.marmotta.kiwi.config.CacheMode.DISTRIBUTED ||
+ config.getCacheMode() == org.apache.marmotta.kiwi.config.CacheMode.REPLICATED;
}
private AdvancedExternalizer[] getExternalizers() {
return new AdvancedExternalizer[] {
- new TripleExternalizer(persistence),
+ new TripleExternalizer(),
new UriExternalizer(),
new BNodeExternalizer(),
new StringLiteralExternalizer(),
@@ -249,7 +287,7 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
.clustering()
.cacheMode(CacheMode.LOCAL)
.eviction()
- .maxEntries(kiWiConfiguration.getTripleCacheSize())
+ .maxEntries(config.getTripleCacheSize())
.expiration()
.lifespan(60, TimeUnit.MINUTES)
.maxIdle(30, TimeUnit.MINUTES)
@@ -272,7 +310,7 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
if(uriCache == null) {
Configuration uriConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
.eviction()
- .maxEntries(kiWiConfiguration.getUriCacheSize())
+ .maxEntries(config.getUriCacheSize())
.build();
cacheManager.defineConfiguration(URI_CACHE, uriConfiguration);
@@ -292,7 +330,7 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
if(bnodeCache == null) {
Configuration bnodeConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
.eviction()
- .maxEntries(kiWiConfiguration.getBNodeCacheSize())
+ .maxEntries(config.getBNodeCacheSize())
.build();
cacheManager.defineConfiguration(BNODE_CACHE, bnodeConfiguration);
@@ -312,7 +350,7 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
if(literalCache == null) {
Configuration literalConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
.eviction()
- .maxEntries(kiWiConfiguration.getLiteralCacheSize())
+ .maxEntries(config.getLiteralCacheSize())
.build();
cacheManager.defineConfiguration(LITERAL_CACHE, literalConfiguration);
@@ -328,12 +366,12 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
*/
public Cache getNamespaceUriCache() {
if(nsUriCache == null) {
- if(clustered) {
+ if(isClustered()) {
Configuration nsuriConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
.clustering()
.cacheMode(CacheMode.REPL_ASYNC)
.eviction()
- .maxEntries(kiWiConfiguration.getNamespaceCacheSize())
+ .maxEntries(config.getNamespaceCacheSize())
.expiration()
.lifespan(1, TimeUnit.DAYS)
.build();
@@ -341,7 +379,7 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
} else {
Configuration nsuriConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
.eviction()
- .maxEntries(kiWiConfiguration.getNamespaceCacheSize())
+ .maxEntries(config.getNamespaceCacheSize())
.expiration()
.lifespan(1, TimeUnit.HOURS)
.build();
@@ -359,12 +397,12 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
*/
public Cache getNamespacePrefixCache() {
if(nsPrefixCache == null) {
- if(clustered) {
+ if(isClustered()) {
Configuration nsprefixConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
.clustering()
.cacheMode(CacheMode.REPL_ASYNC)
.eviction()
- .maxEntries(kiWiConfiguration.getNamespaceCacheSize())
+ .maxEntries(config.getNamespaceCacheSize())
.expiration()
.lifespan(1, TimeUnit.DAYS)
.build();
@@ -373,7 +411,7 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
} else {
Configuration nsprefixConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
.eviction()
- .maxEntries(kiWiConfiguration.getNamespaceCacheSize())
+ .maxEntries(config.getNamespaceCacheSize())
.expiration()
.lifespan(1, TimeUnit.HOURS)
.build();
@@ -395,7 +433,7 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
*/
public Cache getRegistryCache() {
if(registryCache == null) {
- if(clustered) {
+ if(isClustered()) {
Configuration registryConfiguration = new ConfigurationBuilder()
.clustering()
.cacheMode(CacheMode.REPL_SYNC)
@@ -436,31 +474,6 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
}
/**
- * Return the Infinispan cache manager used by the caching infrastructure.
- *
- * @return
- */
- public EmbeddedCacheManager getCacheManager() {
- return cacheManager;
- }
-
- /**
- * Return the global cache manager configuration used by the caching infrastructure.
- * @return
- */
- public GlobalConfiguration getGlobalConfiguration() {
- return globalConfiguration;
- }
-
- /**
- * Return the default cache configuration used by the caching infrastructure.
- * @return
- */
- public Configuration getDefaultConfiguration() {
- return defaultConfiguration;
- }
-
- /**
* Clear all caches managed by this cache manager.
*/
public void clear() {
@@ -479,7 +492,6 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
bnodeCache = null;
nsPrefixCache = null;
nsUriCache = null;
- loaderCache = null;
registryCache = null;
}
@@ -488,7 +500,7 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
*/
public void shutdown() {
try {
- if(embedded && cacheManager.getStatus() == ComponentStatus.RUNNING) {
+ if(cacheManager.getStatus() == ComponentStatus.RUNNING) {
log.warn("shutting down cache manager ...");
// if(cacheManager.getTransport() != null) {
// log.info("... shutting down transport ...");
http://git-wip-us.apache.org/repos/asf/marmotta/blob/1698c6cb/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/TripleExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/TripleExternalizer.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/TripleExternalizer.java
index e4c584c..05e6933 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/TripleExternalizer.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/TripleExternalizer.java
@@ -17,21 +17,17 @@
package org.apache.marmotta.kiwi.externalizer;
+import org.apache.commons.lang3.StringUtils;
import org.apache.marmotta.kiwi.model.rdf.KiWiNode;
import org.apache.marmotta.kiwi.model.rdf.KiWiResource;
import org.apache.marmotta.kiwi.model.rdf.KiWiTriple;
import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
-import org.apache.marmotta.kiwi.persistence.KiWiConnection;
-import org.apache.marmotta.kiwi.persistence.KiWiPersistence;
import org.infinispan.commons.marshall.AdvancedExternalizer;
import org.infinispan.commons.util.Util;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
-import java.sql.SQLException;
import java.util.Date;
import java.util.Set;
@@ -41,13 +37,10 @@ import java.util.Set;
*/
public class TripleExternalizer implements AdvancedExternalizer<KiWiTriple> {
- private static Logger log = LoggerFactory.getLogger(TripleExternalizer.class);
- private KiWiPersistence persistence;
+ public static final int MODE_DEFAULT = 1;
+ public static final int MODE_PREFIX = 2;
- public TripleExternalizer(KiWiPersistence persistence) {
- this.persistence = persistence;
- }
@Override
public Set<Class<? extends KiWiTriple>> getTypeClasses() {
@@ -62,11 +55,39 @@ public class TripleExternalizer implements AdvancedExternalizer<KiWiTriple> {
@Override
public void writeObject(ObjectOutput output, KiWiTriple object) throws IOException {
output.writeLong(object.getId());
- output.writeLong(object.getSubject().getId());
- output.writeLong(object.getPredicate().getId());
- output.writeLong(object.getObject().getId());
- output.writeLong(object.getContext() != null ? object.getContext().getId() : -1L);
- output.writeLong(object.getCreator() != null ? object.getCreator().getId() : -1L);
+
+ // in case subject and object are both uris we use a special prefix-compressed mode
+ if(object.getSubject().isUriResource() && object.getObject().isUriResource()) {
+ String sUri = object.getSubject().stringValue();
+ String oUri = object.getObject().stringValue();
+
+ String prefix = StringUtils.getCommonPrefix(sUri,oUri);
+
+ output.writeByte(MODE_PREFIX);
+ output.writeInt(prefix.length());
+ output.writeChars(prefix);
+
+ output.writeLong(object.getSubject().getId());
+ output.writeInt(sUri.length() - prefix.length());
+ output.writeChars(sUri.substring(prefix.length()));
+ output.writeLong(object.getSubject().getCreated().getTime());
+
+ output.writeObject(object.getPredicate());
+
+ output.writeLong(object.getObject().getId());
+ output.writeInt(oUri.length() - prefix.length());
+ output.writeChars(oUri.substring(prefix.length()));
+ output.writeLong(object.getObject().getCreated().getTime());
+ } else {
+ output.writeByte(MODE_DEFAULT);
+
+ output.writeObject(object.getSubject());
+ output.writeObject(object.getPredicate());
+ output.writeObject(object.getObject());
+ }
+
+ output.writeObject(object.getContext());
+ output.writeObject(object.getCreator());
output.writeBoolean(object.isDeleted());
output.writeBoolean(object.isInferred());
output.writeBoolean(object.isNewTriple());
@@ -80,48 +101,33 @@ public class TripleExternalizer implements AdvancedExternalizer<KiWiTriple> {
@Override
public KiWiTriple readObject(ObjectInput input) throws IOException, ClassNotFoundException {
- try {
- KiWiConnection con = persistence.getConnection();
- try {
- KiWiTriple result = new KiWiTriple();
- result.setId(input.readLong());
-
- long[] nodeIds = new long[5];
- for(int i=0; i<5; i++) {
- nodeIds[0] = input.readLong();
- }
- KiWiNode[] nodes = con.loadNodesByIds(nodeIds);
-
- result.setSubject((KiWiResource) nodes[0]);
- result.setPredicate((KiWiUriResource) nodes[1]);
- result.setObject(nodes[2]);
-
- if(nodes[3] != null) {
- result.setContext((KiWiResource) nodes[3]);
- }
- if(nodes[4] != null) {
- result.setCreator((KiWiResource) nodes[4]);
- }
-
- result.setDeleted(input.readBoolean());
- result.setInferred(input.readBoolean());
- result.setNewTriple(input.readBoolean());
-
- result.setCreated(new Date(input.readLong()));
-
- long deletedAt = input.readLong();
- if(deletedAt > 0) {
- result.setDeletedAt(new Date(deletedAt));
- }
-
-
- return result;
- } finally {
- con.commit();
- con.close();
- }
- } catch (SQLException ex) {
- throw new IOException(ex);
+
+ KiWiTriple result = new KiWiTriple();
+ result.setId(input.readLong());
+
+ int mode = input.readInt();
+ if(mode == MODE_PREFIX) {
+ String prefix =
+ }
+
+
+ result.setSubject((KiWiResource) input.readObject());
+ result.setPredicate((KiWiUriResource) input.readObject());
+ result.setObject((KiWiNode) input.readObject());
+ result.setContext((KiWiResource) input.readObject());
+ result.setCreator((KiWiResource) input.readObject());
+ result.setDeleted(input.readBoolean());
+ result.setInferred(input.readBoolean());
+ result.setNewTriple(input.readBoolean());
+
+ result.setCreated(new Date(input.readLong()));
+
+ long deletedAt = input.readLong();
+ if(deletedAt > 0) {
+ result.setDeletedAt(new Date(deletedAt));
}
+
+
+ return result;
}
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/1698c6cb/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/remote/InfinispanRemoteCacheManager.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/remote/InfinispanRemoteCacheManager.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/remote/InfinispanRemoteCacheManager.java
index c40feb8..6f5034a 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/remote/InfinispanRemoteCacheManager.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/remote/InfinispanRemoteCacheManager.java
@@ -19,6 +19,9 @@ package org.apache.marmotta.kiwi.remote;
import org.apache.marmotta.kiwi.caching.CacheManager;
import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+import org.apache.marmotta.kiwi.model.rdf.*;
+
+import java.util.Map;
/**
* Implementation of an Infinispan cache manager with a remote (client-server) cache.
@@ -34,7 +37,118 @@ public class InfinispanRemoteCacheManager implements CacheManager {
}
+ /**
+ * Return the node id -> node cache from the cache manager. This cache is heavily used to lookup
+ * nodes when querying or loading triples and should therefore have a decent size (default 500.000 elements).
+ *
+ * @return an EHCache Cache instance containing the node id -> node mappings
+ */
+ @Override
+ public Map<Long, KiWiNode> getNodeCache() {
+ return null;
+ }
+
+ /**
+ * Return the triple id -> triple cache from the cache manager. This cache is used for speeding up the
+ * construction of query results.
+ *
+ * @return
+ */
+ @Override
+ public Map<Long, KiWiTriple> getTripleCache() {
+ return null;
+ }
+ /**
+ * Return the uri -> KiWiUriResource cache from the cache manager. This cache is used when constructing new
+ * KiWiUriResources to avoid a database lookup.
+ *
+ * @return
+ */
+ @Override
+ public Map<String, KiWiUriResource> getUriCache() {
+ return null;
+ }
+ /**
+ * Return the anonId -> KiWiAnonResource cache from the cache manager. This cache is used when constructing new
+ * KiWiAnonResources to avoid a database lookup.
+ *
+ * @return
+ */
+ @Override
+ public Map<String, KiWiAnonResource> getBNodeCache() {
+ return null;
+ }
+ /**
+ * Return the literal cache key -> KiWiLiteral cache from the cache manager. This cache is used when constructing new
+ * KiWiLiterals to avoid a database lookup.
+ *
+ * @return
+ * @see org.apache.marmotta.commons.sesame.model.LiteralCommons#createCacheKey(String, java.util.Locale, String)
+ */
+ @Override
+ public Map<String, KiWiLiteral> getLiteralCache() {
+ return null;
+ }
+
+ /**
+ * Return the URI -> namespace cache from the cache manager. Used for looking up namespaces
+ *
+ * @return
+ */
+ @Override
+ public Map<String, KiWiNamespace> getNamespaceUriCache() {
+ return null;
+ }
+
+ /**
+ * Return the prefix -> namespace cache from the cache manager. Used for looking up namespaces
+ *
+ * @return
+ */
+ @Override
+ public Map<String, KiWiNamespace> getNamespacePrefixCache() {
+ return null;
+ }
+
+ /**
+ * Create and return the cache used by the CacheTripleRegistry. This is an unlimited synchronous replicated
+ * cache and should be used with care.
+ *
+ * @return
+ */
+ @Override
+ public Map<Long, Long> getRegistryCache() {
+ return null;
+ }
+
+ /**
+ * Get the cache with the given name from the cache manager. Can be used to request additional
+ * caches from the cache manager that are not covered by explicit methods.
+ *
+ * @param name
+ * @return
+ */
+ @Override
+ public Map getCacheByName(String name) {
+ return null;
+ }
+
+ /**
+ * Clear all caches managed by this cache manager.
+ */
+ @Override
+ public void clear() {
+
+ }
+
+ /**
+ * Shutdown this cache manager instance. Will shutdown the underlying EHCache cache manager.
+ */
+ @Override
+ public void shutdown() {
+
+ }
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/1698c6cb/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/ClusterTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/ClusterTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/ClusterTest.java
new file mode 100644
index 0000000..0b6823c
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/ClusterTest.java
@@ -0,0 +1,160 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.test;
+
+import com.google.common.hash.Hasher;
+import com.google.common.hash.Hashing;
+import org.apache.marmotta.kiwi.caching.CacheManager;
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+import org.apache.marmotta.kiwi.embedded.InfinispanEmbeddedCacheManagerFactory;
+import org.apache.marmotta.kiwi.persistence.h2.H2Dialect;
+import org.apache.marmotta.kiwi.sail.KiWiStore;
+import org.junit.*;
+import org.openrdf.model.URI;
+import org.openrdf.repository.Repository;
+import org.openrdf.repository.RepositoryException;
+import org.openrdf.repository.sail.SailRepository;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class ClusterTest {
+
+ private static Logger log = LoggerFactory.getLogger(ClusterTest.class);
+
+ KiWiConfiguration config1, config2;
+
+ KiWiStore store1, store2;
+
+ Repository repository1, repository2;
+
+ CacheManager cacheManager1, cacheManager2;
+
+ @Before
+ public void setup() throws RepositoryException {
+ config1 = new KiWiConfiguration(
+ "default-H2",
+ "jdbc:h2:mem:kiwitest;MVCC=true;DB_CLOSE_ON_EXIT=TRUE;DB_CLOSE_DELAY=-1",
+ "kiwi", "kiwi",
+ new H2Dialect());
+ config1.setDatacenterId(1);
+ config1.setClustered(true);
+ config1.setCacheManagerFactory(InfinispanEmbeddedCacheManagerFactory.class.getName());
+
+ config2 = new KiWiConfiguration(
+ "default-H2",
+ "jdbc:h2:mem:kiwitest;MVCC=true;DB_CLOSE_ON_EXIT=TRUE;DB_CLOSE_DELAY=-1",
+ "kiwi", "kiwi",
+ new H2Dialect());
+ config2.setDatacenterId(2);
+ config2.setClustered(true);
+ config2.setCacheManagerFactory(InfinispanEmbeddedCacheManagerFactory.class.getName());
+
+
+
+ }
+
+ public void setupCluster(int port1, int port2) throws RepositoryException {
+ config1.setClusterPort(port1);
+ config2.setClusterPort(port2);
+
+ store1 = new KiWiStore(config1);
+ store2 = new KiWiStore(config2);
+
+ repository1 = new SailRepository(store1);
+ repository2 = new SailRepository(store2);
+
+ repository1.initialize();
+ repository2.initialize();
+
+ cacheManager1 = store1.getPersistence().getCacheManager();
+ cacheManager2 = store2.getPersistence().getCacheManager();
+ }
+
+
+ @After
+ public void teardown() throws RepositoryException {
+ repository1.shutDown();
+ repository2.shutDown();
+ }
+
+
+ @Test
+ @Ignore
+ public void testClusteredCacheSync() throws InterruptedException, RepositoryException {
+ setupCluster(61222,61222);
+
+ log.info("testing cache synchronization ...");
+
+ URI u = repository1.getValueFactory().createURI("http://localhost/test1");
+
+
+ // give the cluster some time to performance asynchronous balancing
+ Thread.sleep(100);
+
+
+ log.debug("test if resource is in cache where it was created ...");
+ URI u1 = (URI) cacheManager1.getUriCache().get(createCacheKey("http://localhost/test1"));
+
+ Assert.assertNotNull(u1);
+ Assert.assertEquals(u,u1);
+
+ log.debug("test if resource has been synced to other cache in cluster ...");
+ URI u2 = (URI) cacheManager2.getUriCache().get(createCacheKey("http://localhost/test1"));
+
+ Assert.assertNotNull(u2);
+ Assert.assertEquals(u,u2);
+ }
+
+ @Test
+ @Ignore
+ public void testDisjointClusters() throws InterruptedException, RepositoryException {
+ setupCluster(61224,61225);
+
+ log.info("testing caches on different ports ...");
+
+ URI u = repository1.getValueFactory().createURI("http://localhost/test1");
+
+
+ // give the cluster some time to performance asynchronous balancing
+ Thread.sleep(100);
+
+ log.debug("test if resource is in cache where it was created ...");
+ URI u1 = (URI) cacheManager1.getUriCache().get(createCacheKey("http://localhost/test1"));
+
+ Assert.assertNotNull(u1);
+ Assert.assertEquals(u,u1);
+
+ log.debug("test if resource has been synced to other cache in cluster ...");
+ URI u2 = (URI) cacheManager2.getUriCache().get(createCacheKey("http://localhost/test1"));
+
+ Assert.assertNull(u2);
+ }
+
+
+ private static Long createCacheKey(String svalue) {
+ Hasher hasher = Hashing.goodFastHash(64).newHasher();
+ hasher.putString(svalue);
+ return hasher.hash().asLong();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/1698c6cb/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/externalizer/ExternalizerTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/externalizer/ExternalizerTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/externalizer/ExternalizerTest.java
index fe7b701..9f52813 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/externalizer/ExternalizerTest.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/externalizer/ExternalizerTest.java
@@ -18,10 +18,8 @@
package org.apache.marmotta.kiwi.test.externalizer;
import org.apache.commons.lang3.RandomStringUtils;
-import org.apache.marmotta.kiwi.model.rdf.KiWiAnonResource;
-import org.apache.marmotta.kiwi.model.rdf.KiWiIntLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiStringLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
+import org.apache.marmotta.kiwi.externalizer.*;
+import org.apache.marmotta.kiwi.model.rdf.*;
import org.apache.marmotta.kiwi.test.TestValueFactory;
import org.infinispan.commons.marshall.AdvancedExternalizer;
import org.infinispan.commons.marshall.StreamingMarshaller;
@@ -123,6 +121,16 @@ public class ExternalizerTest {
}
+ @Test
+ public void testTriple() throws Exception {
+ KiWiUriResource s = (KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
+ KiWiUriResource p = (KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
+ KiWiNode o = (KiWiNode) randomNode();
+ KiWiTriple t = (KiWiTriple) valueFactory.createStatement(s,p,o);
+
+ marshall(t, new TripleExternalizer());
+ }
+
/**
* Run the given object through the marshaller using an in-memory stream.
* @param origin
@@ -130,6 +138,17 @@ public class ExternalizerTest {
* @return
*/
private <T> void marshall(T origin, AdvancedExternalizer<T> externalizer) throws IOException, ClassNotFoundException, InterruptedException {
+ log.info("- testing Java ObjectStream ...");
+ ByteArrayOutputStream outBytesOS = new ByteArrayOutputStream();
+ ObjectOutputStream outOS = new ObjectOutputStream(outBytesOS);
+
+ outOS.writeObject(origin);
+
+ outOS.close();
+
+ log.info(" object {}: serialized with {} bytes", origin, outBytesOS.size());
+
+
log.info("- testing externalizer directly ...");
ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(outBytes);
http://git-wip-us.apache.org/repos/asf/marmotta/blob/1698c6cb/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/ClusterTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/ClusterTest.java b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/ClusterTest.java
deleted file mode 100644
index 5f4d719..0000000
--- a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/ClusterTest.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.kiwi.test;
-
-import com.google.common.hash.Hasher;
-import com.google.common.hash.Hashing;
-import org.apache.marmotta.kiwi.caching.KiWiCacheManager;
-import org.apache.marmotta.kiwi.config.KiWiConfiguration;
-import org.apache.marmotta.kiwi.persistence.h2.H2Dialect;
-import org.apache.marmotta.kiwi.sail.KiWiStore;
-import org.junit.*;
-import org.openrdf.model.URI;
-import org.openrdf.repository.Repository;
-import org.openrdf.repository.RepositoryException;
-import org.openrdf.repository.sail.SailRepository;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Add file description here!
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class ClusterTest {
-
- private static Logger log = LoggerFactory.getLogger(ClusterTest.class);
-
- KiWiConfiguration config1, config2;
-
- KiWiStore store1, store2;
-
- Repository repository1, repository2;
-
- KiWiCacheManager cacheManager1, cacheManager2;
-
- @Before
- public void setup() throws RepositoryException {
- config1 = new KiWiConfiguration(
- "default-H2",
- "jdbc:h2:mem:kiwitest;MVCC=true;DB_CLOSE_ON_EXIT=TRUE;DB_CLOSE_DELAY=-1",
- "kiwi", "kiwi",
- new H2Dialect());
- config1.setDatacenterId(1);
- config1.setClustered(true);
-
- config2 = new KiWiConfiguration(
- "default-H2",
- "jdbc:h2:mem:kiwitest;MVCC=true;DB_CLOSE_ON_EXIT=TRUE;DB_CLOSE_DELAY=-1",
- "kiwi", "kiwi",
- new H2Dialect());
- config2.setDatacenterId(2);
- config2.setClustered(true);
-
-
-
- }
-
- public void setupCluster(int port1, int port2) throws RepositoryException {
- config1.setClusterPort(port1);
- config2.setClusterPort(port2);
-
- store1 = new KiWiStore(config1);
- store2 = new KiWiStore(config2);
-
- repository1 = new SailRepository(store1);
- repository2 = new SailRepository(store2);
-
- repository1.initialize();
- repository2.initialize();
-
- cacheManager1 = store1.getPersistence().getCacheManager();
- cacheManager2 = store2.getPersistence().getCacheManager();
- }
-
-
- @After
- public void teardown() throws RepositoryException {
- repository1.shutDown();
- repository2.shutDown();
- }
-
-
- @Test
- @Ignore
- public void testClusteredCacheSync() throws InterruptedException, RepositoryException {
- setupCluster(61222,61222);
-
- log.info("testing cache synchronization ...");
-
- URI u = repository1.getValueFactory().createURI("http://localhost/test1");
-
-
- // give the cluster some time to performance asynchronous balancing
- Thread.sleep(100);
-
-
- log.debug("test if resource is in cache where it was created ...");
- URI u1 = (URI) cacheManager1.getUriCache().get(createCacheKey("http://localhost/test1"));
-
- Assert.assertNotNull(u1);
- Assert.assertEquals(u,u1);
-
- log.debug("test if resource has been synced to other cache in cluster ...");
- URI u2 = (URI) cacheManager2.getUriCache().get(createCacheKey("http://localhost/test1"));
-
- Assert.assertNotNull(u2);
- Assert.assertEquals(u,u2);
- }
-
- @Test
- @Ignore
- public void testDisjointClusters() throws InterruptedException, RepositoryException {
- setupCluster(61224,61225);
-
- log.info("testing caches on different ports ...");
-
- URI u = repository1.getValueFactory().createURI("http://localhost/test1");
-
-
- // give the cluster some time to performance asynchronous balancing
- Thread.sleep(100);
-
- log.debug("test if resource is in cache where it was created ...");
- URI u1 = (URI) cacheManager1.getUriCache().get(createCacheKey("http://localhost/test1"));
-
- Assert.assertNotNull(u1);
- Assert.assertEquals(u,u1);
-
- log.debug("test if resource has been synced to other cache in cluster ...");
- URI u2 = (URI) cacheManager2.getUriCache().get(createCacheKey("http://localhost/test1"));
-
- Assert.assertNull(u2);
- }
-
-
- private static Long createCacheKey(String svalue) {
- Hasher hasher = Hashing.goodFastHash(64).newHasher();
- hasher.putString(svalue);
- return hasher.hash().asLong();
- }
-
-}
[20/21] git commit: there is a problem with too many open TCP
connections waiting in TIME_WAIT, trying different approaches
Posted by ss...@apache.org.
there is a problem with too many open TCP connections waiting in TIME_WAIT, trying different approaches
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/673b4f97
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/673b4f97
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/673b4f97
Branch: refs/heads/MARMOTTA-450
Commit: 673b4f97d156e8576e1b86e1dd379f4a7951713f
Parents: 35cd6c6
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Tue Mar 4 23:26:39 2014 +0100
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Tue Mar 4 23:26:39 2014 +0100
----------------------------------------------------------------------
.../embedded/InfinispanEmbeddedCacheManager.java | 4 ++++
.../remote/InfinispanRemoteCacheManager.java | 1 +
.../embedded/EmbeddedRepositoryConnectionTest.java | 1 +
.../kiwi/test/embedded/EmbeddedRepositoryTest.java | 1 +
.../test/remote/HotRodRepositoryConnectionTest.java | 1 +
.../kiwi/test/remote/HotRodRepositoryTest.java | 1 +
.../marmotta/kiwi/test/remote/HotRodServerRule.java | 4 +++-
.../marmotta/kiwi/config/KiWiConfiguration.java | 15 +++++++++++++++
8 files changed, 27 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/673b4f97/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/embedded/InfinispanEmbeddedCacheManager.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/embedded/InfinispanEmbeddedCacheManager.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/embedded/InfinispanEmbeddedCacheManager.java
index 6076577..95f1109 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/embedded/InfinispanEmbeddedCacheManager.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/embedded/InfinispanEmbeddedCacheManager.java
@@ -145,6 +145,7 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
.clusterName(config.getClusterName())
.machineId("instance-" + config.getDatacenterId())
.addProperty("configurationXml", jgroupsXml)
+ .distributedSyncTimeout(config.getClusterTimeout())
.globalJmxStatistics()
.jmxDomain("org.apache.marmotta.kiwi")
.allowDuplicateDomains(true)
@@ -165,6 +166,7 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
.consistentHashFactory(new SyncConsistentHashFactory())
.stateTransfer()
.fetchInMemoryState(false)
+ .timeout(config.getClusterTimeout())
.eviction()
.strategy(EvictionStrategy.LIRS)
.maxEntries(100000)
@@ -198,6 +200,7 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
.clusterName(config.getClusterName())
.machineId("instance-" + config.getDatacenterId())
.addProperty("configurationXml", jgroupsXml)
+ .distributedSyncTimeout(config.getClusterTimeout())
.globalJmxStatistics()
.jmxDomain("org.apache.marmotta.kiwi")
.allowDuplicateDomains(true)
@@ -212,6 +215,7 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
.asyncMarshalling()
.stateTransfer()
.fetchInMemoryState(false)
+ .timeout(config.getClusterTimeout())
.eviction()
.strategy(EvictionStrategy.LIRS)
.maxEntries(100000)
http://git-wip-us.apache.org/repos/asf/marmotta/blob/673b4f97/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/InfinispanRemoteCacheManager.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/InfinispanRemoteCacheManager.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/InfinispanRemoteCacheManager.java
index 0952706..8455fdd 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/InfinispanRemoteCacheManager.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/InfinispanRemoteCacheManager.java
@@ -54,6 +54,7 @@ public class InfinispanRemoteCacheManager implements CacheManager {
.host(configuration.getClusterAddress())
.port(configuration.getClusterPort())
.marshaller(new CustomJBossMarshaller())
+ .socketTimeout(configuration.getClusterTimeout())
.build();
cacheManager = new RemoteCacheManager(remoteCfg);
http://git-wip-us.apache.org/repos/asf/marmotta/blob/673b4f97/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedRepositoryConnectionTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedRepositoryConnectionTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedRepositoryConnectionTest.java
index 676e90b..8fffa88 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedRepositoryConnectionTest.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedRepositoryConnectionTest.java
@@ -44,6 +44,7 @@ public class EmbeddedRepositoryConnectionTest extends RepositoryConnectionTest {
config.setClustered(true);
config.setClusterPort(61222);
config.setCacheMode(CacheMode.LOCAL);
+ config.setClusterTimeout(10000);
config.setCacheManager(CacheManagerType.INFINISPAN_CLUSTERED);
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/673b4f97/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedRepositoryTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedRepositoryTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedRepositoryTest.java
index 7094893..3796d68 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedRepositoryTest.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedRepositoryTest.java
@@ -44,6 +44,7 @@ public class EmbeddedRepositoryTest extends RepositoryTest {
config.setClustered(true);
config.setClusterPort(61222);
config.setCacheMode(CacheMode.LOCAL);
+ config.setClusterTimeout(10000);
config.setCacheManager(CacheManagerType.INFINISPAN_CLUSTERED);
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/673b4f97/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryConnectionTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryConnectionTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryConnectionTest.java
index 198c44c..7890df0 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryConnectionTest.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryConnectionTest.java
@@ -47,6 +47,7 @@ public class HotRodRepositoryConnectionTest extends RepositoryConnectionTest {
config.setClusterAddress("127.0.0.1");
config.setClustered(true);
config.setClusterPort(61222);
+ config.setClusterTimeout(10000);
config.setCacheManager(CacheManagerType.INFINISPAN_HOTROD);
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/673b4f97/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryTest.java
index a7ee8a4..a026114 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryTest.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryTest.java
@@ -48,6 +48,7 @@ public class HotRodRepositoryTest extends RepositoryTest {
config.setClusterAddress("127.0.0.1");
config.setClustered(true);
config.setClusterPort(61222);
+ config.setClusterTimeout(10000);
config.setCacheManager(CacheManagerType.INFINISPAN_HOTROD);
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/673b4f97/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodServerRule.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodServerRule.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodServerRule.java
index 7029b1f..6e3dec2 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodServerRule.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodServerRule.java
@@ -107,7 +107,9 @@ public class HotRodServerRule implements TestRule {
.proxyPort(port)
.topologyStateTransfer(false)
.defaultCacheName(BasicCacheContainer.DEFAULT_CACHE_NAME)
- .idleTimeout(0)
+ .recvBufSize(4096)
+ .sendBufSize(4096)
+ //.idleTimeout(0)
.workerThreads(2)
.build(true);
http://git-wip-us.apache.org/repos/asf/marmotta/blob/673b4f97/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java
index 2db24f2..6cf8ab4 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java
@@ -137,6 +137,12 @@ public class KiWiConfiguration {
*/
private String clusterAddress = "228.6.7.8";
+
+ /**
+ * Socket timeout for cluster connections.
+ */
+ private int clusterTimeout = 60000;
+
public KiWiConfiguration(String name, String jdbcUrl, String dbUser, String dbPassword, KiWiDialect dialect) {
this(name, jdbcUrl, dbUser, dbPassword, dialect, null, null);
}
@@ -577,4 +583,13 @@ public class KiWiConfiguration {
public void setClusterAddress(String clusterAddress) {
this.clusterAddress = clusterAddress;
}
+
+
+ public int getClusterTimeout() {
+ return clusterTimeout;
+ }
+
+ public void setClusterTimeout(int clusterTimeout) {
+ this.clusterTimeout = clusterTimeout;
+ }
}
[04/21] git commit: add hotrod dependency for Infinispan
Posted by ss...@apache.org.
add hotrod dependency for Infinispan
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/2e324d8b
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/2e324d8b
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/2e324d8b
Branch: refs/heads/MARMOTTA-450
Commit: 2e324d8b46e6f5875b55de61dd482fc6d6ad7593
Parents: c6d0cc1
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Mon Mar 3 16:29:53 2014 +0100
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Mon Mar 3 16:29:53 2014 +0100
----------------------------------------------------------------------
libraries/kiwi/kiwi-caching-infinispan/pom.xml | 4 ++++
parent/pom.xml | 5 +++++
2 files changed, 9 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2e324d8b/libraries/kiwi/kiwi-caching-infinispan/pom.xml
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/pom.xml b/libraries/kiwi/kiwi-caching-infinispan/pom.xml
index 7ec7dc1..ddbbab0 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/pom.xml
+++ b/libraries/kiwi/kiwi-caching-infinispan/pom.xml
@@ -49,6 +49,10 @@
<groupId>org.infinispan</groupId>
<artifactId>infinispan-core</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.infinispan</groupId>
+ <artifactId>infinispan-client-hotrod</artifactId>
+ </dependency>
<!-- Testing -->
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2e324d8b/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index f2c11d6..2190cbe 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -1040,6 +1040,11 @@
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
+ <artifactId>infinispan-client-hotrod</artifactId>
+ <version>6.0.1.Final</version>
+ </dependency>
+ <dependency>
+ <groupId>org.infinispan</groupId>
<artifactId>infinispan-cdi</artifactId>
<version>6.0.1.Final</version>
</dependency>
[06/21] git commit: optimized serializers for nodes
Posted by ss...@apache.org.
optimized serializers for nodes
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/27a9c265
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/27a9c265
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/27a9c265
Branch: refs/heads/MARMOTTA-450
Commit: 27a9c2652dae658fcf32cf46c0bffb5a5b7c1bfa
Parents: 1698c6c
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Mon Mar 3 18:17:00 2014 +0100
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Mon Mar 3 18:17:00 2014 +0100
----------------------------------------------------------------------
.../org/apache/marmotta/commons/io/DataIO.java | 67 ++++++
.../kiwi/externalizer/ExternalizerIds.java | 2 +
.../externalizer/StringLiteralExternalizer.java | 32 +--
.../kiwi/externalizer/TripleExternalizer.java | 44 ++--
.../kiwi/externalizer/UriExternalizer.java | 78 ++++++-
.../marmotta/kiwi/test/ExternalizerTest.java | 228 +++++++++++++++++++
.../test/externalizer/ExternalizerTest.java | 206 -----------------
7 files changed, 406 insertions(+), 251 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/27a9c265/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/io/DataIO.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/io/DataIO.java b/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/io/DataIO.java
new file mode 100644
index 0000000..d236ef7
--- /dev/null
+++ b/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/io/DataIO.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.commons.io;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.Date;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class DataIO {
+
+
+ public static void writeString(DataOutput out, String s) throws IOException {
+ if(s != null) {
+ out.writeInt(s.length());
+ out.writeChars(s);
+ } else {
+ out.writeInt(-1);
+ }
+ }
+
+
+ public static String readString(DataInput in) throws IOException {
+ int len = in.readInt();
+
+ if(len >= 0) {
+ StringBuilder builder = new StringBuilder();
+ for(int i=0; i<len; i++) {
+ builder.append(in.readChar());
+ }
+ return builder.toString();
+ } else {
+ return null;
+ }
+ }
+
+
+ public static void writeDate(DataOutput out, Date date) throws IOException {
+ out.writeLong(date.getTime());
+ }
+
+
+ public static Date readDate(DataInput in) throws IOException {
+ long time = in.readLong();
+ return new Date(time);
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/27a9c265/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/ExternalizerIds.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/ExternalizerIds.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/ExternalizerIds.java
index 880303d..5be8cbe 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/ExternalizerIds.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/ExternalizerIds.java
@@ -24,6 +24,8 @@ package org.apache.marmotta.kiwi.externalizer;
*/
public class ExternalizerIds {
+ public static final int TRIPLE = 13;
+
public static final int URI = 17;
public static final int BNODE = 23;
http://git-wip-us.apache.org/repos/asf/marmotta/blob/27a9c265/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/StringLiteralExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/StringLiteralExternalizer.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/StringLiteralExternalizer.java
index 4e47459..178c76a 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/StringLiteralExternalizer.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/StringLiteralExternalizer.java
@@ -17,6 +17,7 @@
package org.apache.marmotta.kiwi.externalizer;
+import org.apache.marmotta.commons.io.DataIO;
import org.apache.marmotta.kiwi.model.rdf.KiWiStringLiteral;
import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
import org.infinispan.commons.marshall.AdvancedExternalizer;
@@ -49,14 +50,9 @@ public class StringLiteralExternalizer implements AdvancedExternalizer<KiWiStrin
@Override
public void writeObject(ObjectOutput output, KiWiStringLiteral object) throws IOException {
output.writeLong(object.getId());
- output.writeInt(object.getContent().length());
- output.writeChars(object.getContent());
- if(object.getLanguage() != null) {
- output.writeInt(object.getLanguage().length());
- output.writeChars(object.getLanguage());
- } else {
- output.writeInt(0);
- }
+
+ DataIO.writeString(output, object.getContent());
+ DataIO.writeString(output, object.getLanguage());
output.writeObject(object.getDatatype());
@@ -67,27 +63,15 @@ public class StringLiteralExternalizer implements AdvancedExternalizer<KiWiStrin
@Override
public KiWiStringLiteral readObject(ObjectInput input) throws IOException, ClassNotFoundException {
long id = input.readLong();
- int clen = input.readInt();
- char[] content = new char[clen];
- for(int i=0; i<clen; i++) {
- content[i]=input.readChar();
- }
-
- int llen = input.readInt();
- String lang = null;
- if(llen > 0) {
- char[] lb = new char[llen];
- for(int i=0; i<llen; i++) {
- lb[i] = input.readChar();
- }
- lang = new String(lb);
- }
+
+ String content = DataIO.readString(input);
+ String lang = DataIO.readString(input);
KiWiUriResource dtype = (KiWiUriResource) input.readObject();
Date created = new Date(input.readLong());
- KiWiStringLiteral r = new KiWiStringLiteral(new String(content), lang != null ? Locale.forLanguageTag(lang) : null, dtype, created);
+ KiWiStringLiteral r = new KiWiStringLiteral(content, lang != null ? Locale.forLanguageTag(lang) : null, dtype, created);
r.setId(id);
return r;
http://git-wip-us.apache.org/repos/asf/marmotta/blob/27a9c265/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/TripleExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/TripleExternalizer.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/TripleExternalizer.java
index 05e6933..60793c1 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/TripleExternalizer.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/TripleExternalizer.java
@@ -18,6 +18,7 @@
package org.apache.marmotta.kiwi.externalizer;
import org.apache.commons.lang3.StringUtils;
+import org.apache.marmotta.commons.io.DataIO;
import org.apache.marmotta.kiwi.model.rdf.KiWiNode;
import org.apache.marmotta.kiwi.model.rdf.KiWiResource;
import org.apache.marmotta.kiwi.model.rdf.KiWiTriple;
@@ -49,7 +50,7 @@ public class TripleExternalizer implements AdvancedExternalizer<KiWiTriple> {
@Override
public Integer getId() {
- return 13;
+ return ExternalizerIds.TRIPLE;
}
@Override
@@ -64,19 +65,16 @@ public class TripleExternalizer implements AdvancedExternalizer<KiWiTriple> {
String prefix = StringUtils.getCommonPrefix(sUri,oUri);
output.writeByte(MODE_PREFIX);
- output.writeInt(prefix.length());
- output.writeChars(prefix);
+ DataIO.writeString(output,prefix);
output.writeLong(object.getSubject().getId());
- output.writeInt(sUri.length() - prefix.length());
- output.writeChars(sUri.substring(prefix.length()));
+ DataIO.writeString(output, sUri.substring(prefix.length()));
output.writeLong(object.getSubject().getCreated().getTime());
output.writeObject(object.getPredicate());
output.writeLong(object.getObject().getId());
- output.writeInt(oUri.length() - prefix.length());
- output.writeChars(oUri.substring(prefix.length()));
+ DataIO.writeString(output, oUri.substring(prefix.length()));
output.writeLong(object.getObject().getCreated().getTime());
} else {
output.writeByte(MODE_DEFAULT);
@@ -105,15 +103,33 @@ public class TripleExternalizer implements AdvancedExternalizer<KiWiTriple> {
KiWiTriple result = new KiWiTriple();
result.setId(input.readLong());
- int mode = input.readInt();
+ int mode = input.readByte();
if(mode == MODE_PREFIX) {
- String prefix =
- }
-
+ String prefix = DataIO.readString(input);
+
+ long sId = input.readLong();
+ String sUri = prefix + DataIO.readString(input);
+ long sTime = input.readLong();
+ KiWiUriResource s = new KiWiUriResource(sUri);
+ s.setId(sId);
+ s.setCreated(new Date(sTime));
+ result.setSubject(s);
+
+ result.setPredicate((KiWiUriResource) input.readObject());
+
+ long oId = input.readLong();
+ String oUri = prefix + DataIO.readString(input);
+ long oTime = input.readLong();
+ KiWiUriResource o = new KiWiUriResource(oUri);
+ o.setId(oId);
+ o.setCreated(new Date(oTime));
+ result.setObject(o);
- result.setSubject((KiWiResource) input.readObject());
- result.setPredicate((KiWiUriResource) input.readObject());
- result.setObject((KiWiNode) input.readObject());
+ } else {
+ result.setSubject((KiWiResource) input.readObject());
+ result.setPredicate((KiWiUriResource) input.readObject());
+ result.setObject((KiWiNode) input.readObject());
+ }
result.setContext((KiWiResource) input.readObject());
result.setCreator((KiWiResource) input.readObject());
result.setDeleted(input.readBoolean());
http://git-wip-us.apache.org/repos/asf/marmotta/blob/27a9c265/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/UriExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/UriExternalizer.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/UriExternalizer.java
index 0daee45..3db4d4e 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/UriExternalizer.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/UriExternalizer.java
@@ -17,9 +17,12 @@
package org.apache.marmotta.kiwi.externalizer;
+import org.apache.marmotta.commons.io.DataIO;
+import org.apache.marmotta.commons.vocabulary.XSD;
import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
import org.infinispan.commons.marshall.AdvancedExternalizer;
import org.infinispan.commons.util.Util;
+import org.openrdf.model.vocabulary.*;
import java.io.IOException;
import java.io.ObjectInput;
@@ -34,6 +37,15 @@ import java.util.Set;
*/
public class UriExternalizer implements AdvancedExternalizer<KiWiUriResource> {
+ private static final int PREFIX_UNKNOWN = 0;
+ private static final int PREFIX_XSD = 1;
+ private static final int PREFIX_RDF = 2;
+ private static final int PREFIX_RDFS = 3;
+ private static final int PREFIX_SKOS = 4;
+ private static final int PREFIX_DC = 5;
+ private static final int PREFIX_DCT = 6;
+ private static final int PREFIX_OWL = 7;
+
@Override
public Set<Class<? extends KiWiUriResource>> getTypeClasses() {
return Util.<Class<? extends KiWiUriResource>>asSet(KiWiUriResource.class);
@@ -47,26 +59,78 @@ public class UriExternalizer implements AdvancedExternalizer<KiWiUriResource> {
@Override
public void writeObject(ObjectOutput output, KiWiUriResource object) throws IOException {
output.writeLong(object.getId());
- output.writeInt(object.stringValue().length());
- output.writeChars(object.stringValue());
+
+ // compression for commonly used constant prefixes
+ if(object.stringValue().startsWith(XSD.NAMESPACE)) {
+ output.writeByte(PREFIX_XSD);
+ DataIO.writeString(output, object.stringValue().substring(XSD.NAMESPACE.length()));
+ } else if(object.stringValue().startsWith(RDF.NAMESPACE)) {
+ output.writeByte(PREFIX_RDF);
+ DataIO.writeString(output, object.stringValue().substring(RDF.NAMESPACE.length()));
+ } else if(object.stringValue().startsWith(RDFS.NAMESPACE)) {
+ output.writeByte(PREFIX_RDFS);
+ DataIO.writeString(output, object.stringValue().substring(RDFS.NAMESPACE.length()));
+ } else if(object.stringValue().startsWith(SKOS.NAMESPACE)) {
+ output.writeByte(PREFIX_SKOS);
+ DataIO.writeString(output, object.stringValue().substring(SKOS.NAMESPACE.length()));
+ } else if(object.stringValue().startsWith(DC.NAMESPACE)) {
+ output.writeByte(PREFIX_DC);
+ DataIO.writeString(output, object.stringValue().substring(DC.NAMESPACE.length()));
+ } else if(object.stringValue().startsWith(DCTERMS.NAMESPACE)) {
+ output.writeByte(PREFIX_DCT);
+ DataIO.writeString(output, object.stringValue().substring(DCTERMS.NAMESPACE.length()));
+ } else if(object.stringValue().startsWith(OWL.NAMESPACE)) {
+ output.writeByte(PREFIX_OWL);
+ DataIO.writeString(output, object.stringValue().substring(OWL.NAMESPACE.length()));
+ } else {
+ output.writeByte(PREFIX_UNKNOWN);
+ DataIO.writeString(output, object.stringValue());
+ }
+
output.writeLong(object.getCreated().getTime());
}
@Override
public KiWiUriResource readObject(ObjectInput input) throws IOException, ClassNotFoundException {
long id = input.readLong();
- int len = input.readInt();
- char[] uri = new char[len];
- for(int i=0; i<len; i++) {
- uri[i] = input.readChar();
+ int prefixMode = input.readByte();
+ String uriPrefix = "";
+ String uriSuffix = DataIO.readString(input);
+
+ switch (prefixMode) {
+ case PREFIX_XSD:
+ uriPrefix = XSD.NAMESPACE;
+ break;
+ case PREFIX_RDF:
+ uriPrefix = RDF.NAMESPACE;
+ break;
+ case PREFIX_RDFS:
+ uriPrefix = RDFS.NAMESPACE;
+ break;
+ case PREFIX_SKOS:
+ uriPrefix = SKOS.NAMESPACE;
+ break;
+ case PREFIX_DC:
+ uriPrefix = DC.NAMESPACE;
+ break;
+ case PREFIX_DCT:
+ uriPrefix = DCTERMS.NAMESPACE;
+ break;
+ case PREFIX_OWL:
+ uriPrefix = OWL.NAMESPACE;
+ break;
+ default:
+ uriPrefix = "";
+ break;
}
Date created = new Date(input.readLong());
- KiWiUriResource r = new KiWiUriResource(new String(uri),created);
+ KiWiUriResource r = new KiWiUriResource(uriPrefix + uriSuffix,created);
r.setId(id);
return r;
}
+
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/27a9c265/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/ExternalizerTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/ExternalizerTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/ExternalizerTest.java
new file mode 100644
index 0000000..74f63d2
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/ExternalizerTest.java
@@ -0,0 +1,228 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.test;
+
+import org.apache.commons.lang3.RandomStringUtils;
+import org.apache.marmotta.commons.vocabulary.XSD;
+import org.apache.marmotta.kiwi.externalizer.*;
+import org.apache.marmotta.kiwi.model.rdf.*;
+import org.infinispan.commons.marshall.AdvancedExternalizer;
+import org.infinispan.commons.marshall.StreamingMarshaller;
+import org.infinispan.configuration.cache.CacheMode;
+import org.infinispan.configuration.cache.Configuration;
+import org.infinispan.configuration.cache.ConfigurationBuilder;
+import org.infinispan.configuration.global.GlobalConfiguration;
+import org.infinispan.configuration.global.GlobalConfigurationBuilder;
+import org.infinispan.manager.DefaultCacheManager;
+import org.infinispan.manager.EmbeddedCacheManager;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.openrdf.model.Value;
+import org.openrdf.model.ValueFactory;
+import org.openrdf.model.vocabulary.OWL;
+import org.openrdf.model.vocabulary.RDFS;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.*;
+import java.util.Random;
+
+/**
+ * Test the different externalizer implementations we provide for Infinispan
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class ExternalizerTest {
+
+ private static ValueFactory valueFactory = new TestValueFactory();
+
+ private static Random rnd = new Random();
+
+ private static Logger log = LoggerFactory.getLogger(ExternalizerTest.class);
+
+ private static StreamingMarshaller marshaller;
+
+
+ @BeforeClass
+ public static void setup() {
+ AdvancedExternalizer[] externalizers = new AdvancedExternalizer[] {
+ new UriExternalizer(),
+ new BNodeExternalizer(),
+ new StringLiteralExternalizer(),
+ new DateLiteralExternalizer(),
+ new BooleanLiteralExternalizer(),
+ new IntLiteralExternalizer(),
+ new DoubleLiteralExternalizer(),
+ new TripleExternalizer()
+ };
+
+
+ GlobalConfiguration globalConfiguration = new GlobalConfigurationBuilder()
+ .transport()
+ .defaultTransport()
+ .serialization()
+ .addAdvancedExternalizer(externalizers)
+ .build();
+
+ Configuration defaultConfiguration = new ConfigurationBuilder()
+ .clustering()
+ .cacheMode(CacheMode.DIST_ASYNC)
+ .build();
+
+ EmbeddedCacheManager cacheManager = new DefaultCacheManager(globalConfiguration, defaultConfiguration, true);
+
+ marshaller = cacheManager.getCache().getAdvancedCache().getComponentRegistry().getCacheMarshaller();
+
+ }
+
+
+ @Test
+ public void testUriResource() throws Exception {
+ marshall((KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8)), new UriExternalizer());
+ }
+
+ @Test
+ public void testCompressedUriResource() throws Exception {
+ marshall((KiWiUriResource) valueFactory.createURI(XSD.Double.stringValue()), new UriExternalizer());
+ marshall((KiWiUriResource) valueFactory.createURI(RDFS.LABEL.stringValue()), new UriExternalizer());
+ marshall((KiWiUriResource) valueFactory.createURI(OWL.SAMEAS.stringValue()), new UriExternalizer());
+ }
+
+
+ @Test
+ public void testBNode() throws Exception {
+ marshall((KiWiAnonResource) valueFactory.createBNode(), new BNodeExternalizer());
+ }
+
+ @Test
+ public void testStringLiteral() throws Exception {
+ marshall((KiWiStringLiteral) valueFactory.createLiteral(RandomStringUtils.randomAscii(40)), new StringLiteralExternalizer());
+ }
+
+ @Test
+ public void testLangLiteral() throws Exception {
+ marshall((KiWiStringLiteral) valueFactory.createLiteral(RandomStringUtils.randomAscii(40),"en"), new StringLiteralExternalizer());
+ }
+
+ @Test
+ public void testTypeLiteral() throws Exception {
+ marshall((KiWiStringLiteral) valueFactory.createLiteral(RandomStringUtils.randomAscii(40),valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8))), new StringLiteralExternalizer());
+ }
+
+
+ @Test
+ public void testIntLiteral() throws Exception {
+ marshall((KiWiIntLiteral) valueFactory.createLiteral(rnd.nextInt()), new IntLiteralExternalizer());
+ }
+
+
+ @Test
+ public void testTriple() throws Exception {
+ KiWiUriResource s = (KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
+ KiWiUriResource p = (KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
+ KiWiNode o = (KiWiNode) randomNode();
+ KiWiTriple t = (KiWiTriple) valueFactory.createStatement(s,p,o);
+
+ marshall(t, new TripleExternalizer());
+ }
+
+ @Test
+ public void testPrefixCompressedTriple() throws Exception {
+ KiWiUriResource s = (KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
+ KiWiUriResource p = (KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
+ KiWiUriResource o = (KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
+ KiWiTriple t = (KiWiTriple) valueFactory.createStatement(s,p,o);
+
+ marshall(t, new TripleExternalizer());
+ }
+
+
+ /**
+ * Run the given object through the marshaller using an in-memory stream.
+ * @param origin
+ * @param <T>
+ * @return
+ */
+ private <T> void marshall(T origin, AdvancedExternalizer<T> externalizer) throws IOException, ClassNotFoundException, InterruptedException {
+ log.info("- testing Java ObjectStream ...");
+ ByteArrayOutputStream outBytesOS = new ByteArrayOutputStream();
+ ObjectOutputStream outOS = new ObjectOutputStream(outBytesOS);
+
+ outOS.writeObject(origin);
+
+ outOS.close();
+
+ log.info(" object {}: serialized with {} bytes", origin, outBytesOS.size());
+
+
+ log.info("- testing externalizer directly ...");
+ ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream(outBytes);
+
+ externalizer.writeObject(out, origin);
+ out.close();
+
+ log.info(" object {}: serialized with {} bytes", origin, outBytes.size());
+
+ ByteArrayInputStream inBytes = new ByteArrayInputStream(outBytes.toByteArray());
+ ObjectInputStream in = new ObjectInputStream(inBytes);
+
+ T destination1 = externalizer.readObject(in);
+
+ Assert.assertEquals(origin,destination1);
+
+ log.info("- testing externalizer with infinispan marshaller ...");
+
+ byte[] bytes = marshaller.objectToByteBuffer(origin);
+ log.info(" object {}: serialized with {} bytes", origin, bytes.length);
+
+ Object destination2 = marshaller.objectFromByteBuffer(bytes);
+
+ Assert.assertEquals(origin, destination2);
+
+ }
+
+
+ /**
+ * Return a random RDF value, either a reused object (10% chance) or of any other kind.
+ * @return
+ */
+ protected Value randomNode() {
+ Value object;
+ switch(rnd.nextInt(6)) {
+ case 0: object = valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
+ break;
+ case 1: object = valueFactory.createBNode();
+ break;
+ case 2: object = valueFactory.createLiteral(RandomStringUtils.randomAscii(40));
+ break;
+ case 3: object = valueFactory.createLiteral(rnd.nextInt());
+ break;
+ case 4: object = valueFactory.createLiteral(rnd.nextDouble());
+ break;
+ case 5: object = valueFactory.createLiteral(rnd.nextBoolean());
+ break;
+ default: object = valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
+ break;
+
+ }
+ return object;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/27a9c265/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/externalizer/ExternalizerTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/externalizer/ExternalizerTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/externalizer/ExternalizerTest.java
deleted file mode 100644
index 9f52813..0000000
--- a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/externalizer/ExternalizerTest.java
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.kiwi.test.externalizer;
-
-import org.apache.commons.lang3.RandomStringUtils;
-import org.apache.marmotta.kiwi.externalizer.*;
-import org.apache.marmotta.kiwi.model.rdf.*;
-import org.apache.marmotta.kiwi.test.TestValueFactory;
-import org.infinispan.commons.marshall.AdvancedExternalizer;
-import org.infinispan.commons.marshall.StreamingMarshaller;
-import org.infinispan.configuration.cache.CacheMode;
-import org.infinispan.configuration.cache.Configuration;
-import org.infinispan.configuration.cache.ConfigurationBuilder;
-import org.infinispan.configuration.global.GlobalConfiguration;
-import org.infinispan.configuration.global.GlobalConfigurationBuilder;
-import org.infinispan.manager.DefaultCacheManager;
-import org.infinispan.manager.EmbeddedCacheManager;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.openrdf.model.Value;
-import org.openrdf.model.ValueFactory;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.*;
-import java.util.Random;
-
-/**
- * Test the different externalizer implementations we provide for Infinispan
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class ExternalizerTest {
-
- private static ValueFactory valueFactory = new TestValueFactory();
-
- private static Random rnd = new Random();
-
- private static Logger log = LoggerFactory.getLogger(ExternalizerTest.class);
-
- private static StreamingMarshaller marshaller;
-
-
- @BeforeClass
- public static void setup() {
- AdvancedExternalizer[] externalizers = new AdvancedExternalizer[] {
- new UriExternalizer(),
- new BNodeExternalizer(),
- new StringLiteralExternalizer(),
- new DateLiteralExternalizer(),
- new BooleanLiteralExternalizer(),
- new IntLiteralExternalizer(),
- new DoubleLiteralExternalizer()
- };
-
-
- GlobalConfiguration globalConfiguration = new GlobalConfigurationBuilder()
- .transport()
- .defaultTransport()
- .serialization()
- .addAdvancedExternalizer(externalizers)
- .build();
-
- Configuration defaultConfiguration = new ConfigurationBuilder()
- .clustering()
- .cacheMode(CacheMode.DIST_ASYNC)
- .build();
-
- EmbeddedCacheManager cacheManager = new DefaultCacheManager(globalConfiguration, defaultConfiguration, true);
-
- marshaller = cacheManager.getCache().getAdvancedCache().getComponentRegistry().getCacheMarshaller();
-
- }
-
-
- @Test
- public void testUriResource() throws Exception {
- marshall((KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8)), new UriExternalizer());
- }
-
- @Test
- public void testBNode() throws Exception {
- marshall((KiWiAnonResource) valueFactory.createBNode(), new BNodeExternalizer());
- }
-
- @Test
- public void testStringLiteral() throws Exception {
- marshall((KiWiStringLiteral) valueFactory.createLiteral(RandomStringUtils.randomAscii(40)), new StringLiteralExternalizer());
- }
-
- @Test
- public void testLangLiteral() throws Exception {
- marshall((KiWiStringLiteral) valueFactory.createLiteral(RandomStringUtils.randomAscii(40),"en"), new StringLiteralExternalizer());
- }
-
- @Test
- public void testTypeLiteral() throws Exception {
- marshall((KiWiStringLiteral) valueFactory.createLiteral(RandomStringUtils.randomAscii(40),valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8))), new StringLiteralExternalizer());
- }
-
-
- @Test
- public void testIntLiteral() throws Exception {
- marshall((KiWiIntLiteral) valueFactory.createLiteral(rnd.nextInt()), new IntLiteralExternalizer());
- }
-
-
- @Test
- public void testTriple() throws Exception {
- KiWiUriResource s = (KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
- KiWiUriResource p = (KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
- KiWiNode o = (KiWiNode) randomNode();
- KiWiTriple t = (KiWiTriple) valueFactory.createStatement(s,p,o);
-
- marshall(t, new TripleExternalizer());
- }
-
- /**
- * Run the given object through the marshaller using an in-memory stream.
- * @param origin
- * @param <T>
- * @return
- */
- private <T> void marshall(T origin, AdvancedExternalizer<T> externalizer) throws IOException, ClassNotFoundException, InterruptedException {
- log.info("- testing Java ObjectStream ...");
- ByteArrayOutputStream outBytesOS = new ByteArrayOutputStream();
- ObjectOutputStream outOS = new ObjectOutputStream(outBytesOS);
-
- outOS.writeObject(origin);
-
- outOS.close();
-
- log.info(" object {}: serialized with {} bytes", origin, outBytesOS.size());
-
-
- log.info("- testing externalizer directly ...");
- ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
- ObjectOutputStream out = new ObjectOutputStream(outBytes);
-
- externalizer.writeObject(out, origin);
- out.close();
-
- log.info(" object {}: serialized with {} bytes", origin, outBytes.size());
-
- ByteArrayInputStream inBytes = new ByteArrayInputStream(outBytes.toByteArray());
- ObjectInputStream in = new ObjectInputStream(inBytes);
-
- T destination1 = externalizer.readObject(in);
-
- Assert.assertEquals(origin,destination1);
-
- log.info("- testing externalizer with infinispan marshaller ...");
-
- byte[] bytes = marshaller.objectToByteBuffer(origin);
- log.info(" object {}: serialized with {} bytes", origin, bytes.length);
-
- Object destination2 = marshaller.objectFromByteBuffer(bytes);
-
- Assert.assertEquals(origin, destination2);
-
- }
-
-
- /**
- * Return a random RDF value, either a reused object (10% chance) or of any other kind.
- * @return
- */
- protected Value randomNode() {
- Value object;
- switch(rnd.nextInt(6)) {
- case 0: object = valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
- break;
- case 1: object = valueFactory.createBNode();
- break;
- case 2: object = valueFactory.createLiteral(RandomStringUtils.randomAscii(40));
- break;
- case 3: object = valueFactory.createLiteral(rnd.nextInt());
- break;
- case 4: object = valueFactory.createLiteral(rnd.nextDouble());
- break;
- case 5: object = valueFactory.createLiteral(rnd.nextBoolean());
- break;
- default: object = valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
- break;
-
- }
- return object;
- }
-
-}
[10/21] git commit: - added cache cluster test for Infinispan
Posted by ss...@apache.org.
- added cache cluster test for Infinispan
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/4cc2d1de
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/4cc2d1de
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/4cc2d1de
Branch: refs/heads/MARMOTTA-450
Commit: 4cc2d1de9b856f4a2d3f4df31c9e4f99a01e1e31
Parents: 62c44de
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Mon Mar 3 22:35:17 2014 +0100
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Mon Mar 3 22:35:17 2014 +0100
----------------------------------------------------------------------
.../kiwi/test/InfinispanClusterTest.java | 37 ++++++++++++++++++++
.../kiwi/test/cluster/BaseClusterTest.java | 2 +-
2 files changed, 38 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/4cc2d1de/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/InfinispanClusterTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/InfinispanClusterTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/InfinispanClusterTest.java
new file mode 100644
index 0000000..0522262
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/InfinispanClusterTest.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.test;
+
+import org.apache.marmotta.kiwi.caching.CacheManagerType;
+import org.apache.marmotta.kiwi.test.cluster.BaseClusterTest;
+import org.junit.BeforeClass;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class InfinispanClusterTest extends BaseClusterTest {
+
+
+ @BeforeClass
+ public static void setup() {
+ ClusterTestSupport s = new ClusterTestSupport(CacheManagerType.INFINISPAN_CLUSTERED);
+ s.setup();
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/4cc2d1de/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/cluster/BaseClusterTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/cluster/BaseClusterTest.java b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/cluster/BaseClusterTest.java
index 4733aa9..f23bfc4 100644
--- a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/cluster/BaseClusterTest.java
+++ b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/cluster/BaseClusterTest.java
@@ -110,7 +110,7 @@ public abstract class BaseClusterTest {
CacheManagerType type;
- protected ClusterTestSupport(CacheManagerType type) {
+ public ClusterTestSupport(CacheManagerType type) {
this.type = type;
}
[16/21] git commit: fix the remaining triple store components so they
properly use the modularized caching system
Posted by ss...@apache.org.
fix the remaining triple store components so they properly use the modularized caching system
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/b25a2549
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/b25a2549
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/b25a2549
Branch: refs/heads/MARMOTTA-450
Commit: b25a254972dd86edef57e7d1ff78a73b26818e39
Parents: d46c684
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Tue Mar 4 21:04:56 2014 +0100
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Tue Mar 4 21:04:56 2014 +0100
----------------------------------------------------------------------
libraries/kiwi/kiwi-caching/pom.xml | 197 --------
.../config/KiWiQueryCacheConfiguration.java | 69 ---
.../caching/iteration/BufferingIteration.java | 118 -----
.../caching/iteration/CachingIteration.java | 136 -----
.../kiwi/caching/sail/KiWiCachingSail.java | 164 ------
.../caching/sail/KiWiCachingSailConnection.java | 503 -------------------
.../GeronimoTransactionManagerLookup.java | 46 --
.../KiWiCachingRepositoryConnectionTest.java | 64 ---
.../caching/test/KiWiCachingRepositoryTest.java | 61 ---
.../persistence/KiWiReasoningConnection.java | 7 +-
.../persistence/KiWiVersioningConnection.java | 4 +-
libraries/kiwi/pom.xml | 1 -
12 files changed, 5 insertions(+), 1365 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/b25a2549/libraries/kiwi/kiwi-caching/pom.xml
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching/pom.xml b/libraries/kiwi/kiwi-caching/pom.xml
deleted file mode 100644
index d7bd8e0..0000000
--- a/libraries/kiwi/kiwi-caching/pom.xml
+++ /dev/null
@@ -1,197 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one or more
- ~ contributor license agreements. See the NOTICE file distributed with
- ~ this work for additional information regarding copyright ownership.
- ~ The ASF licenses this file to You under the Apache License, Version 2.0
- ~ (the "License"); you may not use this file except in compliance with
- ~ the License. You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License.
- -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.apache.marmotta</groupId>
- <artifactId>kiwi-parent</artifactId>
- <version>3.2.0-SNAPSHOT</version>
- <relativePath>../</relativePath>
- </parent>
-
- <artifactId>kiwi-caching</artifactId>
- <packaging>jar</packaging>
-
- <name>KiWi Triplestore: Caching</name>
- <description>
- Provides transparent query caching on top of the KiWi triplestore. Queries are cached using the Infinispan
- distributed caching system using the EmbeddedCacheManager used by the triplestore itself.
- </description>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.marmotta</groupId>
- <artifactId>kiwi-triplestore</artifactId>
- </dependency>
- <dependency>
- <groupId>org.infinispan</groupId>
- <artifactId>infinispan-core</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.geronimo.components</groupId>
- <artifactId>geronimo-transaction</artifactId>
- <version>3.1.1</version>
-
- <exclusions>
- <exclusion>
- <groupId>org.apache.geronimo.ext.tomcat</groupId>
- <artifactId>juli</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.apache.geronimo.ext.tomcat</groupId>
- <artifactId>util</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.apache.geronimo.specs</groupId>
- <artifactId>geronimo-servlet_3.0_spec</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.apache.geronimo.specs</groupId>
- <artifactId>geronimo-jta_1.1_spec</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
-
-
- <!-- Logging -->
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>log4j-over-slf4j</artifactId>
- </dependency>
-
- <!-- Sesame dependencies -->
- <dependency>
- <groupId>org.openrdf.sesame</groupId>
- <artifactId>sesame-model</artifactId>
- </dependency>
- <dependency>
- <groupId>org.openrdf.sesame</groupId>
- <artifactId>sesame-sail-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.openrdf.sesame</groupId>
- <artifactId>sesame-repository-sail</artifactId>
- </dependency>
-
- <!-- Utilities -->
- <dependency>
- <groupId>com.google.guava</groupId>
- <artifactId>guava</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.marmotta</groupId>
- <artifactId>marmotta-commons</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.marmotta</groupId>
- <artifactId>marmotta-util-filter</artifactId>
- </dependency>
- <dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- </dependency>
-
-
- <!-- Testing -->
- <dependency>
- <artifactId>junit</artifactId>
- <groupId>junit</groupId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.marmotta</groupId>
- <artifactId>kiwi-triplestore</artifactId>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
- <dependency>
- <artifactId>hamcrest-core</artifactId>
- <groupId>org.hamcrest</groupId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <artifactId>hamcrest-library</artifactId>
- <groupId>org.hamcrest</groupId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-core</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-classic</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>com.h2database</groupId>
- <artifactId>h2</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.postgresql</groupId>
- <artifactId>postgresql</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <scope>test</scope>
- <optional>true</optional> <!-- GPL licensed, no dependency -->
- </dependency>
- <dependency>
- <groupId>org.openrdf.sesame</groupId>
- <artifactId>sesame-rio-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.openrdf.sesame</groupId>
- <artifactId>sesame-rio-rdfxml</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.openrdf.sesame</groupId>
- <artifactId>sesame-queryparser-api</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.openrdf.sesame</groupId>
- <artifactId>sesame-queryparser-sparql</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.openrdf.sesame</groupId>
- <artifactId>sesame-store-testsuite</artifactId>
- <scope>test</scope>
- </dependency>
-
- </dependencies>
-
-</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/marmotta/blob/b25a2549/libraries/kiwi/kiwi-caching/src/main/java/org/apache/marmotta/kiwi/caching/config/KiWiQueryCacheConfiguration.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching/src/main/java/org/apache/marmotta/kiwi/caching/config/KiWiQueryCacheConfiguration.java b/libraries/kiwi/kiwi-caching/src/main/java/org/apache/marmotta/kiwi/caching/config/KiWiQueryCacheConfiguration.java
deleted file mode 100644
index 518e82e..0000000
--- a/libraries/kiwi/kiwi-caching/src/main/java/org/apache/marmotta/kiwi/caching/config/KiWiQueryCacheConfiguration.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.kiwi.caching.config;
-
-/**
- * Configuration object for all query caching options that are configurable.
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class KiWiQueryCacheConfiguration {
-
-
- /**
- * Maximum size of results to cache. Results bigger than this value will not be cached.
- */
- private int maxEntrySize = 150;
-
-
- /**
- * Maximum number of entries to keep in the cache.
- */
- private int maxCacheSize = 100000;
-
- public KiWiQueryCacheConfiguration() {
- }
-
- /**
- * Maximum size of results to cache. Results bigger than this value will not be cached.
- */
- public int getMaxEntrySize() {
- return maxEntrySize;
- }
-
- /**
- * Maximum size of results to cache. Results bigger than this value will not be cached.
- */
- public void setMaxEntrySize(int maxEntrySize) {
- this.maxEntrySize = maxEntrySize;
- }
-
- /**
- * Maximum number of entries to keep in the cache.
- */
- public int getMaxCacheSize() {
- return maxCacheSize;
- }
-
- /**
- * Maximum number of entries to keep in the cache.
- */
- public void setMaxCacheSize(int maxCacheSize) {
- this.maxCacheSize = maxCacheSize;
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/b25a2549/libraries/kiwi/kiwi-caching/src/main/java/org/apache/marmotta/kiwi/caching/iteration/BufferingIteration.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching/src/main/java/org/apache/marmotta/kiwi/caching/iteration/BufferingIteration.java b/libraries/kiwi/kiwi-caching/src/main/java/org/apache/marmotta/kiwi/caching/iteration/BufferingIteration.java
deleted file mode 100644
index a0d02ff..0000000
--- a/libraries/kiwi/kiwi-caching/src/main/java/org/apache/marmotta/kiwi/caching/iteration/BufferingIteration.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.kiwi.caching.iteration;
-
-import info.aduna.iteration.CloseableIteration;
-import info.aduna.iteration.CloseableIterationBase;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * An iterator that buffers iteration results up to a configurable limit.
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class BufferingIteration<E,X extends Exception> extends CloseableIterationBase<E,X> implements CloseableIteration<E,X> {
-
- private int limit = 150;
-
- private List<E> buffer;
-
- private CloseableIteration<? extends E,X> wrapped;
-
- public BufferingIteration(int limit, CloseableIteration<? extends E, X> wrapped) {
- this.limit = limit;
-
- this.wrapped = wrapped;
- this.buffer = new ArrayList<>(limit);
- }
-
- /**
- * Returns <tt>true</tt> if the iteration has more elements. (In other
- * words, returns <tt>true</tt> if {@link #next} would return an element
- * rather than throwing a <tt>NoSuchElementException</tt>.)
- *
- * @return <tt>true</tt> if the iteration has more elements.
- * @throws X
- */
- @Override
- public boolean hasNext() throws X {
- return wrapped.hasNext();
- }
-
- /**
- * Returns the next element in the iteration.
- *
- * @return the next element in the iteration.
- */
- @Override
- public E next() throws X {
- E n = wrapped.next();
-
- if(buffer != null && buffer.size() < limit) {
- buffer.add(n);
- } else {
- buffer = null;
- }
-
- return n;
- }
-
- /**
- * Removes from the underlying collection the last element returned by the
- * iteration (optional operation). This method can be called only once per
- * call to next.
- *
- * @throws UnsupportedOperationException if the remove operation is not supported by this Iteration.
- * @throws IllegalStateException If the Iteration has been closed, or if <tt>next()</tt> has not
- * yet been called, or <tt>remove()</tt> has already been called
- * after the last call to <tt>next()</tt>.
- */
- @Override
- public void remove() throws X {
- wrapped.remove();
- buffer.remove(buffer.size() - 1);
- }
-
- /**
- * Called by {@link #close} when it is called for the first time. This method
- * is only called once on each iteration. By default, this method does
- * nothing.
- *
- * @throws X
- */
- @Override
- protected void handleClose() throws X {
-
- super.handleClose();
- }
-
- /**
- * Return the buffer contents (or null if the buffer has reached its limit)
- *
- * @return
- */
- public List<E> getBuffer() {
- return buffer;
- }
-
- public int getLimit() {
- return limit;
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/b25a2549/libraries/kiwi/kiwi-caching/src/main/java/org/apache/marmotta/kiwi/caching/iteration/CachingIteration.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching/src/main/java/org/apache/marmotta/kiwi/caching/iteration/CachingIteration.java b/libraries/kiwi/kiwi-caching/src/main/java/org/apache/marmotta/kiwi/caching/iteration/CachingIteration.java
deleted file mode 100644
index 255ac00..0000000
--- a/libraries/kiwi/kiwi-caching/src/main/java/org/apache/marmotta/kiwi/caching/iteration/CachingIteration.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.kiwi.caching.iteration;
-
-import info.aduna.iteration.CloseableIteration;
-import info.aduna.iteration.CloseableIterationBase;
-import info.aduna.iteration.CloseableIteratorIteration;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.List;
-
-/**
- * Add file description here!
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class CachingIteration<E,X extends Exception> extends CloseableIterationBase<E,X> implements CloseableIteration<E,X> {
-
- private static Logger log = LoggerFactory.getLogger(CachingIteration.class);
-
- private CloseableIteration<E,X> wrapped;
-
- private CacheFunction<E> cacheFunction;
-
- public CachingIteration(CacheFunction<E> cacheFunction,BufferingIterationProducer<E, X> producer) throws X {
-
- this.cacheFunction = cacheFunction;
-
- List<E> cached = cacheFunction.getResult();
- if(cached != null) {
- log.debug("cache hit, using iterator over cached result (size={})!", cached.size());
- this.wrapped = new CloseableIteratorIteration<>(cached.iterator());
- } else {
- log.debug("cache miss, querying backend!");
- this.wrapped = producer.getIteration();
- }
- }
-
- /**
- * Returns <tt>true</tt> if the iteration has more elements. (In other
- * words, returns <tt>true</tt> if {@link #next} would return an element
- * rather than throwing a <tt>NoSuchElementException</tt>.)
- *
- * @return <tt>true</tt> if the iteration has more elements.
- * @throws X
- */
- @Override
- public boolean hasNext() throws X {
- return wrapped.hasNext();
- }
-
- /**
- * Returns the next element in the iteration.
- *
- * @return the next element in the iteration.
- */
- @Override
- public E next() throws X {
- return wrapped.next();
- }
-
- /**
- * Removes from the underlying collection the last element returned by the
- * iteration (optional operation). This method can be called only once per
- * call to next.
- *
- * @throws UnsupportedOperationException if the remove operation is not supported by this Iteration.
- * @throws IllegalStateException If the Iteration has been closed, or if <tt>next()</tt> has not
- * yet been called, or <tt>remove()</tt> has already been called
- * after the last call to <tt>next()</tt>.
- */
- @Override
- public void remove() throws X {
- wrapped.remove();
- }
-
- /**
- * Called by {@link #close} when it is called for the first time. This method
- * is only called once on each iteration. By default, this method does
- * nothing.
- *
- * @throws X
- */
- @Override
- protected void handleClose() throws X {
- if(wrapped instanceof BufferingIteration && ((BufferingIteration) wrapped).getBuffer() != null) {
- cacheFunction.cacheResult(((BufferingIteration) wrapped).getBuffer());
- }
-
- super.handleClose();
- }
-
-
- public static interface BufferingIterationProducer<E,X extends Exception> {
-
- /**
- * This method should lazily create the iteration wrapped by this caching iteration.
- * @return
- */
- public BufferingIteration<E,X> getIteration() throws X;
-
- }
-
-
- public static interface CacheFunction<E> {
-
- /**
- * Return the cached result for this iteration (or null in case there is no cached result)
- */
- public List<E> getResult();
-
- /**
- * Cache the result of this iteration.
- *
- * @param buffer
- */
- public void cacheResult(List<E> buffer);
-
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/b25a2549/libraries/kiwi/kiwi-caching/src/main/java/org/apache/marmotta/kiwi/caching/sail/KiWiCachingSail.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching/src/main/java/org/apache/marmotta/kiwi/caching/sail/KiWiCachingSail.java b/libraries/kiwi/kiwi-caching/src/main/java/org/apache/marmotta/kiwi/caching/sail/KiWiCachingSail.java
deleted file mode 100644
index fbc7289..0000000
--- a/libraries/kiwi/kiwi-caching/src/main/java/org/apache/marmotta/kiwi/caching/sail/KiWiCachingSail.java
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.kiwi.caching.sail;
-
-import org.apache.marmotta.kiwi.caching.config.KiWiQueryCacheConfiguration;
-import org.apache.marmotta.kiwi.caching.transaction.GeronimoTransactionManagerLookup;
-import org.apache.marmotta.kiwi.sail.KiWiStore;
-import org.infinispan.Cache;
-import org.infinispan.configuration.cache.CacheMode;
-import org.infinispan.configuration.cache.Configuration;
-import org.infinispan.configuration.cache.ConfigurationBuilder;
-import org.infinispan.configuration.cache.VersioningScheme;
-import org.infinispan.context.Flag;
-import org.infinispan.distribution.ch.SyncConsistentHashFactory;
-import org.infinispan.manager.EmbeddedCacheManager;
-import org.infinispan.transaction.TransactionMode;
-import org.infinispan.util.concurrent.IsolationLevel;
-import org.openrdf.sail.NotifyingSail;
-import org.openrdf.sail.NotifyingSailConnection;
-import org.openrdf.sail.Sail;
-import org.openrdf.sail.SailException;
-import org.openrdf.sail.helpers.NotifyingSailWrapper;
-import org.openrdf.sail.helpers.SailWrapper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.concurrent.TimeUnit;
-
-/**
- * A sail wrapper for KiWi stores that introduces transparent query caching using Infinispan distributed caches.
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class KiWiCachingSail extends NotifyingSailWrapper {
-
- public static final String QUERY_CACHE = "query-cache";
-
- private static Logger log = LoggerFactory.getLogger(KiWiCachingSail.class);
-
- private KiWiStore parent;
-
-
- private EmbeddedCacheManager cacheManager;
-
- private KiWiQueryCacheConfiguration configuration;
-
- /**
- * Creates a new SailWrapper that wraps the supplied Sail.
- *
- * @param baseSail
- */
- public KiWiCachingSail(NotifyingSail baseSail, KiWiQueryCacheConfiguration configuration) {
- super(baseSail);
-
- this.parent = getRootSail(baseSail);
- this.configuration = configuration;
- }
-
-
- @Override
- public void initialize() throws SailException {
- super.initialize();
-
- this.cacheManager = parent.getPersistence().getCacheManager().getCacheManager();
- }
-
- @Override
- public NotifyingSailConnection getConnection() throws SailException {
- return new KiWiCachingSailConnection(super.getConnection(), getQueryCache(), configuration.getMaxEntrySize());
- }
-
-
-
- /**
- * Return the query key -> query result cache from the cache manager. This cache is used for speeding up the
- * listing of query results.
- *
- * @return
- */
- private Cache getQueryCache() {
- if(!cacheManager.cacheExists(QUERY_CACHE)) {
- if(parent.getPersistence().getConfiguration().isClustered()) {
- Configuration tripleConfiguration = new ConfigurationBuilder()
- .clustering()
- .cacheMode(CacheMode.DIST_SYNC)
- .sync()
- .replTimeout(60, TimeUnit.SECONDS)
- .hash()
- .numOwners(2)
- .numSegments(40)
- .consistentHashFactory(new SyncConsistentHashFactory())
- .transaction()
- .transactionMode(TransactionMode.TRANSACTIONAL)
- .transactionManagerLookup(new GeronimoTransactionManagerLookup())
- .cacheStopTimeout(1, TimeUnit.SECONDS)
- .locking()
- .isolationLevel(IsolationLevel.READ_COMMITTED)
- .concurrencyLevel(5)
- .versioning()
- .enabled(true)
- .scheme(VersioningScheme.SIMPLE)
- .eviction()
- .maxEntries(configuration.getMaxCacheSize())
- .expiration()
- .lifespan(60, TimeUnit.MINUTES)
- .maxIdle(30, TimeUnit.MINUTES)
- .build();
- cacheManager.defineConfiguration(QUERY_CACHE, tripleConfiguration);
- } else {
- Configuration tripleConfiguration = new ConfigurationBuilder().read(cacheManager.getDefaultCacheConfiguration())
- .transaction()
- .transactionMode(TransactionMode.TRANSACTIONAL)
- .transactionManagerLookup(new GeronimoTransactionManagerLookup())
- .cacheStopTimeout(1, TimeUnit.SECONDS)
- .locking()
- .isolationLevel(IsolationLevel.READ_COMMITTED)
- .concurrencyLevel(5)
- .versioning()
- .enabled(true)
- .scheme(VersioningScheme.SIMPLE)
- .eviction()
- .maxEntries(configuration.getMaxCacheSize())
- .expiration()
- .lifespan(60, TimeUnit.MINUTES)
- .maxIdle(30, TimeUnit.MINUTES)
- .build();
- cacheManager.defineConfiguration(QUERY_CACHE, tripleConfiguration);
- }
- }
- return cacheManager.getCache(QUERY_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
- }
-
-
- /**
- * Get the root sail in the wrapped sail stack
- * @param sail
- * @return
- */
- private KiWiStore getRootSail(Sail sail) {
- if(sail instanceof KiWiStore) {
- return (KiWiStore) sail;
- } else if(sail instanceof SailWrapper) {
- return getRootSail(((SailWrapper) sail).getBaseSail());
- } else {
- throw new IllegalArgumentException("root sail is not a KiWiStore or could not be found");
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/b25a2549/libraries/kiwi/kiwi-caching/src/main/java/org/apache/marmotta/kiwi/caching/sail/KiWiCachingSailConnection.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching/src/main/java/org/apache/marmotta/kiwi/caching/sail/KiWiCachingSailConnection.java b/libraries/kiwi/kiwi-caching/src/main/java/org/apache/marmotta/kiwi/caching/sail/KiWiCachingSailConnection.java
deleted file mode 100644
index d1dc908..0000000
--- a/libraries/kiwi/kiwi-caching/src/main/java/org/apache/marmotta/kiwi/caching/sail/KiWiCachingSailConnection.java
+++ /dev/null
@@ -1,503 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.kiwi.caching.sail;
-
-import com.google.common.base.Function;
-import com.google.common.collect.Lists;
-import info.aduna.iteration.CloseableIteration;
-import info.aduna.iteration.Iteration;
-import info.aduna.iteration.UnionIteration;
-import org.apache.geronimo.transaction.manager.TransactionImpl;
-import org.apache.marmotta.commons.sesame.tripletable.IntArray;
-import org.apache.marmotta.kiwi.caching.iteration.BufferingIteration;
-import org.apache.marmotta.kiwi.caching.iteration.CachingIteration;
-import org.apache.marmotta.kiwi.model.rdf.KiWiTriple;
-import org.apache.marmotta.kiwi.persistence.KiWiConnection;
-import org.apache.marmotta.kiwi.sail.KiWiSailConnection;
-import org.infinispan.Cache;
-import org.openrdf.model.Resource;
-import org.openrdf.model.Statement;
-import org.openrdf.model.URI;
-import org.openrdf.model.Value;
-import org.openrdf.model.impl.URIImpl;
-import org.openrdf.sail.NotifyingSailConnection;
-import org.openrdf.sail.SailConnection;
-import org.openrdf.sail.SailConnectionListener;
-import org.openrdf.sail.SailException;
-import org.openrdf.sail.helpers.NotifyingSailConnectionWrapper;
-import org.openrdf.sail.helpers.SailConnectionWrapper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.transaction.*;
-import java.nio.IntBuffer;
-import java.sql.SQLException;
-import java.util.*;
-
-/**
- * A sail connection with Infinispan caching support. It will dynamically cache getStatements results up to a certain
- * result size and invalidate the cache on updates.
- *
- * <p/>
- * Since Infinispan uses JTA for transaction management, we need to align Sesame transactions with JTA. JTA transactions
- * are associated per-thread, while Sesame transactions are per-connection. This makes this combination a bit tricky:
- * every time a relevant method on the sesame connection is called we need to suspend the existing thread transaction
- * and resume the connection that is associated with the connection.
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class KiWiCachingSailConnection extends NotifyingSailConnectionWrapper implements SailConnectionListener {
-
- private static Logger log = LoggerFactory.getLogger(KiWiCachingSailConnection.class);
-
- private Cache<Long,long[]> queryCache;
-
- // a dummy default context to work around the double meaning of the null value
- private final static URI defaultContext = new URIImpl("http://marmotta.apache.org/contexts/default");
-
- private int limit = 150;
-
- private Transaction tx;
-
- private long connectionId;
-
- private static long connectionIdCounter = 0;
-
- private KiWiConnection kiWiConnection;
-
- public KiWiCachingSailConnection(NotifyingSailConnection wrappedCon, Cache<Long, long[]> queryCache, int limit) {
- super(wrappedCon);
-
- this.queryCache = queryCache;
- this.limit = limit;
- this.kiWiConnection = getKiWiConnection(wrappedCon);
-
- this.addConnectionListener(this);
-
- connectionId = ++connectionIdCounter;
-
- }
-
-
- @Override
- public CloseableIteration<? extends Statement, SailException> getStatements(final Resource subj, final URI pred, final Value obj, final boolean includeInferred, final Resource... contexts) throws SailException {
- if(tx != null) {
- log.debug("CONN({}) LIST: listing statements for transaction: {}", connectionId, ((TransactionImpl) tx).getTransactionKey());
- } else {
- log.debug("CONN({}) LIST: listing statements (no transaction)", connectionId);
- }
- List<Iteration<? extends Statement, SailException>> cResults = new ArrayList<>(contexts.length + 1);
- for(final Resource context : resolveContexts(contexts)) {
- cResults.add(new CachingIteration<>(
- new CachingIteration.CacheFunction<Statement>() {
- @Override
- public List<Statement> getResult() {
- return listTriples(subj,pred,obj,context, includeInferred);
- }
-
- @Override
- public void cacheResult(List<Statement> buffer) {
- log.debug("CONN({}) CACHE: caching result for query ({},{},{},{},{}): {}", connectionId, subj, pred, obj, context, includeInferred, buffer);
- cacheTriples(subj, pred, obj, context, includeInferred, buffer);
- }
- },
- new CachingIteration.BufferingIterationProducer<Statement, SailException>() {
- @Override
- public BufferingIteration<Statement, SailException> getIteration() throws SailException {
- return new BufferingIteration<>(limit, KiWiCachingSailConnection.super.getStatements(subj, pred, obj, includeInferred, contexts));
- }
- }
- ));
- }
-
- return new UnionIteration<Statement, SailException>(cResults);
-
- }
-
-
- /**
- * Notifies the listener that a statement has been added in a transaction
- * that it has registered itself with.
- *
- * @param st The statement that was added.
- */
- @Override
- public void statementAdded(Statement st) {
- resumeTransaction();
- log.debug("CONN({}) ADD: updating cache for statement {} (transaction: {})", connectionId, st, ((TransactionImpl) tx).getTransactionKey());
- if(st.getContext() == null) {
- tripleUpdated(st.getSubject(), st.getPredicate(), st.getObject(), Collections.singleton((Resource)defaultContext));
- } else {
- tripleUpdated(st.getSubject(), st.getPredicate(), st.getObject(), Collections.singleton(st.getContext()));
- }
- }
-
- /**
- * Notifies the listener that a statement has been removed in a transaction
- * that it has registered itself with.
- *
- * @param st The statement that was removed.
- */
- @Override
- public void statementRemoved(Statement st) {
- log.debug("CONN({}) DEL: updating cache for statement {} (transaction: {})", connectionId, st, ((TransactionImpl)tx).getTransactionKey());
- resumeTransaction();
- if(st.getContext() == null) {
- tripleUpdated(st.getSubject(), st.getPredicate(), st.getObject(), Collections.singleton((Resource)defaultContext));
- } else {
- tripleUpdated(st.getSubject(), st.getPredicate(), st.getObject(), Collections.singleton(st.getContext()));
- }
- }
-
- @Override
- public void begin() throws SailException {
- super.begin();
-
- resumeTransaction();
- }
-
- @Override
- public void commit() throws SailException {
- TransactionManager txmgr = queryCache.getAdvancedCache().getTransactionManager();
- try {
- resumeTransaction();
- log.debug("CONN({}) COMMIT: transaction: {}", connectionId, ((TransactionImpl) tx).getTransactionKey());
- txmgr.commit();
- closeTransaction();
- } catch (RollbackException | HeuristicMixedException | HeuristicRollbackException | SystemException e) {
- log.error("error committing cache transaction: ", e);
- }
-
- super.commit();
- }
-
- @Override
- public void rollback() throws SailException {
- TransactionManager txmgr = queryCache.getAdvancedCache().getTransactionManager();
- try {
- resumeTransaction();
- txmgr.rollback();
- closeTransaction();
- } catch (SystemException e) {
- log.error("error rolling back cache transaction: ",e);
- }
-
- super.rollback();
- }
-
- @Override
- public void close() throws SailException {
- closeTransaction();
-
- super.close();
- }
-
- private void resumeTransaction() {
- TransactionManager txmgr = queryCache.getAdvancedCache().getTransactionManager();
- try {
- // cases:
- // 1. there is a transaction in this connection, the transaction is active, and associated with the current
- // thread -> nothing to do
- // 2. there is a transaction in this connection, the transaction is active, bit another transactionis
- // associated with the current thread -> suspend thread transaction, resume connection transaction
- // 3. there is no transaction in this connection, or the transaction in this connection is invalid
- // -> create and start new transaction
- if(tx != null && tx.getStatus() == Status.STATUS_ACTIVE && txmgr.getTransaction() == tx) {
- log.debug("CONN({}) RESUME: using active transaction: {}, status {}", connectionId, ((TransactionImpl)tx).getTransactionKey(), tx.getStatus());
- } else if(tx != null && tx.getStatus() == Status.STATUS_ACTIVE && txmgr.getTransaction() != tx) {
- txmgr.suspend();
- txmgr.resume(tx);
-
- log.debug("CONN({}) RESUME: resumed transaction: {}, status {}", connectionId, ((TransactionImpl)tx).getTransactionKey(), tx.getStatus());
- } else {
- if(txmgr.getTransaction() != null) {
- Transaction old = txmgr.suspend();
- log.debug("CONN({}) BEGIN: suspended transaction not belonging to this connection: {}", connectionId, ((TransactionImpl)old).getTransactionKey());
- }
- txmgr.begin();
- tx = txmgr.getTransaction();
-
- log.debug("CONN({}) BEGIN: created and started new transaction: {}", connectionId, ((TransactionImpl)tx).getTransactionKey());
-
- }
-
-
- } catch (NotSupportedException | SystemException | InvalidTransactionException e) {
- log.error("error resuming transaction");
- }
- }
-
- private void closeTransaction() {
- TransactionManager txmgr = queryCache.getAdvancedCache().getTransactionManager();
- try {
- if(tx != null && txmgr.getTransaction() == tx) {
- log.debug("CONN({}) CLOSE: closing transaction: {}", connectionId, ((TransactionImpl)tx).getTransactionKey());
- if(tx.getStatus() == Status.STATUS_ACTIVE) {
- tx.commit();
- }
- txmgr.suspend();
- tx = null;
- }
- } catch (RollbackException | HeuristicMixedException | HeuristicRollbackException | SystemException e) {
- log.error("error while closing transaction", e);
- }
- }
-
- private List<Resource> resolveContexts(Resource... contexts) {
- if(contexts.length == 0) {
- return Collections.singletonList((Resource) defaultContext);
- } else {
- return Lists.newArrayList(contexts);
- }
- }
-
- /**
- * Look up a triple query in the query cache. Returns the result set if the query is found in the cache, returns
- * null if the query is not found.
- *
- * @param subject the subject of the triples to list or null for wildcard
- * @param property the property of the triples to list or null for wildcard
- * @param object the object of the triples to list or null for wildcard
- * @param context the context/knowledge space of the triples to list or null for all spaces
- * @param inferred if true, inferred triples are included in the result; if false not
- * @return the result set if the query is found in the cache, returns null if the query is not found
- */
- @SuppressWarnings("unchecked")
- private List<Statement> listTriples(Resource subject, URI property, Value object, Resource context, boolean inferred) {
- boolean implicitTx = tx == null;
- resumeTransaction();
-
- IntArray key = createCacheKey(subject,property,object,context,inferred);
- try {
- long[] ids = queryCache.get(key.longHashCode());
- if(ids == null) {
- return null;
- } else {
- ArrayList<Statement> statements = new ArrayList<>(ids.length);
- for(long id : ids) {
- try {
- statements.add(kiWiConnection.loadTripleById(id));
- } catch (SQLException e) {
- log.warn("could not load triple from database: {}",id);
- }
- }
- return statements;
- }
- } finally {
- if(implicitTx) {
- closeTransaction();
- }
- }
- }
-
-
- /**
- * Cache the result of a triple query in the query cache.
- *
- * @param subject the subject of the triples to list or null for wildcard
- * @param property the property of the triples to list or null for wildcard
- * @param object the object of the triples to list or null for wildcard
- * @param context the context/knowledge space of the triples to list or null for all spaces
- * @param inferred if true, inferred triples are included in the result; if false not
- * @param result the result of the triple query to cache
- */
- private void cacheTriples(final Resource subject, final URI property, final Value object, final Resource context, boolean inferred, List<Statement> result) {
- boolean implicitTx = tx == null;
-
- resumeTransaction();
-
- try {
- // cache the query result
- IntArray key = createCacheKey(subject,property,object,context,inferred);
- long[] data = new long[result.size()];
- for(int i=0; i<result.size(); i++) {
- Statement stmt = result.get(i);
- if(stmt instanceof KiWiTriple) {
- data[i] = ((KiWiTriple) stmt).getId();
- }
- }
- queryCache.put(key.longHashCode(), data);
-
- // cache the nodes of the triples and the triples themselves
- Set<Value> nodes = new HashSet<Value>();
- for(Statement stmt : result) {
- if(stmt instanceof KiWiTriple) {
- KiWiTriple triple = (KiWiTriple)stmt;
- Collections.addAll(nodes, new Value[]{triple.getSubject(), triple.getObject(), triple.getPredicate(), triple.getContext()});
- queryCache.put(createCacheKey(triple.getSubject(), triple.getPredicate(), triple.getObject(), triple.getContext(), triple.isInferred()).longHashCode(), new long[] {triple.getId()});
- }
- }
-
- // special optimisation: when only the subject (and optionally context) is given, we also fill the caches for
- // all property values
- if(subject != null && property == null && object == null) {
- HashMap<URI,ArrayList<Long>> properties = new HashMap<>();
- for(Statement triple : result) {
- ArrayList<Long> values = properties.get(triple.getPredicate());
- if(values == null) {
- values = new ArrayList<>();
- properties.put(triple.getPredicate(),values);
- }
- if(triple instanceof KiWiTriple) {
- values.add(((KiWiTriple) triple).getId());
- }
- }
- for(Map.Entry<URI,ArrayList<Long>> entry : properties.entrySet()) {
- IntArray key2 = createCacheKey(subject,entry.getKey(),null,context,inferred);
- long[] dvalues = new long[entry.getValue().size()];
- for(int i=0; i<entry.getValue().size(); i++) {
- dvalues[i] = entry.getValue().get(i);
- }
- queryCache.put(key2.longHashCode(), dvalues);
- }
- }
-
- } finally {
- if(implicitTx) {
- closeTransaction();
- }
- }
-
- }
-
-
-
-
- /**
- * Clear all contents of the query cache.
- */
- private void clearAll() {
- queryCache.clear();
- }
-
-
- /**
- * Notify the cache that the triple passed as argument has been updated and that all cache entries affected by
- * the triple update need to be cleared.
- *
- */
- private void tripleUpdated(Resource subject, URI predicate, Value object, Iterable<Resource> contexts) {
- queryCache.remove(createCacheKey(null, null, null, null, false).longHashCode());
- queryCache.remove(createCacheKey(null,null,null,null,true).longHashCode());
-
- queryCache.remove(createCacheKey(null,null,null,defaultContext,false).longHashCode());
- queryCache.remove(createCacheKey(null,null,null,defaultContext,true).longHashCode());
-
-
- // remove all possible combinations of this triple as they may appear in the cache
- queryCache.remove(createCacheKey(subject,null,null,null,false).longHashCode());
- queryCache.remove(createCacheKey(subject,null,null,null,true).longHashCode());
- queryCache.remove(createCacheKey(null,predicate,null,null,false).longHashCode());
- queryCache.remove(createCacheKey(null,predicate,null,null,true).longHashCode());
- queryCache.remove(createCacheKey(null,null,object,null,false).longHashCode());
- queryCache.remove(createCacheKey(null,null,object,null,true).longHashCode());
-
- queryCache.remove(createCacheKey(subject,predicate,null,null,false).longHashCode());
- queryCache.remove(createCacheKey(subject,predicate,null,null,true).longHashCode());
- queryCache.remove(createCacheKey(subject,null,object,null,false).longHashCode());
- queryCache.remove(createCacheKey(subject,null,object,null,true).longHashCode());
- queryCache.remove(createCacheKey(null,predicate,object,null,false).longHashCode());
- queryCache.remove(createCacheKey(null,predicate,object,null,true).longHashCode());
-
-
- queryCache.remove(createCacheKey(subject,predicate,object,null,false).longHashCode());
- queryCache.remove(createCacheKey(subject,predicate,object,null,true).longHashCode());
-
- for(Resource context : contexts) {
- queryCache.remove(createCacheKey(null,null,null,context,false).longHashCode());
- queryCache.remove(createCacheKey(null,null,null,context,true).longHashCode());
- queryCache.remove(createCacheKey(subject,null,null,context,false).longHashCode());
- queryCache.remove(createCacheKey(subject,null,null,context,true).longHashCode());
- queryCache.remove(createCacheKey(null,predicate,null,context,false).longHashCode());
- queryCache.remove(createCacheKey(null,predicate,null,context,true).longHashCode());
- queryCache.remove(createCacheKey(null,null,object,context,false).longHashCode());
- queryCache.remove(createCacheKey(null,null,object,context,true).longHashCode());
-
- queryCache.remove(createCacheKey(subject,predicate,null,context,false).longHashCode());
- queryCache.remove(createCacheKey(subject,predicate,null,context,true).longHashCode());
- queryCache.remove(createCacheKey(subject,null,object,context,false).longHashCode());
- queryCache.remove(createCacheKey(subject,null,object,context,true).longHashCode());
- queryCache.remove(createCacheKey(null,predicate,object,context,false).longHashCode());
- queryCache.remove(createCacheKey(null,predicate,object,context,true).longHashCode());
-
- queryCache.remove(createCacheKey(subject,predicate,object,context,false).longHashCode());
- queryCache.remove(createCacheKey(subject,predicate,object,context,true).longHashCode());
- }
- }
-
-
- private static IntArray createCacheKey(Resource subject, URI property, Value object, Resource context, boolean inferred){
-
- // the cache key is generated by appending the bytes of the hashcodes of subject, property, object, context and inferred and
- // storing them as a BigInteger; generating the cache key should thus be very efficient
-
- int s = subject != null ? subject.hashCode() : Integer.MIN_VALUE;
- int p = property != null ? property.hashCode() : Integer.MIN_VALUE;
- int o = object != null ? object.hashCode() : Integer.MIN_VALUE;
- int c = context != null ? context.hashCode() : Integer.MIN_VALUE;
-
- IntBuffer bb = IntBuffer.allocate(5);
- bb.put(s);
- bb.put(p);
- bb.put(o);
- bb.put(c);
- bb.put( (byte) (inferred ? 1 : 0) );
-
- return new IntArray(bb.array());
-
- }
-
-
- /**
- * Get the root sail in the wrapped sail stack
- * @param sail
- * @return
- */
- private KiWiConnection getKiWiConnection(SailConnection sail) {
- if(sail instanceof KiWiSailConnection) {
- return ((KiWiSailConnection) sail).getDatabaseConnection();
- } else if(sail instanceof SailConnectionWrapper) {
- return getKiWiConnection(((SailConnectionWrapper) sail).getWrappedConnection());
- } else {
- throw new IllegalArgumentException("root sail connection is not a KiWiSailConnection or could not be found");
- }
- }
-
- private class IDTripleLoader implements Function<Long,Statement> {
- @Override
- public Statement apply(Long input) {
- try {
- return kiWiConnection.loadTripleById(input);
- } catch (SQLException e) {
- log.error("could not load triple with ID {}", input);
- throw new RuntimeException(e);
- }
- }
- }
-
- private class IDTripleExtractor implements Function<Statement,Long> {
- @Override
- public Long apply(Statement input) {
- if(input instanceof KiWiTriple) {
- return ((KiWiTriple) input).getId();
- } else {
- return -1L;
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/b25a2549/libraries/kiwi/kiwi-caching/src/main/java/org/apache/marmotta/kiwi/caching/transaction/GeronimoTransactionManagerLookup.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching/src/main/java/org/apache/marmotta/kiwi/caching/transaction/GeronimoTransactionManagerLookup.java b/libraries/kiwi/kiwi-caching/src/main/java/org/apache/marmotta/kiwi/caching/transaction/GeronimoTransactionManagerLookup.java
deleted file mode 100644
index ad35473..0000000
--- a/libraries/kiwi/kiwi-caching/src/main/java/org/apache/marmotta/kiwi/caching/transaction/GeronimoTransactionManagerLookup.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.kiwi.caching.transaction;
-
-import org.apache.geronimo.transaction.manager.GeronimoTransactionManager;
-import org.infinispan.transaction.lookup.TransactionManagerLookup;
-
-import javax.transaction.TransactionManager;
-
-/**
- * Add file description here!
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class GeronimoTransactionManagerLookup implements TransactionManagerLookup {
-
- private TransactionManager manager;
-
- /**
- * Returns a new TransactionManager.
- *
- * @throws Exception if lookup failed
- */
- @Override
- public TransactionManager getTransactionManager() throws Exception {
- if(manager == null) {
- manager = new GeronimoTransactionManager();
- }
- return manager;
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/b25a2549/libraries/kiwi/kiwi-caching/src/test/java/org/apache/marmotta/kiwi/caching/test/KiWiCachingRepositoryConnectionTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching/src/test/java/org/apache/marmotta/kiwi/caching/test/KiWiCachingRepositoryConnectionTest.java b/libraries/kiwi/kiwi-caching/src/test/java/org/apache/marmotta/kiwi/caching/test/KiWiCachingRepositoryConnectionTest.java
deleted file mode 100644
index bce1eb4..0000000
--- a/libraries/kiwi/kiwi-caching/src/test/java/org/apache/marmotta/kiwi/caching/test/KiWiCachingRepositoryConnectionTest.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.kiwi.caching.test;
-
-import org.apache.marmotta.kiwi.caching.config.KiWiQueryCacheConfiguration;
-import org.apache.marmotta.kiwi.caching.sail.KiWiCachingSail;
-import org.apache.marmotta.kiwi.config.KiWiConfiguration;
-import org.apache.marmotta.kiwi.sail.KiWiStore;
-import org.apache.marmotta.kiwi.test.junit.KiWiDatabaseRunner;
-import org.junit.Ignore;
-import org.junit.runner.RunWith;
-import org.openrdf.repository.Repository;
-import org.openrdf.repository.RepositoryConnectionTest;
-import org.openrdf.repository.sail.SailRepository;
-
-/**
- * Run the {@link RepositoryConnectionTest}s.
- * @author Jakob Frank <ja...@apache.org>
- *
- */
-@RunWith(KiWiDatabaseRunner.class)
-public class KiWiCachingRepositoryConnectionTest extends RepositoryConnectionTest {
-
- private final KiWiConfiguration config;
-
- public KiWiCachingRepositoryConnectionTest(KiWiConfiguration config) {
- this.config = config;
- }
-
- /* (non-Javadoc)
- * @see org.openrdf.repository.RepositoryConnectionTest#createRepository()
- */
- @Override
- protected Repository createRepository() throws Exception {
- config.setDefaultContext(null);
- KiWiStore store = new KiWiStore(config);
- store.setDropTablesOnShutdown(true);
-
- KiWiCachingSail cache = new KiWiCachingSail(store, new KiWiQueryCacheConfiguration());
- return new SailRepository(cache);
- }
-
-
- @Override
- @Ignore
- public void testGetStatementsInMultipleContexts() throws Exception {
- // this test is not working, because the cache can return duplicates
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/b25a2549/libraries/kiwi/kiwi-caching/src/test/java/org/apache/marmotta/kiwi/caching/test/KiWiCachingRepositoryTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching/src/test/java/org/apache/marmotta/kiwi/caching/test/KiWiCachingRepositoryTest.java b/libraries/kiwi/kiwi-caching/src/test/java/org/apache/marmotta/kiwi/caching/test/KiWiCachingRepositoryTest.java
deleted file mode 100644
index 9b13279..0000000
--- a/libraries/kiwi/kiwi-caching/src/test/java/org/apache/marmotta/kiwi/caching/test/KiWiCachingRepositoryTest.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.kiwi.caching.test;
-
-import org.apache.marmotta.kiwi.caching.config.KiWiQueryCacheConfiguration;
-import org.apache.marmotta.kiwi.caching.sail.KiWiCachingSail;
-import org.apache.marmotta.kiwi.config.KiWiConfiguration;
-import org.apache.marmotta.kiwi.sail.KiWiStore;
-import org.apache.marmotta.kiwi.test.junit.KiWiDatabaseRunner;
-import org.junit.runner.RunWith;
-import org.openrdf.repository.Repository;
-import org.openrdf.repository.RepositoryTest;
-import org.openrdf.repository.sail.SailRepository;
-
-/**
- * Run the {@link RepositoryTest}s.
- * @author Jakob Frank <ja...@apache.org>
- *
- */
-@RunWith(KiWiDatabaseRunner.class)
-public class KiWiCachingRepositoryTest extends RepositoryTest {
-
- private final KiWiConfiguration config;
-
- private KiWiStore store;
-
- public KiWiCachingRepositoryTest(KiWiConfiguration config) {
- this.config = config;
- }
-
- /* (non-Javadoc)
- * @see org.openrdf.repository.RepositoryTest#createRepository()
- */
- @Override
- protected Repository createRepository() throws Exception {
- store = new KiWiStore(config);
- KiWiCachingSail cache = new KiWiCachingSail(store, new KiWiQueryCacheConfiguration());
- return new SailRepository(cache);
- }
-
- @Override
- public void tearDown() throws Exception {
- store.getPersistence().dropDatabase();
- super.tearDown();
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/b25a2549/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/persistence/KiWiReasoningConnection.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/persistence/KiWiReasoningConnection.java b/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/persistence/KiWiReasoningConnection.java
index 67459e5..4688696 100644
--- a/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/persistence/KiWiReasoningConnection.java
+++ b/libraries/kiwi/kiwi-reasoner/src/main/java/org/apache/marmotta/kiwi/reasoner/persistence/KiWiReasoningConnection.java
@@ -18,7 +18,7 @@
package org.apache.marmotta.kiwi.reasoner.persistence;
import info.aduna.iteration.*;
-import org.apache.marmotta.kiwi.caching.KiWiCacheManager;
+import org.apache.marmotta.kiwi.caching.CacheManager;
import org.apache.marmotta.kiwi.model.rdf.KiWiNode;
import org.apache.marmotta.kiwi.model.rdf.KiWiTriple;
import org.apache.marmotta.kiwi.persistence.KiWiConnection;
@@ -30,7 +30,6 @@ import org.apache.marmotta.kiwi.reasoner.model.program.*;
import org.apache.marmotta.kiwi.reasoner.model.query.QueryResult;
import org.apache.marmotta.kiwi.reasoner.parser.KWRLProgramParser;
import org.apache.marmotta.kiwi.reasoner.parser.ParseException;
-import org.infinispan.Cache;
import org.openrdf.model.ValueFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -53,9 +52,9 @@ public class KiWiReasoningConnection extends KiWiConnection {
private ValueFactory valueFactory;
- private Cache<Long,Rule> ruleIdCache;
+ private Map<Long,Rule> ruleIdCache;
- public KiWiReasoningConnection(KiWiPersistence persistence, KiWiDialect dialect, KiWiCacheManager cacheManager, ValueFactory valueFactory) throws SQLException {
+ public KiWiReasoningConnection(KiWiPersistence persistence, KiWiDialect dialect, CacheManager cacheManager, ValueFactory valueFactory) throws SQLException {
super(persistence, dialect, cacheManager);
this.valueFactory = valueFactory;
http://git-wip-us.apache.org/repos/asf/marmotta/blob/b25a2549/libraries/kiwi/kiwi-versioning/src/main/java/org/apache/marmotta/kiwi/versioning/persistence/KiWiVersioningConnection.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-versioning/src/main/java/org/apache/marmotta/kiwi/versioning/persistence/KiWiVersioningConnection.java b/libraries/kiwi/kiwi-versioning/src/main/java/org/apache/marmotta/kiwi/versioning/persistence/KiWiVersioningConnection.java
index 844a0be..49716e9 100644
--- a/libraries/kiwi/kiwi-versioning/src/main/java/org/apache/marmotta/kiwi/versioning/persistence/KiWiVersioningConnection.java
+++ b/libraries/kiwi/kiwi-versioning/src/main/java/org/apache/marmotta/kiwi/versioning/persistence/KiWiVersioningConnection.java
@@ -21,7 +21,7 @@ import com.google.common.base.Preconditions;
import info.aduna.iteration.CloseableIteration;
import info.aduna.iteration.EmptyIteration;
import info.aduna.iteration.ExceptionConvertingIteration;
-import org.apache.marmotta.kiwi.caching.KiWiCacheManager;
+import org.apache.marmotta.kiwi.caching.CacheManager;
import org.apache.marmotta.kiwi.model.rdf.KiWiNode;
import org.apache.marmotta.kiwi.model.rdf.KiWiResource;
import org.apache.marmotta.kiwi.model.rdf.KiWiTriple;
@@ -53,7 +53,7 @@ public class KiWiVersioningConnection extends KiWiConnection {
private static Logger log = LoggerFactory.getLogger(KiWiVersioningConnection.class);
- public KiWiVersioningConnection(KiWiPersistence persistence, KiWiDialect dialect, KiWiCacheManager cacheManager) throws SQLException {
+ public KiWiVersioningConnection(KiWiPersistence persistence, KiWiDialect dialect, CacheManager cacheManager) throws SQLException {
super(persistence, dialect, cacheManager);
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/b25a2549/libraries/kiwi/pom.xml
----------------------------------------------------------------------
diff --git a/libraries/kiwi/pom.xml b/libraries/kiwi/pom.xml
index c244567..f47b8de 100644
--- a/libraries/kiwi/pom.xml
+++ b/libraries/kiwi/pom.xml
@@ -117,7 +117,6 @@
<module>kiwi-reasoner</module>
<module>kiwi-sparql</module>
<module>kiwi-loader</module>
- <module>kiwi-caching</module>
</modules>
</project>
[11/21] - hotrod serialization with custom JBoss Marshaller
Posted by ss...@apache.org.
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2f22f5ca/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/BNodeExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/BNodeExternalizer.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/BNodeExternalizer.java
new file mode 100644
index 0000000..4bcaf40
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/BNodeExternalizer.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.infinispan.externalizer;
+
+import org.apache.marmotta.kiwi.model.rdf.KiWiAnonResource;
+import org.infinispan.commons.marshall.AdvancedExternalizer;
+import org.infinispan.commons.util.Util;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Date;
+import java.util.Set;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class BNodeExternalizer extends BaseExternalizer<KiWiAnonResource> implements AdvancedExternalizer<KiWiAnonResource> {
+
+
+ @Override
+ public Set<Class<? extends KiWiAnonResource>> getTypeClasses() {
+ return Util.<Class<? extends KiWiAnonResource>>asSet(KiWiAnonResource.class);
+ }
+
+ @Override
+ public Integer getId() {
+ return ExternalizerIds.BNODE;
+ }
+
+ @Override
+ public void writeObject(ObjectOutput output, KiWiAnonResource object) throws IOException {
+ output.writeLong(object.getId());
+ output.writeInt(object.stringValue().length());
+ output.writeChars(object.stringValue());
+ output.writeLong(object.getCreated().getTime());
+ }
+
+ @Override
+ public KiWiAnonResource readObject(ObjectInput input) throws IOException, ClassNotFoundException {
+ long id = input.readLong();
+ int len = input.readInt();
+
+ char[] anonId = new char[len];
+ for(int i=0; i<len; i++) {
+ anonId[i] = input.readChar();
+ }
+
+ Date created = new Date(input.readLong());
+
+ KiWiAnonResource r = new KiWiAnonResource(new String(anonId),created);
+ r.setId(id);
+
+ return r;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2f22f5ca/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/BaseExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/BaseExternalizer.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/BaseExternalizer.java
new file mode 100644
index 0000000..8f15a09
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/BaseExternalizer.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.infinispan.externalizer;
+
+import org.infinispan.commons.marshall.AdvancedExternalizer;
+import org.jboss.marshalling.Creator;
+import org.jboss.marshalling.Externalizer;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+/**
+ * Base class merging the functionality from JBoss Marshalling and JBoss Infinispan for externalizers
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public abstract class BaseExternalizer<T> implements Externalizer, AdvancedExternalizer<T> {
+
+
+ /**
+ * Write the external representation of an object. The object's class and the externalizer's class will
+ * already have been written.
+ *
+ * @param subject the object to externalize
+ * @param output the output
+ * @throws java.io.IOException if an error occurs
+ */
+ @Override
+ public void writeExternal(Object subject, ObjectOutput output) throws IOException {
+ writeObject(output, (T)subject);
+ }
+
+ /**
+ * Create an instance of a type. The object may then be initialized from {@code input}, or that may be deferred
+ * to the {@code readExternal()} method. Instances may simply delegate the task to the given {@code Creator}.
+ * Note that this method is called only on the leaf class, so externalizers for non-final classes that initialize
+ * the instance from the stream need to be aware of this.
+ *
+ * @param subjectType the type of object to create
+ * @param input the input
+ * @param defaultCreator the configured creator
+ * @return the new instance
+ * @throws java.io.IOException if an error occurs
+ * @throws ClassNotFoundException if a class could not be found during read
+ */
+ @Override
+ public Object createExternal(Class<?> subjectType, ObjectInput input, Creator defaultCreator) throws IOException, ClassNotFoundException {
+ return readObject(input);
+ }
+
+ /**
+ * Read the external representation of an object. The object will already be instantiated, but may be uninitialized, when
+ * this method is called.
+ *
+ * @param subject the object to read
+ * @param input the input
+ * @throws java.io.IOException if an error occurs
+ * @throws ClassNotFoundException if a class could not be found during read
+ */
+ @Override
+ public void readExternal(Object subject, ObjectInput input) throws IOException, ClassNotFoundException {
+ // no-op
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2f22f5ca/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/BooleanLiteralExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/BooleanLiteralExternalizer.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/BooleanLiteralExternalizer.java
new file mode 100644
index 0000000..73793bf
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/BooleanLiteralExternalizer.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.infinispan.externalizer;
+
+import org.apache.marmotta.kiwi.model.rdf.KiWiBooleanLiteral;
+import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
+import org.infinispan.commons.marshall.AdvancedExternalizer;
+import org.infinispan.commons.util.Util;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Date;
+import java.util.Set;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class BooleanLiteralExternalizer extends BaseExternalizer<KiWiBooleanLiteral> implements AdvancedExternalizer<KiWiBooleanLiteral> {
+
+ @Override
+ public Set<Class<? extends KiWiBooleanLiteral>> getTypeClasses() {
+ return Util.<Class<? extends KiWiBooleanLiteral>>asSet(KiWiBooleanLiteral.class);
+ }
+
+ @Override
+ public Integer getId() {
+ return ExternalizerIds.BOOL_LITERAL;
+ }
+
+ @Override
+ public void writeObject(ObjectOutput output, KiWiBooleanLiteral object) throws IOException {
+ output.writeLong(object.getId());
+ output.writeBoolean(object.booleanValue());
+ output.writeObject(object.getDatatype());
+
+ output.writeLong(object.getCreated().getTime());
+
+ }
+
+ @Override
+ public KiWiBooleanLiteral readObject(ObjectInput input) throws IOException, ClassNotFoundException {
+ long id = input.readLong();
+ boolean content = input.readBoolean();
+
+ KiWiUriResource dtype = (KiWiUriResource) input.readObject();
+
+ Date created = new Date(input.readLong());
+
+ KiWiBooleanLiteral r = new KiWiBooleanLiteral(content, dtype, created);
+ r.setId(id);
+
+ return r;
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2f22f5ca/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/DateLiteralExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/DateLiteralExternalizer.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/DateLiteralExternalizer.java
new file mode 100644
index 0000000..532d70e
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/DateLiteralExternalizer.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.infinispan.externalizer;
+
+import org.apache.marmotta.kiwi.model.rdf.KiWiDateLiteral;
+import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
+import org.infinispan.commons.marshall.AdvancedExternalizer;
+import org.infinispan.commons.util.Util;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Date;
+import java.util.Set;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class DateLiteralExternalizer extends BaseExternalizer<KiWiDateLiteral> implements AdvancedExternalizer<KiWiDateLiteral> {
+
+ @Override
+ public Set<Class<? extends KiWiDateLiteral>> getTypeClasses() {
+ return Util.<Class<? extends KiWiDateLiteral>>asSet(KiWiDateLiteral.class);
+ }
+
+ @Override
+ public Integer getId() {
+ return ExternalizerIds.DATE_LITERAL;
+ }
+
+ @Override
+ public void writeObject(ObjectOutput output, KiWiDateLiteral object) throws IOException {
+ output.writeLong(object.getId());
+ output.writeLong(object.getDateContent().getTime());
+ output.writeObject(object.getDatatype());
+
+ output.writeLong(object.getCreated().getTime());
+
+ }
+
+ @Override
+ public KiWiDateLiteral readObject(ObjectInput input) throws IOException, ClassNotFoundException {
+ long id = input.readLong();
+ Date content = new Date(input.readLong());
+
+ KiWiUriResource dtype = (KiWiUriResource) input.readObject();
+
+ Date created = new Date(input.readLong());
+
+ KiWiDateLiteral r = new KiWiDateLiteral(content, dtype, created);
+ r.setId(id);
+
+ return r;
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2f22f5ca/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/DoubleLiteralExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/DoubleLiteralExternalizer.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/DoubleLiteralExternalizer.java
new file mode 100644
index 0000000..66b40f9
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/DoubleLiteralExternalizer.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.infinispan.externalizer;
+
+import org.apache.marmotta.kiwi.model.rdf.KiWiDoubleLiteral;
+import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
+import org.infinispan.commons.marshall.AdvancedExternalizer;
+import org.infinispan.commons.util.Util;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Date;
+import java.util.Set;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class DoubleLiteralExternalizer extends BaseExternalizer<KiWiDoubleLiteral> implements AdvancedExternalizer<KiWiDoubleLiteral> {
+
+ @Override
+ public Set<Class<? extends KiWiDoubleLiteral>> getTypeClasses() {
+ return Util.<Class<? extends KiWiDoubleLiteral>>asSet(KiWiDoubleLiteral.class);
+ }
+
+ @Override
+ public Integer getId() {
+ return ExternalizerIds.DOUBLE_LITERAL;
+ }
+
+ @Override
+ public void writeObject(ObjectOutput output, KiWiDoubleLiteral object) throws IOException {
+ output.writeLong(object.getId());
+ output.writeDouble(object.getDoubleContent());
+ output.writeObject(object.getDatatype());
+
+ output.writeLong(object.getCreated().getTime());
+
+ }
+
+ @Override
+ public KiWiDoubleLiteral readObject(ObjectInput input) throws IOException, ClassNotFoundException {
+ long id = input.readLong();
+ double content = input.readDouble();
+
+ KiWiUriResource dtype = (KiWiUriResource) input.readObject();
+
+ Date created = new Date(input.readLong());
+
+ KiWiDoubleLiteral r = new KiWiDoubleLiteral(content, dtype, created);
+ r.setId(id);
+
+ return r;
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2f22f5ca/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/ExternalizerIds.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/ExternalizerIds.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/ExternalizerIds.java
new file mode 100644
index 0000000..eced367
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/ExternalizerIds.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.infinispan.externalizer;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class ExternalizerIds {
+
+ public static final int TRIPLE = 13;
+
+ public static final int URI = 17;
+
+ public static final int BNODE = 23;
+
+ public static final int STRING_LITERAL = 19;
+
+ public static final int INT_LITERAL = 39;
+
+ public static final int DOUBLE_LITERAL = 37;
+
+ public static final int DATE_LITERAL = 29;
+
+ public static final int BOOL_LITERAL = 31;
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2f22f5ca/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/IntLiteralExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/IntLiteralExternalizer.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/IntLiteralExternalizer.java
new file mode 100644
index 0000000..3f2052a
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/IntLiteralExternalizer.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.infinispan.externalizer;
+
+import org.apache.marmotta.kiwi.model.rdf.KiWiIntLiteral;
+import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
+import org.infinispan.commons.marshall.AdvancedExternalizer;
+import org.infinispan.commons.util.Util;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Date;
+import java.util.Set;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class IntLiteralExternalizer extends BaseExternalizer<KiWiIntLiteral> implements AdvancedExternalizer<KiWiIntLiteral> {
+
+ @Override
+ public Set<Class<? extends KiWiIntLiteral>> getTypeClasses() {
+ return Util.<Class<? extends KiWiIntLiteral>>asSet(KiWiIntLiteral.class);
+ }
+
+ @Override
+ public Integer getId() {
+ return ExternalizerIds.INT_LITERAL;
+ }
+
+ @Override
+ public void writeObject(ObjectOutput output, KiWiIntLiteral object) throws IOException {
+ output.writeLong(object.getId());
+ output.writeLong(object.getIntContent());
+ output.writeObject(object.getDatatype());
+
+ output.writeLong(object.getCreated().getTime());
+
+ }
+
+ @Override
+ public KiWiIntLiteral readObject(ObjectInput input) throws IOException, ClassNotFoundException {
+ long id = input.readLong();
+ long content = input.readLong();
+
+ KiWiUriResource dtype = (KiWiUriResource) input.readObject();
+
+ Date created = new Date(input.readLong());
+
+ KiWiIntLiteral r = new KiWiIntLiteral(content, dtype, created);
+ r.setId(id);
+
+ return r;
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2f22f5ca/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/StringLiteralExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/StringLiteralExternalizer.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/StringLiteralExternalizer.java
new file mode 100644
index 0000000..015698c
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/StringLiteralExternalizer.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.infinispan.externalizer;
+
+import org.apache.marmotta.commons.io.DataIO;
+import org.apache.marmotta.kiwi.model.rdf.KiWiStringLiteral;
+import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
+import org.infinispan.commons.marshall.AdvancedExternalizer;
+import org.infinispan.commons.util.Util;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Date;
+import java.util.Locale;
+import java.util.Set;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class StringLiteralExternalizer extends BaseExternalizer<KiWiStringLiteral> implements AdvancedExternalizer<KiWiStringLiteral> {
+
+ @Override
+ public Set<Class<? extends KiWiStringLiteral>> getTypeClasses() {
+ return Util.<Class<? extends KiWiStringLiteral>>asSet(KiWiStringLiteral.class);
+ }
+
+ @Override
+ public Integer getId() {
+ return ExternalizerIds.STRING_LITERAL;
+ }
+
+ @Override
+ public void writeObject(ObjectOutput output, KiWiStringLiteral object) throws IOException {
+ output.writeLong(object.getId());
+
+ DataIO.writeString(output, object.getContent());
+ DataIO.writeString(output, object.getLanguage());
+
+ output.writeObject(object.getDatatype());
+
+ output.writeLong(object.getCreated().getTime());
+
+ }
+
+ @Override
+ public KiWiStringLiteral readObject(ObjectInput input) throws IOException, ClassNotFoundException {
+ long id = input.readLong();
+
+ String content = DataIO.readString(input);
+ String lang = DataIO.readString(input);
+
+ KiWiUriResource dtype = (KiWiUriResource) input.readObject();
+
+ Date created = new Date(input.readLong());
+
+ KiWiStringLiteral r = new KiWiStringLiteral(content, lang != null ? Locale.forLanguageTag(lang) : null, dtype, created);
+ r.setId(id);
+
+ return r;
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2f22f5ca/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/TripleExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/TripleExternalizer.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/TripleExternalizer.java
new file mode 100644
index 0000000..562475d
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/TripleExternalizer.java
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.infinispan.externalizer;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.marmotta.commons.io.DataIO;
+import org.apache.marmotta.kiwi.model.rdf.KiWiNode;
+import org.apache.marmotta.kiwi.model.rdf.KiWiResource;
+import org.apache.marmotta.kiwi.model.rdf.KiWiTriple;
+import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
+import org.infinispan.commons.marshall.AdvancedExternalizer;
+import org.infinispan.commons.util.Util;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Date;
+import java.util.Set;
+
+/**
+ * An externalizer for Infinispan allowing to more efficiently transport triples by only serializing the node
+ * IDs instead of the whole nodes.
+ */
+public class TripleExternalizer extends BaseExternalizer<KiWiTriple> implements AdvancedExternalizer<KiWiTriple> {
+
+
+ public static final int MODE_DEFAULT = 1;
+ public static final int MODE_PREFIX = 2;
+
+
+ @Override
+ public Set<Class<? extends KiWiTriple>> getTypeClasses() {
+ return Util.<Class<? extends KiWiTriple>>asSet(KiWiTriple.class);
+ }
+
+ @Override
+ public Integer getId() {
+ return ExternalizerIds.TRIPLE;
+ }
+
+ @Override
+ public void writeObject(ObjectOutput output, KiWiTriple object) throws IOException {
+ output.writeLong(object.getId());
+
+ // in case subject and object are both uris we use a special prefix-compressed mode
+ if(object.getSubject().isUriResource() && object.getObject().isUriResource()) {
+ String sUri = object.getSubject().stringValue();
+ String oUri = object.getObject().stringValue();
+
+ String prefix = StringUtils.getCommonPrefix(sUri,oUri);
+
+ output.writeByte(MODE_PREFIX);
+ DataIO.writeString(output,prefix);
+
+ output.writeLong(object.getSubject().getId());
+ DataIO.writeString(output, sUri.substring(prefix.length()));
+ output.writeLong(object.getSubject().getCreated().getTime());
+
+ output.writeObject(object.getPredicate());
+
+ output.writeLong(object.getObject().getId());
+ DataIO.writeString(output, oUri.substring(prefix.length()));
+ output.writeLong(object.getObject().getCreated().getTime());
+ } else {
+ output.writeByte(MODE_DEFAULT);
+
+ output.writeObject(object.getSubject());
+ output.writeObject(object.getPredicate());
+ output.writeObject(object.getObject());
+ }
+
+ output.writeObject(object.getContext());
+ output.writeObject(object.getCreator());
+ output.writeBoolean(object.isDeleted());
+ output.writeBoolean(object.isInferred());
+ output.writeBoolean(object.isNewTriple());
+ output.writeLong(object.getCreated().getTime());
+ if(object.getDeletedAt() != null) {
+ output.writeLong(object.getDeletedAt().getTime());
+ } else {
+ output.writeLong(0);
+ }
+ }
+
+ @Override
+ public KiWiTriple readObject(ObjectInput input) throws IOException, ClassNotFoundException {
+
+ KiWiTriple result = new KiWiTriple();
+ result.setId(input.readLong());
+
+ int mode = input.readByte();
+ if(mode == MODE_PREFIX) {
+ String prefix = DataIO.readString(input);
+
+ long sId = input.readLong();
+ String sUri = prefix + DataIO.readString(input);
+ long sTime = input.readLong();
+ KiWiUriResource s = new KiWiUriResource(sUri);
+ s.setId(sId);
+ s.setCreated(new Date(sTime));
+ result.setSubject(s);
+
+ result.setPredicate((KiWiUriResource) input.readObject());
+
+ long oId = input.readLong();
+ String oUri = prefix + DataIO.readString(input);
+ long oTime = input.readLong();
+ KiWiUriResource o = new KiWiUriResource(oUri);
+ o.setId(oId);
+ o.setCreated(new Date(oTime));
+ result.setObject(o);
+
+ } else {
+ result.setSubject((KiWiResource) input.readObject());
+ result.setPredicate((KiWiUriResource) input.readObject());
+ result.setObject((KiWiNode) input.readObject());
+ }
+ result.setContext((KiWiResource) input.readObject());
+ result.setCreator((KiWiResource) input.readObject());
+ result.setDeleted(input.readBoolean());
+ result.setInferred(input.readBoolean());
+ result.setNewTriple(input.readBoolean());
+
+ result.setCreated(new Date(input.readLong()));
+
+ long deletedAt = input.readLong();
+ if(deletedAt > 0) {
+ result.setDeletedAt(new Date(deletedAt));
+ }
+
+
+ return result;
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2f22f5ca/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/UriExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/UriExternalizer.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/UriExternalizer.java
new file mode 100644
index 0000000..cfd9dc2
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/UriExternalizer.java
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.infinispan.externalizer;
+
+import org.apache.marmotta.commons.io.DataIO;
+import org.apache.marmotta.commons.vocabulary.XSD;
+import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
+import org.infinispan.commons.marshall.AdvancedExternalizer;
+import org.infinispan.commons.util.Util;
+import org.openrdf.model.vocabulary.*;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Date;
+import java.util.Set;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class UriExternalizer extends BaseExternalizer<KiWiUriResource> implements AdvancedExternalizer<KiWiUriResource> {
+
+ private static final int PREFIX_UNKNOWN = 0;
+ private static final int PREFIX_XSD = 1;
+ private static final int PREFIX_RDF = 2;
+ private static final int PREFIX_RDFS = 3;
+ private static final int PREFIX_SKOS = 4;
+ private static final int PREFIX_DC = 5;
+ private static final int PREFIX_DCT = 6;
+ private static final int PREFIX_OWL = 7;
+
+ @Override
+ public Set<Class<? extends KiWiUriResource>> getTypeClasses() {
+ return Util.<Class<? extends KiWiUriResource>>asSet(KiWiUriResource.class);
+ }
+
+ @Override
+ public Integer getId() {
+ return ExternalizerIds.URI;
+ }
+
+ @Override
+ public void writeObject(ObjectOutput output, KiWiUriResource object) throws IOException {
+ output.writeLong(object.getId());
+
+ // compression for commonly used constant prefixes
+ if(object.stringValue().startsWith(XSD.NAMESPACE)) {
+ output.writeByte(PREFIX_XSD);
+ DataIO.writeString(output, object.stringValue().substring(XSD.NAMESPACE.length()));
+ } else if(object.stringValue().startsWith(RDF.NAMESPACE)) {
+ output.writeByte(PREFIX_RDF);
+ DataIO.writeString(output, object.stringValue().substring(RDF.NAMESPACE.length()));
+ } else if(object.stringValue().startsWith(RDFS.NAMESPACE)) {
+ output.writeByte(PREFIX_RDFS);
+ DataIO.writeString(output, object.stringValue().substring(RDFS.NAMESPACE.length()));
+ } else if(object.stringValue().startsWith(SKOS.NAMESPACE)) {
+ output.writeByte(PREFIX_SKOS);
+ DataIO.writeString(output, object.stringValue().substring(SKOS.NAMESPACE.length()));
+ } else if(object.stringValue().startsWith(DC.NAMESPACE)) {
+ output.writeByte(PREFIX_DC);
+ DataIO.writeString(output, object.stringValue().substring(DC.NAMESPACE.length()));
+ } else if(object.stringValue().startsWith(DCTERMS.NAMESPACE)) {
+ output.writeByte(PREFIX_DCT);
+ DataIO.writeString(output, object.stringValue().substring(DCTERMS.NAMESPACE.length()));
+ } else if(object.stringValue().startsWith(OWL.NAMESPACE)) {
+ output.writeByte(PREFIX_OWL);
+ DataIO.writeString(output, object.stringValue().substring(OWL.NAMESPACE.length()));
+ } else {
+ output.writeByte(PREFIX_UNKNOWN);
+ DataIO.writeString(output, object.stringValue());
+ }
+
+ output.writeLong(object.getCreated().getTime());
+ }
+
+ @Override
+ public KiWiUriResource readObject(ObjectInput input) throws IOException, ClassNotFoundException {
+ long id = input.readLong();
+
+ int prefixMode = input.readByte();
+ String uriPrefix = "";
+ String uriSuffix = DataIO.readString(input);
+
+ switch (prefixMode) {
+ case PREFIX_XSD:
+ uriPrefix = XSD.NAMESPACE;
+ break;
+ case PREFIX_RDF:
+ uriPrefix = RDF.NAMESPACE;
+ break;
+ case PREFIX_RDFS:
+ uriPrefix = RDFS.NAMESPACE;
+ break;
+ case PREFIX_SKOS:
+ uriPrefix = SKOS.NAMESPACE;
+ break;
+ case PREFIX_DC:
+ uriPrefix = DC.NAMESPACE;
+ break;
+ case PREFIX_DCT:
+ uriPrefix = DCTERMS.NAMESPACE;
+ break;
+ case PREFIX_OWL:
+ uriPrefix = OWL.NAMESPACE;
+ break;
+ default:
+ uriPrefix = "";
+ break;
+ }
+
+ Date created = new Date(input.readLong());
+
+ KiWiUriResource r = new KiWiUriResource(uriPrefix + uriSuffix,created);
+ r.setId(id);
+
+ return r;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2f22f5ca/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/CustomClassExternalizerFactory.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/CustomClassExternalizerFactory.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/CustomClassExternalizerFactory.java
new file mode 100644
index 0000000..d68bda5
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/CustomClassExternalizerFactory.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.infinispan.remote;
+
+import org.apache.marmotta.kiwi.infinispan.externalizer.*;
+import org.jboss.marshalling.ClassExternalizerFactory;
+import org.jboss.marshalling.Externalizer;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class CustomClassExternalizerFactory implements ClassExternalizerFactory {
+
+ Map<Class<?>,Externalizer> externalizers = new HashMap<>();
+
+ public CustomClassExternalizerFactory() {
+
+ addExternalizer(new UriExternalizer());
+ addExternalizer(new BNodeExternalizer());
+ addExternalizer(new BooleanLiteralExternalizer());
+ addExternalizer(new DateLiteralExternalizer());
+ addExternalizer(new DoubleLiteralExternalizer());
+ addExternalizer(new IntLiteralExternalizer());
+ addExternalizer(new StringLiteralExternalizer());
+ addExternalizer(new TripleExternalizer());
+
+ }
+
+ private void addExternalizer(BaseExternalizer e) {
+ for(Class c : (Set <Class>)e.getTypeClasses()) {
+ externalizers.put(c,e);
+ }
+ }
+
+ /**
+ * Look up a custom externalizer for a given object class. If no such externalizer exists, returns {@code null}.
+ *
+ * @param type the type to be externalized
+ * @return the externalizer, or {@code null} if there is none
+ */
+ @Override
+ public Externalizer getExternalizer(Class<?> type) {
+ if(externalizers.containsKey(type)) {
+ return externalizers.get(type);
+ } else {
+ return null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2f22f5ca/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/CustomClassTable.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/CustomClassTable.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/CustomClassTable.java
new file mode 100644
index 0000000..05d9283
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/CustomClassTable.java
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.infinispan.remote;
+
+import org.apache.marmotta.kiwi.infinispan.externalizer.*;
+import org.jboss.marshalling.ClassTable;
+import org.jboss.marshalling.Marshaller;
+import org.jboss.marshalling.Unmarshaller;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * A custom class table to allow for efficient serialization and deserialization of KiWi triple store objects
+ * and their externalizers.
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class CustomClassTable implements ClassTable {
+
+ Writer writer;
+
+ Map<Integer,Class> classLookup;
+ Map<Class,Integer> idLookup;
+
+
+ public CustomClassTable() {
+ classLookup = new HashMap<>();
+ idLookup = new HashMap<>();
+
+ register(new BNodeExternalizer());
+ register(new BooleanLiteralExternalizer());
+ register(new DateLiteralExternalizer());
+ register(new DoubleLiteralExternalizer());
+ register(new IntLiteralExternalizer());
+ register(new StringLiteralExternalizer());
+ register(new TripleExternalizer());
+ register(new UriExternalizer());
+
+ classLookup.put(11, BaseExternalizer.class);
+ idLookup.put(BaseExternalizer.class,11);
+
+ writer = new Writer() {
+ @Override
+ public void writeClass(Marshaller marshaller, Class<?> clazz) throws IOException {
+ marshaller.writeByte((byte) ((int)idLookup.get(clazz)));
+ }
+ };
+
+ }
+
+ private void register(BaseExternalizer e) {
+ // for each externalizer, we register the externalizer itself using its own ID, as well as the type managed
+ // by this externalizer using its ID+1 (we anyways use prime numbers for ids, so this is safe)
+
+ classLookup.put(e.getId(), e.getClass());
+ idLookup.put(e.getClass(), e.getId());
+
+ Class type = (Class) e.getTypeClasses().iterator().next();
+ classLookup.put(e.getId()+1, type);
+ idLookup.put(type,e.getId()+1);
+ }
+
+ /**
+ * Determine whether the given class reference is a valid predefined reference.
+ *
+ * @param clazz the candidate class
+ * @return the class writer, or {@code null} to use the default mechanism
+ * @throws java.io.IOException if an I/O error occurs
+ */
+ @Override
+ public Writer getClassWriter(Class<?> clazz) throws IOException {
+ if(idLookup.containsKey(clazz)) {
+ return writer;
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Read a class from the stream. The class will have been written by the
+ * {@link #getClassWriter(Class)} method's {@code Writer} instance, as defined above.
+ *
+ * @param unmarshaller the unmarshaller to read from
+ * @return the class
+ * @throws java.io.IOException if an I/O error occurs
+ * @throws ClassNotFoundException if a class could not be found
+ */
+ @Override
+ public Class<?> readClass(Unmarshaller unmarshaller) throws IOException, ClassNotFoundException {
+ int id = unmarshaller.readByte();
+
+ return classLookup.get(id);
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2f22f5ca/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/CustomJBossMarshaller.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/CustomJBossMarshaller.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/CustomJBossMarshaller.java
new file mode 100644
index 0000000..428b397
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/CustomJBossMarshaller.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.infinispan.remote;
+
+import org.infinispan.commons.marshall.jboss.AbstractJBossMarshaller;
+import org.infinispan.commons.marshall.jboss.DefaultContextClassResolver;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class CustomJBossMarshaller extends AbstractJBossMarshaller {
+
+ public CustomJBossMarshaller() {
+ super();
+ baseCfg.setClassResolver(
+ new DefaultContextClassResolver(this.getClass().getClassLoader()));
+
+ baseCfg.setClassExternalizerFactory (new CustomClassExternalizerFactory());
+ baseCfg.setClassTable(new CustomClassTable());
+ }
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2f22f5ca/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/InfinispanRemoteCacheManager.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/InfinispanRemoteCacheManager.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/InfinispanRemoteCacheManager.java
new file mode 100644
index 0000000..a4a4e38
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/InfinispanRemoteCacheManager.java
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.infinispan.remote;
+
+import org.apache.marmotta.kiwi.caching.CacheManager;
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+import org.apache.marmotta.kiwi.model.rdf.*;
+
+import java.util.Map;
+
+/**
+ * Implementation of an Infinispan cache manager with a remote (client-server) cache.
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class InfinispanRemoteCacheManager implements CacheManager {
+
+ private KiWiConfiguration configuration;
+
+ public InfinispanRemoteCacheManager(KiWiConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
+
+ /**
+ * Return the node id -> node cache from the cache manager. This cache is heavily used to lookup
+ * nodes when querying or loading triples and should therefore have a decent size (default 500.000 elements).
+ *
+ * @return an EHCache Cache instance containing the node id -> node mappings
+ */
+ @Override
+ public Map<Long, KiWiNode> getNodeCache() {
+ return null;
+ }
+
+ /**
+ * Return the triple id -> triple cache from the cache manager. This cache is used for speeding up the
+ * construction of query results.
+ *
+ * @return
+ */
+ @Override
+ public Map<Long, KiWiTriple> getTripleCache() {
+ return null;
+ }
+
+ /**
+ * Return the uri -> KiWiUriResource cache from the cache manager. This cache is used when constructing new
+ * KiWiUriResources to avoid a database lookup.
+ *
+ * @return
+ */
+ @Override
+ public Map<String, KiWiUriResource> getUriCache() {
+ return null;
+ }
+
+ /**
+ * Return the anonId -> KiWiAnonResource cache from the cache manager. This cache is used when constructing new
+ * KiWiAnonResources to avoid a database lookup.
+ *
+ * @return
+ */
+ @Override
+ public Map<String, KiWiAnonResource> getBNodeCache() {
+ return null;
+ }
+
+ /**
+ * Return the literal cache key -> KiWiLiteral cache from the cache manager. This cache is used when constructing new
+ * KiWiLiterals to avoid a database lookup.
+ *
+ * @return
+ * @see org.apache.marmotta.commons.sesame.model.LiteralCommons#createCacheKey(String, java.util.Locale, String)
+ */
+ @Override
+ public Map<String, KiWiLiteral> getLiteralCache() {
+ return null;
+ }
+
+ /**
+ * Return the URI -> namespace cache from the cache manager. Used for looking up namespaces
+ *
+ * @return
+ */
+ @Override
+ public Map<String, KiWiNamespace> getNamespaceUriCache() {
+ return null;
+ }
+
+ /**
+ * Return the prefix -> namespace cache from the cache manager. Used for looking up namespaces
+ *
+ * @return
+ */
+ @Override
+ public Map<String, KiWiNamespace> getNamespacePrefixCache() {
+ return null;
+ }
+
+ /**
+ * Create and return the cache used by the CacheTripleRegistry. This is an unlimited synchronous replicated
+ * cache and should be used with care.
+ *
+ * @return
+ */
+ @Override
+ public Map<Long, Long> getRegistryCache() {
+ return null;
+ }
+
+ /**
+ * Get the cache with the given name from the cache manager. Can be used to request additional
+ * caches from the cache manager that are not covered by explicit methods.
+ *
+ * @param name
+ * @return
+ */
+ @Override
+ public Map getCacheByName(String name) {
+ return null;
+ }
+
+ /**
+ * Clear all caches managed by this cache manager.
+ */
+ @Override
+ public void clear() {
+
+ }
+
+ /**
+ * Shutdown this cache manager instance. Will shutdown the underlying EHCache cache manager.
+ */
+ @Override
+ public void shutdown() {
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2f22f5ca/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/InfinispanRemoteCacheManagerFactory.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/InfinispanRemoteCacheManagerFactory.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/InfinispanRemoteCacheManagerFactory.java
new file mode 100644
index 0000000..a1047fb
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/InfinispanRemoteCacheManagerFactory.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.infinispan.remote;
+
+import org.apache.marmotta.kiwi.caching.CacheManager;
+import org.apache.marmotta.kiwi.caching.CacheManagerFactory;
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class InfinispanRemoteCacheManagerFactory implements CacheManagerFactory {
+
+ public InfinispanRemoteCacheManagerFactory() {
+ }
+
+ /**
+ * Create a new cache manager instance using the KiWiConfiguration passed as argument.
+ *
+ * @param configuration KiWi configuration used by the underlying triple store
+ * @return a new cache manager instance for this triple store
+ */
+ @Override
+ public CacheManager createCacheManager(KiWiConfiguration configuration) {
+ return new InfinispanRemoteCacheManager(configuration);
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2f22f5ca/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/remote/InfinispanRemoteCacheManager.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/remote/InfinispanRemoteCacheManager.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/remote/InfinispanRemoteCacheManager.java
deleted file mode 100644
index 6f5034a..0000000
--- a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/remote/InfinispanRemoteCacheManager.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.kiwi.remote;
-
-import org.apache.marmotta.kiwi.caching.CacheManager;
-import org.apache.marmotta.kiwi.config.KiWiConfiguration;
-import org.apache.marmotta.kiwi.model.rdf.*;
-
-import java.util.Map;
-
-/**
- * Implementation of an Infinispan cache manager with a remote (client-server) cache.
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class InfinispanRemoteCacheManager implements CacheManager {
-
- private KiWiConfiguration configuration;
-
- public InfinispanRemoteCacheManager(KiWiConfiguration configuration) {
- this.configuration = configuration;
- }
-
-
- /**
- * Return the node id -> node cache from the cache manager. This cache is heavily used to lookup
- * nodes when querying or loading triples and should therefore have a decent size (default 500.000 elements).
- *
- * @return an EHCache Cache instance containing the node id -> node mappings
- */
- @Override
- public Map<Long, KiWiNode> getNodeCache() {
- return null;
- }
-
- /**
- * Return the triple id -> triple cache from the cache manager. This cache is used for speeding up the
- * construction of query results.
- *
- * @return
- */
- @Override
- public Map<Long, KiWiTriple> getTripleCache() {
- return null;
- }
-
- /**
- * Return the uri -> KiWiUriResource cache from the cache manager. This cache is used when constructing new
- * KiWiUriResources to avoid a database lookup.
- *
- * @return
- */
- @Override
- public Map<String, KiWiUriResource> getUriCache() {
- return null;
- }
-
- /**
- * Return the anonId -> KiWiAnonResource cache from the cache manager. This cache is used when constructing new
- * KiWiAnonResources to avoid a database lookup.
- *
- * @return
- */
- @Override
- public Map<String, KiWiAnonResource> getBNodeCache() {
- return null;
- }
-
- /**
- * Return the literal cache key -> KiWiLiteral cache from the cache manager. This cache is used when constructing new
- * KiWiLiterals to avoid a database lookup.
- *
- * @return
- * @see org.apache.marmotta.commons.sesame.model.LiteralCommons#createCacheKey(String, java.util.Locale, String)
- */
- @Override
- public Map<String, KiWiLiteral> getLiteralCache() {
- return null;
- }
-
- /**
- * Return the URI -> namespace cache from the cache manager. Used for looking up namespaces
- *
- * @return
- */
- @Override
- public Map<String, KiWiNamespace> getNamespaceUriCache() {
- return null;
- }
-
- /**
- * Return the prefix -> namespace cache from the cache manager. Used for looking up namespaces
- *
- * @return
- */
- @Override
- public Map<String, KiWiNamespace> getNamespacePrefixCache() {
- return null;
- }
-
- /**
- * Create and return the cache used by the CacheTripleRegistry. This is an unlimited synchronous replicated
- * cache and should be used with care.
- *
- * @return
- */
- @Override
- public Map<Long, Long> getRegistryCache() {
- return null;
- }
-
- /**
- * Get the cache with the given name from the cache manager. Can be used to request additional
- * caches from the cache manager that are not covered by explicit methods.
- *
- * @param name
- * @return
- */
- @Override
- public Map getCacheByName(String name) {
- return null;
- }
-
- /**
- * Clear all caches managed by this cache manager.
- */
- @Override
- public void clear() {
-
- }
-
- /**
- * Shutdown this cache manager instance. Will shutdown the underlying EHCache cache manager.
- */
- @Override
- public void shutdown() {
-
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2f22f5ca/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/remote/InfinispanRemoteCacheManagerFactory.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/remote/InfinispanRemoteCacheManagerFactory.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/remote/InfinispanRemoteCacheManagerFactory.java
deleted file mode 100644
index a0152d1..0000000
--- a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/remote/InfinispanRemoteCacheManagerFactory.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.kiwi.remote;
-
-import org.apache.marmotta.kiwi.caching.CacheManager;
-import org.apache.marmotta.kiwi.caching.CacheManagerFactory;
-import org.apache.marmotta.kiwi.config.KiWiConfiguration;
-
-/**
- * Add file description here!
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class InfinispanRemoteCacheManagerFactory implements CacheManagerFactory {
-
- public InfinispanRemoteCacheManagerFactory() {
- }
-
- /**
- * Create a new cache manager instance using the KiWiConfiguration passed as argument.
- *
- * @param configuration KiWi configuration used by the underlying triple store
- * @return a new cache manager instance for this triple store
- */
- @Override
- public CacheManager createCacheManager(KiWiConfiguration configuration) {
- return new InfinispanRemoteCacheManager(configuration);
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2f22f5ca/libraries/kiwi/kiwi-caching-infinispan/src/main/resources/META-INF/services/org.apache.marmotta.kiwi.caching.CacheManagerFactory
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/resources/META-INF/services/org.apache.marmotta.kiwi.caching.CacheManagerFactory b/libraries/kiwi/kiwi-caching-infinispan/src/main/resources/META-INF/services/org.apache.marmotta.kiwi.caching.CacheManagerFactory
index 4fd2bec..d354758 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/main/resources/META-INF/services/org.apache.marmotta.kiwi.caching.CacheManagerFactory
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/resources/META-INF/services/org.apache.marmotta.kiwi.caching.CacheManagerFactory
@@ -1,2 +1,2 @@
-org.apache.marmotta.kiwi.embedded.InfinispanEmbeddedCacheManagerFactory
-org.apache.marmotta.kiwi.remote.InfinispanRemoteCacheManagerFactory
+org.apache.marmotta.kiwi.infinispan.embedded.InfinispanEmbeddedCacheManagerFactory
+org.apache.marmotta.kiwi.infinispan.remote.InfinispanRemoteCacheManagerFactory
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2f22f5ca/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/ExternalizerTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/ExternalizerTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/ExternalizerTest.java
index 74f63d2..94121f3 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/ExternalizerTest.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/ExternalizerTest.java
@@ -19,7 +19,8 @@ package org.apache.marmotta.kiwi.test;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.marmotta.commons.vocabulary.XSD;
-import org.apache.marmotta.kiwi.externalizer.*;
+import org.apache.marmotta.kiwi.infinispan.externalizer.*;
+import org.apache.marmotta.kiwi.infinispan.remote.CustomJBossMarshaller;
import org.apache.marmotta.kiwi.model.rdf.*;
import org.infinispan.commons.marshall.AdvancedExternalizer;
import org.infinispan.commons.marshall.StreamingMarshaller;
@@ -56,7 +57,7 @@ public class ExternalizerTest {
private static Logger log = LoggerFactory.getLogger(ExternalizerTest.class);
- private static StreamingMarshaller marshaller;
+ private static StreamingMarshaller marshaller, hotrod;
@BeforeClass
@@ -89,6 +90,7 @@ public class ExternalizerTest {
marshaller = cacheManager.getCache().getAdvancedCache().getComponentRegistry().getCacheMarshaller();
+ hotrod = new CustomJBossMarshaller();
}
@@ -187,7 +189,7 @@ public class ExternalizerTest {
Assert.assertEquals(origin,destination1);
- log.info("- testing externalizer with infinispan marshaller ...");
+ log.info("- testing externalizer with infinispan cluster marshaller ...");
byte[] bytes = marshaller.objectToByteBuffer(origin);
log.info(" object {}: serialized with {} bytes", origin, bytes.length);
@@ -196,6 +198,17 @@ public class ExternalizerTest {
Assert.assertEquals(origin, destination2);
+
+
+ log.info("- testing externalizer with infinispan hotrod marshaller ...");
+
+ byte[] bytesH = hotrod.objectToByteBuffer(origin);
+ log.info(" object {}: serialized with {} bytes", origin, bytesH.length);
+
+ Object destination3 = hotrod.objectFromByteBuffer(bytesH);
+
+ Assert.assertEquals(origin, destination3);
+
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2f22f5ca/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/InfinispanClusterTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/InfinispanClusterTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/InfinispanClusterTest.java
index 0522262..c35a492 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/InfinispanClusterTest.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/InfinispanClusterTest.java
@@ -17,7 +17,7 @@
package org.apache.marmotta.kiwi.test;
-import org.apache.marmotta.kiwi.caching.CacheManagerType;
+import org.apache.marmotta.kiwi.config.CacheManagerType;
import org.apache.marmotta.kiwi.test.cluster.BaseClusterTest;
import org.junit.BeforeClass;
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2f22f5ca/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/CacheManagerType.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/CacheManagerType.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/CacheManagerType.java
deleted file mode 100644
index 25dc7b8..0000000
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/CacheManagerType.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.kiwi.caching;
-
-/**
- * Add file description here!
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public enum CacheManagerType {
-
- /**
- * Simple in-memory cache backend using the Guava library; no clustering support
- */
- GUAVA("org.apache.marmotta.kiwi.caching.GuavaCacheManagerFactory"),
-
- /**
- * Cache backend based on Infinispan using a dynamic cluster setup (UDP multicast)
- */
- INFINISPAN_CLUSTERED("org.apache.marmotta.kiwi.embedded.InfinispanEmbeddedCacheManagerFactory"),
-
- /**
- * Cache backend based on Infinispan using a client-server setup (Hotrod)
- */
- INFINISPAN_HOTROD("org.apache.marmotta.kiwi.remote.InfinispanRemoteCacheManagerFactory"),
-
-
- /**
- * Cache backend based on Hazelcast using a dynamic cluster setup
- */
- HAZELCAST("org.apache.marmotta.kiwi.hazelcast.caching.HazelcastCacheManagerFactory");
-
-
- CacheManagerType(String factoryClass) {
- this.factoryClass = factoryClass;
- }
-
- private String factoryClass;
-
- public String getFactoryClass() {
- return factoryClass;
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2f22f5ca/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/CacheManagerType.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/CacheManagerType.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/CacheManagerType.java
new file mode 100644
index 0000000..783a79d
--- /dev/null
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/CacheManagerType.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.config;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public enum CacheManagerType {
+
+ /**
+ * Simple in-memory cache backend using the Guava library; no clustering support
+ */
+ GUAVA("org.apache.marmotta.kiwi.caching.GuavaCacheManagerFactory"),
+
+ /**
+ * Cache backend based on Infinispan using a dynamic cluster setup (UDP multicast)
+ */
+ INFINISPAN_CLUSTERED("org.apache.marmotta.kiwi.infinispan.embedded.InfinispanEmbeddedCacheManagerFactory"),
+
+ /**
+ * Cache backend based on Infinispan using a client-server setup (Hotrod)
+ */
+ INFINISPAN_HOTROD("org.apache.marmotta.kiwi.infinispan.remote.InfinispanRemoteCacheManagerFactory"),
+
+
+ /**
+ * Cache backend based on Hazelcast using a dynamic cluster setup
+ */
+ HAZELCAST("org.apache.marmotta.kiwi.hazelcast.caching.HazelcastCacheManagerFactory");
+
+
+ CacheManagerType(String factoryClass) {
+ this.factoryClass = factoryClass;
+ }
+
+ private String factoryClass;
+
+ public String getFactoryClass() {
+ return factoryClass;
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2f22f5ca/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java
index 7ffee6a..fb9fb2c 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java
@@ -17,7 +17,6 @@
*/
package org.apache.marmotta.kiwi.config;
-import org.apache.marmotta.kiwi.caching.CacheManagerType;
import org.apache.marmotta.kiwi.persistence.KiWiDialect;
import java.util.ArrayList;
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2f22f5ca/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/cluster/BaseClusterTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/cluster/BaseClusterTest.java b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/cluster/BaseClusterTest.java
index f23bfc4..12a57b0 100644
--- a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/cluster/BaseClusterTest.java
+++ b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/cluster/BaseClusterTest.java
@@ -18,7 +18,7 @@
package org.apache.marmotta.kiwi.test.cluster;
import org.apache.marmotta.kiwi.caching.CacheManager;
-import org.apache.marmotta.kiwi.caching.CacheManagerType;
+import org.apache.marmotta.kiwi.config.CacheManagerType;
import org.apache.marmotta.kiwi.config.KiWiConfiguration;
import org.apache.marmotta.kiwi.persistence.h2.H2Dialect;
import org.apache.marmotta.kiwi.sail.KiWiStore;
@@ -39,6 +39,7 @@ import org.slf4j.LoggerFactory;
*/
public abstract class BaseClusterTest {
+ public static final int REGISTRY_TESTS = 10000;
private static Logger log = LoggerFactory.getLogger(BaseClusterTest.class);
private static int datacenterIds = 1;
@@ -106,6 +107,23 @@ public abstract class BaseClusterTest {
}
+ @Test
+ public void testRegistry() {
+
+ log.info("testing synchronized registry ...");
+
+ for(int i=0; i < REGISTRY_TESTS; i++) {
+ cacheManagerSync1.getRegistryCache().put((long)i,(long)i);
+
+ Long j = cacheManagerSync1.getRegistryCache().get((long)i);
+ Long k = cacheManagerSync2.getRegistryCache().get((long)i);
+
+ Assert.assertEquals("objects in same cache were not identical!", (long)i, (long)j);
+ Assert.assertEquals("objects in caches 1 and 2 were not identical!", (long)i, (long)k);
+ }
+
+ }
+
protected static class ClusterTestSupport {
CacheManagerType type;
[19/21] git commit: trying to fix repository connection test for
hotrod
Posted by ss...@apache.org.
trying to fix repository connection test for hotrod
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/35cd6c6a
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/35cd6c6a
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/35cd6c6a
Branch: refs/heads/MARMOTTA-450
Commit: 35cd6c6a1c336596413d4f35ec598ae0626cbb79
Parents: d04230a
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Tue Mar 4 22:44:43 2014 +0100
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Tue Mar 4 22:44:43 2014 +0100
----------------------------------------------------------------------
.../remote/InfinispanRemoteCacheManager.java | 9 ++++++--
.../kiwi/test/remote/HotRodRepositoryTest.java | 2 ++
.../kiwi/test/remote/HotRodServerRule.java | 24 --------------------
3 files changed, 9 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/35cd6c6a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/InfinispanRemoteCacheManager.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/InfinispanRemoteCacheManager.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/InfinispanRemoteCacheManager.java
index 39a20b6..0952706 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/InfinispanRemoteCacheManager.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/InfinispanRemoteCacheManager.java
@@ -199,9 +199,14 @@ public class InfinispanRemoteCacheManager implements CacheManager {
@Override
public void shutdown() {
try {
- log.info("shutting down cache manager ...");
+ log.info("shutting down Infinispan remote cache manager ...");
cacheManager.stop();
- } catch (CacheException ex) {
+
+ while(cacheManager.isStarted()) {
+ log.info("waiting 100ms for cache manager to come down ...");
+ Thread.sleep(100);
+ }
+ } catch (CacheException | InterruptedException ex) {
log.warn("error shutting down cache: {}", ex.getMessage());
}
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/35cd6c6a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryTest.java
index 6d1cc2f..a7ee8a4 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryTest.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryTest.java
@@ -58,6 +58,8 @@ public class HotRodRepositoryTest extends RepositoryTest {
*/
@Override
protected Repository createRepository() throws Exception {
+ hotrod.clearAll();
+
store = new KiWiStore(config);
return new SailRepository(store);
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/35cd6c6a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodServerRule.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodServerRule.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodServerRule.java
index 0bef0ee..7029b1f 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodServerRule.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodServerRule.java
@@ -19,10 +19,7 @@ package org.apache.marmotta.kiwi.test.remote;
import org.apache.marmotta.kiwi.caching.CacheManager;
import org.apache.marmotta.kiwi.infinispan.embedded.InfinispanEmbeddedCacheManager;
-import org.apache.marmotta.kiwi.infinispan.remote.CustomJBossMarshaller;
import org.infinispan.Cache;
-import org.infinispan.client.hotrod.RemoteCache;
-import org.infinispan.client.hotrod.RemoteCacheManager;
import org.infinispan.commons.api.BasicCacheContainer;
import org.infinispan.commons.equivalence.ByteArrayEquivalence;
import org.infinispan.configuration.cache.CacheMode;
@@ -35,7 +32,6 @@ import org.infinispan.manager.EmbeddedCacheManager;
import org.infinispan.server.hotrod.HotRodServer;
import org.infinispan.server.hotrod.configuration.HotRodServerConfiguration;
import org.infinispan.server.hotrod.configuration.HotRodServerConfigurationBuilder;
-import org.junit.Assert;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
@@ -152,26 +148,6 @@ public class HotRodServerRule implements TestRule {
hotRodServer.start(hotrodConfig, cacheManager);
- // test if cache is available
- org.infinispan.client.hotrod.configuration.Configuration remoteCfg = new org.infinispan.client.hotrod.configuration.ConfigurationBuilder()
- .addServer()
- .host("127.0.0.1")
- .port(port)
- .marshaller(new CustomJBossMarshaller())
- .pingOnStartup(true)
- .build(true);
-
-
- RemoteCacheManager remoteCacheManager = new RemoteCacheManager(remoteCfg);
- Assert.assertTrue(remoteCacheManager.isStarted());
-
- RemoteCache<String, String> m = remoteCacheManager.getCache();
-
- m.put("xyz", "abc");
- String n = m.get("xyz");
-
- Assert.assertNotNull(n);
-
return hotRodServer;
}
[12/21] git commit: - hotrod serialization with custom JBoss
Marshaller
Posted by ss...@apache.org.
- hotrod serialization with custom JBoss Marshaller
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/2f22f5ca
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/2f22f5ca
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/2f22f5ca
Branch: refs/heads/MARMOTTA-450
Commit: 2f22f5cab74cb46d2ffa1b32627a1b71d004542d
Parents: 4cc2d1d
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Tue Mar 4 17:29:15 2014 +0100
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Tue Mar 4 17:29:15 2014 +0100
----------------------------------------------------------------------
.../kiwi/test/cluster/HazelcastClusterTest.java | 2 +-
.../InfinispanEmbeddedCacheManager.java | 517 -------------------
.../InfinispanEmbeddedCacheManagerFactory.java | 44 --
.../kiwi/externalizer/BNodeExternalizer.java | 74 ---
.../BooleanLiteralExternalizer.java | 72 ---
.../externalizer/DateLiteralExternalizer.java | 72 ---
.../externalizer/DoubleLiteralExternalizer.java | 72 ---
.../kiwi/externalizer/ExternalizerIds.java | 43 --
.../externalizer/IntLiteralExternalizer.java | 72 ---
.../externalizer/StringLiteralExternalizer.java | 79 ---
.../kiwi/externalizer/TripleExternalizer.java | 149 ------
.../kiwi/externalizer/UriExternalizer.java | 136 -----
.../InfinispanEmbeddedCacheManager.java | 517 +++++++++++++++++++
.../InfinispanEmbeddedCacheManagerFactory.java | 44 ++
.../externalizer/BNodeExternalizer.java | 74 +++
.../externalizer/BaseExternalizer.java | 80 +++
.../BooleanLiteralExternalizer.java | 72 +++
.../externalizer/DateLiteralExternalizer.java | 72 +++
.../externalizer/DoubleLiteralExternalizer.java | 72 +++
.../externalizer/ExternalizerIds.java | 43 ++
.../externalizer/IntLiteralExternalizer.java | 72 +++
.../externalizer/StringLiteralExternalizer.java | 79 +++
.../externalizer/TripleExternalizer.java | 149 ++++++
.../externalizer/UriExternalizer.java | 136 +++++
.../remote/CustomClassExternalizerFactory.java | 70 +++
.../infinispan/remote/CustomClassTable.java | 113 ++++
.../remote/CustomJBossMarshaller.java | 41 ++
.../remote/InfinispanRemoteCacheManager.java | 154 ++++++
.../InfinispanRemoteCacheManagerFactory.java | 44 ++
.../remote/InfinispanRemoteCacheManager.java | 154 ------
.../InfinispanRemoteCacheManagerFactory.java | 44 --
...he.marmotta.kiwi.caching.CacheManagerFactory | 4 +-
.../marmotta/kiwi/test/ExternalizerTest.java | 19 +-
.../kiwi/test/InfinispanClusterTest.java | 2 +-
.../marmotta/kiwi/caching/CacheManagerType.java | 58 ---
.../marmotta/kiwi/config/CacheManagerType.java | 58 +++
.../marmotta/kiwi/config/KiWiConfiguration.java | 1 -
.../kiwi/test/cluster/BaseClusterTest.java | 20 +-
38 files changed, 1929 insertions(+), 1595 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2f22f5ca/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastClusterTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastClusterTest.java b/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastClusterTest.java
index c53b704..5cbbe7f 100644
--- a/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastClusterTest.java
+++ b/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastClusterTest.java
@@ -17,7 +17,7 @@
package org.apache.marmotta.kiwi.test.cluster;
-import org.apache.marmotta.kiwi.caching.CacheManagerType;
+import org.apache.marmotta.kiwi.config.CacheManagerType;
import org.junit.BeforeClass;
/**
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2f22f5ca/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/embedded/InfinispanEmbeddedCacheManager.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/embedded/InfinispanEmbeddedCacheManager.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/embedded/InfinispanEmbeddedCacheManager.java
deleted file mode 100644
index 85ed56b..0000000
--- a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/embedded/InfinispanEmbeddedCacheManager.java
+++ /dev/null
@@ -1,517 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.marmotta.kiwi.embedded;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.marmotta.kiwi.caching.CacheManager;
-import org.apache.marmotta.kiwi.config.KiWiConfiguration;
-import org.apache.marmotta.kiwi.externalizer.*;
-import org.infinispan.Cache;
-import org.infinispan.commons.CacheException;
-import org.infinispan.commons.marshall.AdvancedExternalizer;
-import org.infinispan.configuration.cache.CacheMode;
-import org.infinispan.configuration.cache.Configuration;
-import org.infinispan.configuration.cache.ConfigurationBuilder;
-import org.infinispan.configuration.global.GlobalConfiguration;
-import org.infinispan.configuration.global.GlobalConfigurationBuilder;
-import org.infinispan.context.Flag;
-import org.infinispan.distribution.ch.SyncConsistentHashFactory;
-import org.infinispan.eviction.EvictionStrategy;
-import org.infinispan.lifecycle.ComponentStatus;
-import org.infinispan.manager.DefaultCacheManager;
-import org.infinispan.manager.EmbeddedCacheManager;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.util.Iterator;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
-
-/**
- * A class for managing the different caches that are used by the triple store.
- * <p/>
- * Author: Sebastian Schaffert
- */
-public class InfinispanEmbeddedCacheManager implements CacheManager {
-
- private static Logger log = LoggerFactory.getLogger(InfinispanEmbeddedCacheManager.class);
-
- public static final String NODE_CACHE = "node-cache";
- public static final String TRIPLE_CACHE = "triple-cache";
- public static final String URI_CACHE = "uri-cache";
- public static final String BNODE_CACHE = "bnode-cache";
- public static final String LITERAL_CACHE = "literal-cache";
- public static final String NAMESPACE_URI_CACHE = "namespace-uri-cache";
- public static final String NAMESPACE_PREFIX_CACHE = "namespace-prefix-cache";
- public static final String LOADER_CACHE = "loader-cache";
- public static final String REGISTRY_CACHE = "registry-cache";
-
- private EmbeddedCacheManager cacheManager;
-
- // default configuration: distributed cache, 100000 entries, 300 seconds expiration, 60 seconds idle
- private Configuration defaultConfiguration;
-
- private KiWiConfiguration config;
-
- private Cache nodeCache, tripleCache, uriCache, literalCache, bnodeCache, nsPrefixCache, nsUriCache, registryCache;
-
-
- /**
- * Create a new cache manager with its own automatically created Infinispan instance.
- *
- * @param config
- */
- public InfinispanEmbeddedCacheManager(KiWiConfiguration config) {
-
-
- this.config = config;
-
- try {
- switch (config.getCacheMode()) {
- case DISTRIBUTED:
- buildDistributedConfiguration(getExternalizers());
- break;
- case REPLICATED:
- buildReplicatedConfiguration(getExternalizers());
- break;
- case LOCAL:
- buildLocalConfiguration();
- break;
- }
- } catch (IOException ex) {
- log.warn("error while building cache cluster configuration, reverting to local cache");
- buildLocalConfiguration();
- }
-
-
- }
-
- /**
- * Build a local cache configuration.
- * <p/>
- * In local cache mode, the cache is not shared among the servers in a cluster. Each machine keeps a local cache.
- * This allows quick startups and eliminates network traffic in the cluster, but subsequent requests to different
- * cluster members cannot benefit from the cached data.
- */
- protected void buildLocalConfiguration() {
- GlobalConfiguration globalConfiguration = new GlobalConfigurationBuilder()
- .classLoader(InfinispanEmbeddedCacheManager.class.getClassLoader())
- .globalJmxStatistics()
- .jmxDomain("org.apache.marmotta.kiwi")
- .allowDuplicateDomains(true)
- .build();
-
- defaultConfiguration = new ConfigurationBuilder()
- .clustering()
- .cacheMode(CacheMode.LOCAL)
- .eviction()
- .strategy(EvictionStrategy.LIRS)
- .maxEntries(100000)
- .expiration()
- .lifespan(5, TimeUnit.MINUTES)
- .maxIdle(1, TimeUnit.MINUTES)
- .build();
- cacheManager = new DefaultCacheManager(globalConfiguration, defaultConfiguration, true);
-
- log.info("initialised Infinispan local cache manager");
- }
-
- /**
- * Build a distributed cache configuration.
- * <p/>
- * In distributed cache mode, the cluster forms a big hash table used as a cache. This allows to make efficient
- * use of the large amount of memory available, but requires cache rebalancing and a lot of network transfers,
- * especially in case cluster members are restarted often.
- */
- protected void buildDistributedConfiguration(AdvancedExternalizer...externalizers) throws IOException {
- String jgroupsXml = IOUtils.toString(InfinispanEmbeddedCacheManager.class.getResourceAsStream("/jgroups-kiwi.xml"));
-
- jgroupsXml = jgroupsXml.replaceAll("mcast_addr=\"[0-9.]+\"", String.format("mcast_addr=\"%s\"", config.getClusterAddress()));
- jgroupsXml = jgroupsXml.replaceAll("mcast_port=\"[0-9]+\"", String.format("mcast_port=\"%d\"", config.getClusterPort()));
-
-
- GlobalConfiguration globalConfiguration = new GlobalConfigurationBuilder()
- .classLoader(InfinispanEmbeddedCacheManager.class.getClassLoader())
- .transport()
- .defaultTransport()
- .clusterName(config.getClusterName())
- .machineId("instance-" + config.getDatacenterId())
- .addProperty("configurationXml", jgroupsXml)
- .globalJmxStatistics()
- .jmxDomain("org.apache.marmotta.kiwi")
- .allowDuplicateDomains(true)
- .serialization()
- .addAdvancedExternalizer(externalizers)
- .build();
-
- defaultConfiguration = new ConfigurationBuilder()
- .clustering()
- .cacheMode(CacheMode.DIST_ASYNC)
- .async()
- .asyncMarshalling()
- .l1()
- .lifespan(5, TimeUnit.MINUTES)
- .hash()
- .numOwners(2)
- .numSegments(40)
- .consistentHashFactory(new SyncConsistentHashFactory())
- .stateTransfer()
- .fetchInMemoryState(false)
- .eviction()
- .strategy(EvictionStrategy.LIRS)
- .maxEntries(100000)
- .expiration()
- .lifespan(30, TimeUnit.MINUTES)
- .maxIdle(10, TimeUnit.MINUTES)
- .build();
- cacheManager = new DefaultCacheManager(globalConfiguration, defaultConfiguration, true);
-
- log.info("initialised Infinispan distributed cache manager (cluster name: {})", globalConfiguration.transport().clusterName());
-
- }
-
- /**
- * Build a replicated cache configuration.
- * <p/>
- * In replicated cache mode, each node in the cluster has an identical copy of all cache data. This allows
- * very efficient cache lookups and reduces the rebalancing effort, but requires more memory.
- */
- protected void buildReplicatedConfiguration(AdvancedExternalizer...externalizers) throws IOException {
- String jgroupsXml = IOUtils.toString(InfinispanEmbeddedCacheManager.class.getResourceAsStream("/jgroups-kiwi.xml"));
-
- jgroupsXml = jgroupsXml.replaceAll("mcast_addr=\"[0-9.]+\"", String.format("mcast_addr=\"%s\"", config.getClusterAddress()));
- jgroupsXml = jgroupsXml.replaceAll("mcast_port=\"[0-9]+\"", String.format("mcast_port=\"%d\"", config.getClusterPort()));
-
-
- GlobalConfiguration globalConfiguration = new GlobalConfigurationBuilder()
- .classLoader(InfinispanEmbeddedCacheManager.class.getClassLoader())
- .transport()
- .defaultTransport()
- .clusterName(config.getClusterName())
- .machineId("instance-" + config.getDatacenterId())
- .addProperty("configurationXml", jgroupsXml)
- .globalJmxStatistics()
- .jmxDomain("org.apache.marmotta.kiwi")
- .allowDuplicateDomains(true)
- .serialization()
- .addAdvancedExternalizer(externalizers)
- .build();
-
- defaultConfiguration = new ConfigurationBuilder()
- .clustering()
- .cacheMode(CacheMode.REPL_ASYNC)
- .async()
- .asyncMarshalling()
- .stateTransfer()
- .fetchInMemoryState(false)
- .eviction()
- .strategy(EvictionStrategy.LIRS)
- .maxEntries(100000)
- .expiration()
- .lifespan(30, TimeUnit.MINUTES)
- .maxIdle(10, TimeUnit.MINUTES)
- .build();
- cacheManager = new DefaultCacheManager(globalConfiguration, defaultConfiguration, true);
-
- log.info("initialised Infinispan replicated cache manager (cluster name: {})", globalConfiguration.transport().clusterName());
- }
-
-
- protected boolean isClustered() {
- return config.getCacheMode() == org.apache.marmotta.kiwi.config.CacheMode.DISTRIBUTED ||
- config.getCacheMode() == org.apache.marmotta.kiwi.config.CacheMode.REPLICATED;
- }
-
-
- private AdvancedExternalizer[] getExternalizers() {
- return new AdvancedExternalizer[] {
- new TripleExternalizer(),
- new UriExternalizer(),
- new BNodeExternalizer(),
- new StringLiteralExternalizer(),
- new DateLiteralExternalizer(),
- new BooleanLiteralExternalizer(),
- new IntLiteralExternalizer(),
- new DoubleLiteralExternalizer()
- };
- }
-
- /**
- * Return the node id -> node cache from the cache manager. This cache is heavily used to lookup
- * nodes when querying or loading triples and should therefore have a decent size (default 500.000 elements).
- *
- * @return an EHCache Cache instance containing the node id -> node mappings
- */
- public Cache getNodeCache() {
- if(nodeCache == null) {
- Configuration nodeConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
- .eviction()
- .maxEntries(1000000)
- .expiration()
- .lifespan(60, TimeUnit.MINUTES)
- .maxIdle(30, TimeUnit.MINUTES)
- .build();
- cacheManager.defineConfiguration(NODE_CACHE, nodeConfiguration);
-
- nodeCache = cacheManager.getCache(NODE_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
- }
-
- return nodeCache;
- }
-
- /**
- * Return the triple id -> triple cache from the cache manager. This cache is used for speeding up the
- * construction of query results.
- *
- * @return
- */
- public Cache getTripleCache() {
- if(tripleCache == null) {
- Configuration tripleConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
- .clustering()
- .cacheMode(CacheMode.LOCAL)
- .eviction()
- .maxEntries(config.getTripleCacheSize())
- .expiration()
- .lifespan(60, TimeUnit.MINUTES)
- .maxIdle(30, TimeUnit.MINUTES)
- .build();
- cacheManager.defineConfiguration(TRIPLE_CACHE, tripleConfiguration);
-
- tripleCache = cacheManager.getCache(TRIPLE_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
- }
- return tripleCache;
- }
-
-
- /**
- * Return the uri -> KiWiUriResource cache from the cache manager. This cache is used when constructing new
- * KiWiUriResources to avoid a database lookup.
- *
- * @return
- */
- public Cache getUriCache() {
- if(uriCache == null) {
- Configuration uriConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
- .eviction()
- .maxEntries(config.getUriCacheSize())
- .build();
- cacheManager.defineConfiguration(URI_CACHE, uriConfiguration);
-
- uriCache = cacheManager.getCache(URI_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
- }
- return uriCache;
- }
-
-
- /**
- * Return the anonId -> KiWiAnonResource cache from the cache manager. This cache is used when constructing new
- * KiWiAnonResources to avoid a database lookup.
- *
- * @return
- */
- public Cache getBNodeCache() {
- if(bnodeCache == null) {
- Configuration bnodeConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
- .eviction()
- .maxEntries(config.getBNodeCacheSize())
- .build();
- cacheManager.defineConfiguration(BNODE_CACHE, bnodeConfiguration);
-
- bnodeCache = cacheManager.getCache(BNODE_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
- }
- return bnodeCache;
- }
-
- /**
- * Return the literal cache key -> KiWiLiteral cache from the cache manager. This cache is used when constructing new
- * KiWiLiterals to avoid a database lookup.
- *
- * @see org.apache.marmotta.commons.sesame.model.LiteralCommons#createCacheKey(String, java.util.Locale, String)
- * @return
- */
- public Cache getLiteralCache() {
- if(literalCache == null) {
- Configuration literalConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
- .eviction()
- .maxEntries(config.getLiteralCacheSize())
- .build();
- cacheManager.defineConfiguration(LITERAL_CACHE, literalConfiguration);
-
- literalCache = cacheManager.getCache(LITERAL_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
- }
- return literalCache;
- }
-
-
- /**
- * Return the URI -> namespace cache from the cache manager. Used for looking up namespaces
- * @return
- */
- public Cache getNamespaceUriCache() {
- if(nsUriCache == null) {
- if(isClustered()) {
- Configuration nsuriConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
- .clustering()
- .cacheMode(CacheMode.REPL_ASYNC)
- .eviction()
- .maxEntries(config.getNamespaceCacheSize())
- .expiration()
- .lifespan(1, TimeUnit.DAYS)
- .build();
- cacheManager.defineConfiguration(NAMESPACE_URI_CACHE, nsuriConfiguration);
- } else {
- Configuration nsuriConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
- .eviction()
- .maxEntries(config.getNamespaceCacheSize())
- .expiration()
- .lifespan(1, TimeUnit.HOURS)
- .build();
- cacheManager.defineConfiguration(NAMESPACE_URI_CACHE, nsuriConfiguration);
- }
-
- nsUriCache = cacheManager.getCache(NAMESPACE_URI_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
- }
- return nsUriCache;
- }
-
- /**
- * Return the prefix -> namespace cache from the cache manager. Used for looking up namespaces
- * @return
- */
- public Cache getNamespacePrefixCache() {
- if(nsPrefixCache == null) {
- if(isClustered()) {
- Configuration nsprefixConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
- .clustering()
- .cacheMode(CacheMode.REPL_ASYNC)
- .eviction()
- .maxEntries(config.getNamespaceCacheSize())
- .expiration()
- .lifespan(1, TimeUnit.DAYS)
- .build();
- cacheManager.defineConfiguration(NAMESPACE_PREFIX_CACHE, nsprefixConfiguration);
-
- } else {
- Configuration nsprefixConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
- .eviction()
- .maxEntries(config.getNamespaceCacheSize())
- .expiration()
- .lifespan(1, TimeUnit.HOURS)
- .build();
- cacheManager.defineConfiguration(NAMESPACE_PREFIX_CACHE, nsprefixConfiguration);
-
- }
- nsPrefixCache = cacheManager.getCache(NAMESPACE_PREFIX_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
- }
- return nsPrefixCache;
- }
-
-
-
-
- /**
- * Create and return the cache used by the CacheTripleRegistry. This is an unlimited synchronous replicated
- * cache and should be used with care.
- * @return
- */
- public Cache getRegistryCache() {
- if(registryCache == null) {
- if(isClustered()) {
- Configuration registryConfiguration = new ConfigurationBuilder()
- .clustering()
- .cacheMode(CacheMode.REPL_SYNC)
- .sync()
- .replTimeout(15, TimeUnit.SECONDS)
- .eviction()
- .strategy(EvictionStrategy.NONE)
- .build();
- cacheManager.defineConfiguration(REGISTRY_CACHE, registryConfiguration);
- } else {
- Configuration registryConfiguration = new ConfigurationBuilder()
- .clustering()
- .cacheMode(CacheMode.LOCAL)
- .eviction()
- .strategy(EvictionStrategy.NONE)
- .build();
- cacheManager.defineConfiguration(REGISTRY_CACHE, registryConfiguration);
- }
-
- registryCache = cacheManager.getCache(REGISTRY_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
- }
- return registryCache;
- }
-
- /**
- * Get the cache with the given name from the cache manager. Can be used to request additional
- * caches from the cache manager that are not covered by explicit methods.
- *
- * @param name
- * @return
- */
- public synchronized Cache getCacheByName(String name) {
- if(!cacheManager.cacheExists(name)) {
- cacheManager.defineConfiguration(name, new ConfigurationBuilder().read(defaultConfiguration).build());
- }
- return cacheManager.getCache(name).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
-
- }
-
- /**
- * Clear all caches managed by this cache manager.
- */
- public void clear() {
- Set<String> set = cacheManager.getCacheNames();
- Iterator<String> iterator = set.iterator();
- while(iterator.hasNext()){
- String cacheName = iterator.next();
- Cache<String,Object> cache = cacheManager.getCache(cacheName);
- cache.clear();
- }
-
- nodeCache = null;
- tripleCache = null;
- uriCache = null;
- literalCache = null;
- bnodeCache = null;
- nsPrefixCache = null;
- nsUriCache = null;
- registryCache = null;
- }
-
- /**
- * Shutdown this cache manager instance. Will shutdown the underlying EHCache cache manager.
- */
- public void shutdown() {
- try {
- if(cacheManager.getStatus() == ComponentStatus.RUNNING) {
- log.warn("shutting down cache manager ...");
-// if(cacheManager.getTransport() != null) {
-// log.info("... shutting down transport ...");
-// cacheManager.getTransport().stop();
-// }
- log.info("... shutting down main component ...");
- cacheManager.stop();
- log.info("... done!");
- }
- } catch (CacheException ex) {
- log.warn("error shutting down cache: {}", ex.getMessage());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2f22f5ca/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/embedded/InfinispanEmbeddedCacheManagerFactory.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/embedded/InfinispanEmbeddedCacheManagerFactory.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/embedded/InfinispanEmbeddedCacheManagerFactory.java
deleted file mode 100644
index 13ffcfd..0000000
--- a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/embedded/InfinispanEmbeddedCacheManagerFactory.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.kiwi.embedded;
-
-import org.apache.marmotta.kiwi.caching.CacheManager;
-import org.apache.marmotta.kiwi.caching.CacheManagerFactory;
-import org.apache.marmotta.kiwi.config.KiWiConfiguration;
-
-/**
- * Add file description here!
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class InfinispanEmbeddedCacheManagerFactory implements CacheManagerFactory {
-
- public InfinispanEmbeddedCacheManagerFactory() {
- }
-
- /**
- * Create a new cache manager instance using the KiWiConfiguration passed as argument.
- *
- * @param configuration KiWi configuration used by the underlying triple store
- * @return a new cache manager instance for this triple store
- */
- @Override
- public CacheManager createCacheManager(KiWiConfiguration configuration) {
- return new InfinispanEmbeddedCacheManager(configuration);
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2f22f5ca/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/BNodeExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/BNodeExternalizer.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/BNodeExternalizer.java
deleted file mode 100644
index 6fd89a5..0000000
--- a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/BNodeExternalizer.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.kiwi.externalizer;
-
-import org.apache.marmotta.kiwi.model.rdf.KiWiAnonResource;
-import org.infinispan.commons.marshall.AdvancedExternalizer;
-import org.infinispan.commons.util.Util;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Date;
-import java.util.Set;
-
-/**
- * Add file description here!
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class BNodeExternalizer implements AdvancedExternalizer<KiWiAnonResource> {
-
-
- @Override
- public Set<Class<? extends KiWiAnonResource>> getTypeClasses() {
- return Util.<Class<? extends KiWiAnonResource>>asSet(KiWiAnonResource.class);
- }
-
- @Override
- public Integer getId() {
- return ExternalizerIds.BNODE;
- }
-
- @Override
- public void writeObject(ObjectOutput output, KiWiAnonResource object) throws IOException {
- output.writeLong(object.getId());
- output.writeInt(object.stringValue().length());
- output.writeChars(object.stringValue());
- output.writeLong(object.getCreated().getTime());
- }
-
- @Override
- public KiWiAnonResource readObject(ObjectInput input) throws IOException, ClassNotFoundException {
- long id = input.readLong();
- int len = input.readInt();
-
- char[] anonId = new char[len];
- for(int i=0; i<len; i++) {
- anonId[i] = input.readChar();
- }
-
- Date created = new Date(input.readLong());
-
- KiWiAnonResource r = new KiWiAnonResource(new String(anonId),created);
- r.setId(id);
-
- return r;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2f22f5ca/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/BooleanLiteralExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/BooleanLiteralExternalizer.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/BooleanLiteralExternalizer.java
deleted file mode 100644
index ffb45d3..0000000
--- a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/BooleanLiteralExternalizer.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.kiwi.externalizer;
-
-import org.apache.marmotta.kiwi.model.rdf.KiWiBooleanLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
-import org.infinispan.commons.marshall.AdvancedExternalizer;
-import org.infinispan.commons.util.Util;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Date;
-import java.util.Set;
-
-/**
- * Add file description here!
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class BooleanLiteralExternalizer implements AdvancedExternalizer<KiWiBooleanLiteral> {
-
- @Override
- public Set<Class<? extends KiWiBooleanLiteral>> getTypeClasses() {
- return Util.<Class<? extends KiWiBooleanLiteral>>asSet(KiWiBooleanLiteral.class);
- }
-
- @Override
- public Integer getId() {
- return ExternalizerIds.BOOL_LITERAL;
- }
-
- @Override
- public void writeObject(ObjectOutput output, KiWiBooleanLiteral object) throws IOException {
- output.writeLong(object.getId());
- output.writeBoolean(object.booleanValue());
- output.writeObject(object.getDatatype());
-
- output.writeLong(object.getCreated().getTime());
-
- }
-
- @Override
- public KiWiBooleanLiteral readObject(ObjectInput input) throws IOException, ClassNotFoundException {
- long id = input.readLong();
- boolean content = input.readBoolean();
-
- KiWiUriResource dtype = (KiWiUriResource) input.readObject();
-
- Date created = new Date(input.readLong());
-
- KiWiBooleanLiteral r = new KiWiBooleanLiteral(content, dtype, created);
- r.setId(id);
-
- return r;
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2f22f5ca/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/DateLiteralExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/DateLiteralExternalizer.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/DateLiteralExternalizer.java
deleted file mode 100644
index afe83a4..0000000
--- a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/DateLiteralExternalizer.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.kiwi.externalizer;
-
-import org.apache.marmotta.kiwi.model.rdf.KiWiDateLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
-import org.infinispan.commons.marshall.AdvancedExternalizer;
-import org.infinispan.commons.util.Util;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Date;
-import java.util.Set;
-
-/**
- * Add file description here!
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class DateLiteralExternalizer implements AdvancedExternalizer<KiWiDateLiteral> {
-
- @Override
- public Set<Class<? extends KiWiDateLiteral>> getTypeClasses() {
- return Util.<Class<? extends KiWiDateLiteral>>asSet(KiWiDateLiteral.class);
- }
-
- @Override
- public Integer getId() {
- return ExternalizerIds.DATE_LITERAL;
- }
-
- @Override
- public void writeObject(ObjectOutput output, KiWiDateLiteral object) throws IOException {
- output.writeLong(object.getId());
- output.writeLong(object.getDateContent().getTime());
- output.writeObject(object.getDatatype());
-
- output.writeLong(object.getCreated().getTime());
-
- }
-
- @Override
- public KiWiDateLiteral readObject(ObjectInput input) throws IOException, ClassNotFoundException {
- long id = input.readLong();
- Date content = new Date(input.readLong());
-
- KiWiUriResource dtype = (KiWiUriResource) input.readObject();
-
- Date created = new Date(input.readLong());
-
- KiWiDateLiteral r = new KiWiDateLiteral(content, dtype, created);
- r.setId(id);
-
- return r;
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2f22f5ca/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/DoubleLiteralExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/DoubleLiteralExternalizer.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/DoubleLiteralExternalizer.java
deleted file mode 100644
index d153998..0000000
--- a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/DoubleLiteralExternalizer.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.kiwi.externalizer;
-
-import org.apache.marmotta.kiwi.model.rdf.KiWiDoubleLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
-import org.infinispan.commons.marshall.AdvancedExternalizer;
-import org.infinispan.commons.util.Util;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Date;
-import java.util.Set;
-
-/**
- * Add file description here!
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class DoubleLiteralExternalizer implements AdvancedExternalizer<KiWiDoubleLiteral> {
-
- @Override
- public Set<Class<? extends KiWiDoubleLiteral>> getTypeClasses() {
- return Util.<Class<? extends KiWiDoubleLiteral>>asSet(KiWiDoubleLiteral.class);
- }
-
- @Override
- public Integer getId() {
- return ExternalizerIds.DOUBLE_LITERAL;
- }
-
- @Override
- public void writeObject(ObjectOutput output, KiWiDoubleLiteral object) throws IOException {
- output.writeLong(object.getId());
- output.writeDouble(object.getDoubleContent());
- output.writeObject(object.getDatatype());
-
- output.writeLong(object.getCreated().getTime());
-
- }
-
- @Override
- public KiWiDoubleLiteral readObject(ObjectInput input) throws IOException, ClassNotFoundException {
- long id = input.readLong();
- double content = input.readDouble();
-
- KiWiUriResource dtype = (KiWiUriResource) input.readObject();
-
- Date created = new Date(input.readLong());
-
- KiWiDoubleLiteral r = new KiWiDoubleLiteral(content, dtype, created);
- r.setId(id);
-
- return r;
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2f22f5ca/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/ExternalizerIds.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/ExternalizerIds.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/ExternalizerIds.java
deleted file mode 100644
index 5be8cbe..0000000
--- a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/ExternalizerIds.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.kiwi.externalizer;
-
-/**
- * Add file description here!
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class ExternalizerIds {
-
- public static final int TRIPLE = 13;
-
- public static final int URI = 17;
-
- public static final int BNODE = 23;
-
- public static final int STRING_LITERAL = 19;
-
- public static final int INT_LITERAL = 39;
-
- public static final int DOUBLE_LITERAL = 37;
-
- public static final int DATE_LITERAL = 29;
-
- public static final int BOOL_LITERAL = 31;
-
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2f22f5ca/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/IntLiteralExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/IntLiteralExternalizer.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/IntLiteralExternalizer.java
deleted file mode 100644
index da71798..0000000
--- a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/IntLiteralExternalizer.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.kiwi.externalizer;
-
-import org.apache.marmotta.kiwi.model.rdf.KiWiIntLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
-import org.infinispan.commons.marshall.AdvancedExternalizer;
-import org.infinispan.commons.util.Util;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Date;
-import java.util.Set;
-
-/**
- * Add file description here!
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class IntLiteralExternalizer implements AdvancedExternalizer<KiWiIntLiteral> {
-
- @Override
- public Set<Class<? extends KiWiIntLiteral>> getTypeClasses() {
- return Util.<Class<? extends KiWiIntLiteral>>asSet(KiWiIntLiteral.class);
- }
-
- @Override
- public Integer getId() {
- return ExternalizerIds.INT_LITERAL;
- }
-
- @Override
- public void writeObject(ObjectOutput output, KiWiIntLiteral object) throws IOException {
- output.writeLong(object.getId());
- output.writeLong(object.getIntContent());
- output.writeObject(object.getDatatype());
-
- output.writeLong(object.getCreated().getTime());
-
- }
-
- @Override
- public KiWiIntLiteral readObject(ObjectInput input) throws IOException, ClassNotFoundException {
- long id = input.readLong();
- long content = input.readLong();
-
- KiWiUriResource dtype = (KiWiUriResource) input.readObject();
-
- Date created = new Date(input.readLong());
-
- KiWiIntLiteral r = new KiWiIntLiteral(content, dtype, created);
- r.setId(id);
-
- return r;
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2f22f5ca/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/StringLiteralExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/StringLiteralExternalizer.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/StringLiteralExternalizer.java
deleted file mode 100644
index 178c76a..0000000
--- a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/StringLiteralExternalizer.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.kiwi.externalizer;
-
-import org.apache.marmotta.commons.io.DataIO;
-import org.apache.marmotta.kiwi.model.rdf.KiWiStringLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
-import org.infinispan.commons.marshall.AdvancedExternalizer;
-import org.infinispan.commons.util.Util;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Date;
-import java.util.Locale;
-import java.util.Set;
-
-/**
- * Add file description here!
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class StringLiteralExternalizer implements AdvancedExternalizer<KiWiStringLiteral> {
-
- @Override
- public Set<Class<? extends KiWiStringLiteral>> getTypeClasses() {
- return Util.<Class<? extends KiWiStringLiteral>>asSet(KiWiStringLiteral.class);
- }
-
- @Override
- public Integer getId() {
- return ExternalizerIds.STRING_LITERAL;
- }
-
- @Override
- public void writeObject(ObjectOutput output, KiWiStringLiteral object) throws IOException {
- output.writeLong(object.getId());
-
- DataIO.writeString(output, object.getContent());
- DataIO.writeString(output, object.getLanguage());
-
- output.writeObject(object.getDatatype());
-
- output.writeLong(object.getCreated().getTime());
-
- }
-
- @Override
- public KiWiStringLiteral readObject(ObjectInput input) throws IOException, ClassNotFoundException {
- long id = input.readLong();
-
- String content = DataIO.readString(input);
- String lang = DataIO.readString(input);
-
- KiWiUriResource dtype = (KiWiUriResource) input.readObject();
-
- Date created = new Date(input.readLong());
-
- KiWiStringLiteral r = new KiWiStringLiteral(content, lang != null ? Locale.forLanguageTag(lang) : null, dtype, created);
- r.setId(id);
-
- return r;
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2f22f5ca/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/TripleExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/TripleExternalizer.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/TripleExternalizer.java
deleted file mode 100644
index 60793c1..0000000
--- a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/TripleExternalizer.java
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.kiwi.externalizer;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.marmotta.commons.io.DataIO;
-import org.apache.marmotta.kiwi.model.rdf.KiWiNode;
-import org.apache.marmotta.kiwi.model.rdf.KiWiResource;
-import org.apache.marmotta.kiwi.model.rdf.KiWiTriple;
-import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
-import org.infinispan.commons.marshall.AdvancedExternalizer;
-import org.infinispan.commons.util.Util;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Date;
-import java.util.Set;
-
-/**
- * An externalizer for Infinispan allowing to more efficiently transport triples by only serializing the node
- * IDs instead of the whole nodes.
- */
-public class TripleExternalizer implements AdvancedExternalizer<KiWiTriple> {
-
-
- public static final int MODE_DEFAULT = 1;
- public static final int MODE_PREFIX = 2;
-
-
- @Override
- public Set<Class<? extends KiWiTriple>> getTypeClasses() {
- return Util.<Class<? extends KiWiTriple>>asSet(KiWiTriple.class);
- }
-
- @Override
- public Integer getId() {
- return ExternalizerIds.TRIPLE;
- }
-
- @Override
- public void writeObject(ObjectOutput output, KiWiTriple object) throws IOException {
- output.writeLong(object.getId());
-
- // in case subject and object are both uris we use a special prefix-compressed mode
- if(object.getSubject().isUriResource() && object.getObject().isUriResource()) {
- String sUri = object.getSubject().stringValue();
- String oUri = object.getObject().stringValue();
-
- String prefix = StringUtils.getCommonPrefix(sUri,oUri);
-
- output.writeByte(MODE_PREFIX);
- DataIO.writeString(output,prefix);
-
- output.writeLong(object.getSubject().getId());
- DataIO.writeString(output, sUri.substring(prefix.length()));
- output.writeLong(object.getSubject().getCreated().getTime());
-
- output.writeObject(object.getPredicate());
-
- output.writeLong(object.getObject().getId());
- DataIO.writeString(output, oUri.substring(prefix.length()));
- output.writeLong(object.getObject().getCreated().getTime());
- } else {
- output.writeByte(MODE_DEFAULT);
-
- output.writeObject(object.getSubject());
- output.writeObject(object.getPredicate());
- output.writeObject(object.getObject());
- }
-
- output.writeObject(object.getContext());
- output.writeObject(object.getCreator());
- output.writeBoolean(object.isDeleted());
- output.writeBoolean(object.isInferred());
- output.writeBoolean(object.isNewTriple());
- output.writeLong(object.getCreated().getTime());
- if(object.getDeletedAt() != null) {
- output.writeLong(object.getDeletedAt().getTime());
- } else {
- output.writeLong(0);
- }
- }
-
- @Override
- public KiWiTriple readObject(ObjectInput input) throws IOException, ClassNotFoundException {
-
- KiWiTriple result = new KiWiTriple();
- result.setId(input.readLong());
-
- int mode = input.readByte();
- if(mode == MODE_PREFIX) {
- String prefix = DataIO.readString(input);
-
- long sId = input.readLong();
- String sUri = prefix + DataIO.readString(input);
- long sTime = input.readLong();
- KiWiUriResource s = new KiWiUriResource(sUri);
- s.setId(sId);
- s.setCreated(new Date(sTime));
- result.setSubject(s);
-
- result.setPredicate((KiWiUriResource) input.readObject());
-
- long oId = input.readLong();
- String oUri = prefix + DataIO.readString(input);
- long oTime = input.readLong();
- KiWiUriResource o = new KiWiUriResource(oUri);
- o.setId(oId);
- o.setCreated(new Date(oTime));
- result.setObject(o);
-
- } else {
- result.setSubject((KiWiResource) input.readObject());
- result.setPredicate((KiWiUriResource) input.readObject());
- result.setObject((KiWiNode) input.readObject());
- }
- result.setContext((KiWiResource) input.readObject());
- result.setCreator((KiWiResource) input.readObject());
- result.setDeleted(input.readBoolean());
- result.setInferred(input.readBoolean());
- result.setNewTriple(input.readBoolean());
-
- result.setCreated(new Date(input.readLong()));
-
- long deletedAt = input.readLong();
- if(deletedAt > 0) {
- result.setDeletedAt(new Date(deletedAt));
- }
-
-
- return result;
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2f22f5ca/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/UriExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/UriExternalizer.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/UriExternalizer.java
deleted file mode 100644
index 3db4d4e..0000000
--- a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/externalizer/UriExternalizer.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.kiwi.externalizer;
-
-import org.apache.marmotta.commons.io.DataIO;
-import org.apache.marmotta.commons.vocabulary.XSD;
-import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
-import org.infinispan.commons.marshall.AdvancedExternalizer;
-import org.infinispan.commons.util.Util;
-import org.openrdf.model.vocabulary.*;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Date;
-import java.util.Set;
-
-/**
- * Add file description here!
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class UriExternalizer implements AdvancedExternalizer<KiWiUriResource> {
-
- private static final int PREFIX_UNKNOWN = 0;
- private static final int PREFIX_XSD = 1;
- private static final int PREFIX_RDF = 2;
- private static final int PREFIX_RDFS = 3;
- private static final int PREFIX_SKOS = 4;
- private static final int PREFIX_DC = 5;
- private static final int PREFIX_DCT = 6;
- private static final int PREFIX_OWL = 7;
-
- @Override
- public Set<Class<? extends KiWiUriResource>> getTypeClasses() {
- return Util.<Class<? extends KiWiUriResource>>asSet(KiWiUriResource.class);
- }
-
- @Override
- public Integer getId() {
- return ExternalizerIds.URI;
- }
-
- @Override
- public void writeObject(ObjectOutput output, KiWiUriResource object) throws IOException {
- output.writeLong(object.getId());
-
- // compression for commonly used constant prefixes
- if(object.stringValue().startsWith(XSD.NAMESPACE)) {
- output.writeByte(PREFIX_XSD);
- DataIO.writeString(output, object.stringValue().substring(XSD.NAMESPACE.length()));
- } else if(object.stringValue().startsWith(RDF.NAMESPACE)) {
- output.writeByte(PREFIX_RDF);
- DataIO.writeString(output, object.stringValue().substring(RDF.NAMESPACE.length()));
- } else if(object.stringValue().startsWith(RDFS.NAMESPACE)) {
- output.writeByte(PREFIX_RDFS);
- DataIO.writeString(output, object.stringValue().substring(RDFS.NAMESPACE.length()));
- } else if(object.stringValue().startsWith(SKOS.NAMESPACE)) {
- output.writeByte(PREFIX_SKOS);
- DataIO.writeString(output, object.stringValue().substring(SKOS.NAMESPACE.length()));
- } else if(object.stringValue().startsWith(DC.NAMESPACE)) {
- output.writeByte(PREFIX_DC);
- DataIO.writeString(output, object.stringValue().substring(DC.NAMESPACE.length()));
- } else if(object.stringValue().startsWith(DCTERMS.NAMESPACE)) {
- output.writeByte(PREFIX_DCT);
- DataIO.writeString(output, object.stringValue().substring(DCTERMS.NAMESPACE.length()));
- } else if(object.stringValue().startsWith(OWL.NAMESPACE)) {
- output.writeByte(PREFIX_OWL);
- DataIO.writeString(output, object.stringValue().substring(OWL.NAMESPACE.length()));
- } else {
- output.writeByte(PREFIX_UNKNOWN);
- DataIO.writeString(output, object.stringValue());
- }
-
- output.writeLong(object.getCreated().getTime());
- }
-
- @Override
- public KiWiUriResource readObject(ObjectInput input) throws IOException, ClassNotFoundException {
- long id = input.readLong();
-
- int prefixMode = input.readByte();
- String uriPrefix = "";
- String uriSuffix = DataIO.readString(input);
-
- switch (prefixMode) {
- case PREFIX_XSD:
- uriPrefix = XSD.NAMESPACE;
- break;
- case PREFIX_RDF:
- uriPrefix = RDF.NAMESPACE;
- break;
- case PREFIX_RDFS:
- uriPrefix = RDFS.NAMESPACE;
- break;
- case PREFIX_SKOS:
- uriPrefix = SKOS.NAMESPACE;
- break;
- case PREFIX_DC:
- uriPrefix = DC.NAMESPACE;
- break;
- case PREFIX_DCT:
- uriPrefix = DCTERMS.NAMESPACE;
- break;
- case PREFIX_OWL:
- uriPrefix = OWL.NAMESPACE;
- break;
- default:
- uriPrefix = "";
- break;
- }
-
- Date created = new Date(input.readLong());
-
- KiWiUriResource r = new KiWiUriResource(uriPrefix + uriSuffix,created);
- r.setId(id);
-
- return r;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2f22f5ca/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/embedded/InfinispanEmbeddedCacheManager.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/embedded/InfinispanEmbeddedCacheManager.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/embedded/InfinispanEmbeddedCacheManager.java
new file mode 100644
index 0000000..5cf5953
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/embedded/InfinispanEmbeddedCacheManager.java
@@ -0,0 +1,517 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.marmotta.kiwi.infinispan.embedded;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.marmotta.kiwi.caching.CacheManager;
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+import org.apache.marmotta.kiwi.infinispan.externalizer.*;
+import org.infinispan.Cache;
+import org.infinispan.commons.CacheException;
+import org.infinispan.commons.marshall.AdvancedExternalizer;
+import org.infinispan.configuration.cache.CacheMode;
+import org.infinispan.configuration.cache.Configuration;
+import org.infinispan.configuration.cache.ConfigurationBuilder;
+import org.infinispan.configuration.global.GlobalConfiguration;
+import org.infinispan.configuration.global.GlobalConfigurationBuilder;
+import org.infinispan.context.Flag;
+import org.infinispan.distribution.ch.SyncConsistentHashFactory;
+import org.infinispan.eviction.EvictionStrategy;
+import org.infinispan.lifecycle.ComponentStatus;
+import org.infinispan.manager.DefaultCacheManager;
+import org.infinispan.manager.EmbeddedCacheManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * A class for managing the different caches that are used by the triple store.
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class InfinispanEmbeddedCacheManager implements CacheManager {
+
+ private static Logger log = LoggerFactory.getLogger(InfinispanEmbeddedCacheManager.class);
+
+ public static final String NODE_CACHE = "node-cache";
+ public static final String TRIPLE_CACHE = "triple-cache";
+ public static final String URI_CACHE = "uri-cache";
+ public static final String BNODE_CACHE = "bnode-cache";
+ public static final String LITERAL_CACHE = "literal-cache";
+ public static final String NAMESPACE_URI_CACHE = "namespace-uri-cache";
+ public static final String NAMESPACE_PREFIX_CACHE = "namespace-prefix-cache";
+ public static final String LOADER_CACHE = "loader-cache";
+ public static final String REGISTRY_CACHE = "registry-cache";
+
+ private EmbeddedCacheManager cacheManager;
+
+ // default configuration: distributed cache, 100000 entries, 300 seconds expiration, 60 seconds idle
+ private Configuration defaultConfiguration;
+
+ private KiWiConfiguration config;
+
+ private Cache nodeCache, tripleCache, uriCache, literalCache, bnodeCache, nsPrefixCache, nsUriCache, registryCache;
+
+
+ /**
+ * Create a new cache manager with its own automatically created Infinispan instance.
+ *
+ * @param config
+ */
+ public InfinispanEmbeddedCacheManager(KiWiConfiguration config) {
+
+
+ this.config = config;
+
+ try {
+ switch (config.getCacheMode()) {
+ case DISTRIBUTED:
+ buildDistributedConfiguration(getExternalizers());
+ break;
+ case REPLICATED:
+ buildReplicatedConfiguration(getExternalizers());
+ break;
+ case LOCAL:
+ buildLocalConfiguration();
+ break;
+ }
+ } catch (IOException ex) {
+ log.warn("error while building cache cluster configuration, reverting to local cache");
+ buildLocalConfiguration();
+ }
+
+
+ }
+
+ /**
+ * Build a local cache configuration.
+ * <p/>
+ * In local cache mode, the cache is not shared among the servers in a cluster. Each machine keeps a local cache.
+ * This allows quick startups and eliminates network traffic in the cluster, but subsequent requests to different
+ * cluster members cannot benefit from the cached data.
+ */
+ protected void buildLocalConfiguration() {
+ GlobalConfiguration globalConfiguration = new GlobalConfigurationBuilder()
+ .classLoader(InfinispanEmbeddedCacheManager.class.getClassLoader())
+ .globalJmxStatistics()
+ .jmxDomain("org.apache.marmotta.kiwi")
+ .allowDuplicateDomains(true)
+ .build();
+
+ defaultConfiguration = new ConfigurationBuilder()
+ .clustering()
+ .cacheMode(CacheMode.LOCAL)
+ .eviction()
+ .strategy(EvictionStrategy.LIRS)
+ .maxEntries(100000)
+ .expiration()
+ .lifespan(5, TimeUnit.MINUTES)
+ .maxIdle(1, TimeUnit.MINUTES)
+ .build();
+ cacheManager = new DefaultCacheManager(globalConfiguration, defaultConfiguration, true);
+
+ log.info("initialised Infinispan local cache manager");
+ }
+
+ /**
+ * Build a distributed cache configuration.
+ * <p/>
+ * In distributed cache mode, the cluster forms a big hash table used as a cache. This allows to make efficient
+ * use of the large amount of memory available, but requires cache rebalancing and a lot of network transfers,
+ * especially in case cluster members are restarted often.
+ */
+ protected void buildDistributedConfiguration(AdvancedExternalizer...externalizers) throws IOException {
+ String jgroupsXml = IOUtils.toString(InfinispanEmbeddedCacheManager.class.getResourceAsStream("/jgroups-kiwi.xml"));
+
+ jgroupsXml = jgroupsXml.replaceAll("mcast_addr=\"[0-9.]+\"", String.format("mcast_addr=\"%s\"", config.getClusterAddress()));
+ jgroupsXml = jgroupsXml.replaceAll("mcast_port=\"[0-9]+\"", String.format("mcast_port=\"%d\"", config.getClusterPort()));
+
+
+ GlobalConfiguration globalConfiguration = new GlobalConfigurationBuilder()
+ .classLoader(InfinispanEmbeddedCacheManager.class.getClassLoader())
+ .transport()
+ .defaultTransport()
+ .clusterName(config.getClusterName())
+ .machineId("instance-" + config.getDatacenterId())
+ .addProperty("configurationXml", jgroupsXml)
+ .globalJmxStatistics()
+ .jmxDomain("org.apache.marmotta.kiwi")
+ .allowDuplicateDomains(true)
+ .serialization()
+ .addAdvancedExternalizer(externalizers)
+ .build();
+
+ defaultConfiguration = new ConfigurationBuilder()
+ .clustering()
+ .cacheMode(CacheMode.DIST_ASYNC)
+ .async()
+ .asyncMarshalling()
+ .l1()
+ .lifespan(5, TimeUnit.MINUTES)
+ .hash()
+ .numOwners(2)
+ .numSegments(40)
+ .consistentHashFactory(new SyncConsistentHashFactory())
+ .stateTransfer()
+ .fetchInMemoryState(false)
+ .eviction()
+ .strategy(EvictionStrategy.LIRS)
+ .maxEntries(100000)
+ .expiration()
+ .lifespan(30, TimeUnit.MINUTES)
+ .maxIdle(10, TimeUnit.MINUTES)
+ .build();
+ cacheManager = new DefaultCacheManager(globalConfiguration, defaultConfiguration, true);
+
+ log.info("initialised Infinispan distributed cache manager (cluster name: {})", globalConfiguration.transport().clusterName());
+
+ }
+
+ /**
+ * Build a replicated cache configuration.
+ * <p/>
+ * In replicated cache mode, each node in the cluster has an identical copy of all cache data. This allows
+ * very efficient cache lookups and reduces the rebalancing effort, but requires more memory.
+ */
+ protected void buildReplicatedConfiguration(AdvancedExternalizer...externalizers) throws IOException {
+ String jgroupsXml = IOUtils.toString(InfinispanEmbeddedCacheManager.class.getResourceAsStream("/jgroups-kiwi.xml"));
+
+ jgroupsXml = jgroupsXml.replaceAll("mcast_addr=\"[0-9.]+\"", String.format("mcast_addr=\"%s\"", config.getClusterAddress()));
+ jgroupsXml = jgroupsXml.replaceAll("mcast_port=\"[0-9]+\"", String.format("mcast_port=\"%d\"", config.getClusterPort()));
+
+
+ GlobalConfiguration globalConfiguration = new GlobalConfigurationBuilder()
+ .classLoader(InfinispanEmbeddedCacheManager.class.getClassLoader())
+ .transport()
+ .defaultTransport()
+ .clusterName(config.getClusterName())
+ .machineId("instance-" + config.getDatacenterId())
+ .addProperty("configurationXml", jgroupsXml)
+ .globalJmxStatistics()
+ .jmxDomain("org.apache.marmotta.kiwi")
+ .allowDuplicateDomains(true)
+ .serialization()
+ .addAdvancedExternalizer(externalizers)
+ .build();
+
+ defaultConfiguration = new ConfigurationBuilder()
+ .clustering()
+ .cacheMode(CacheMode.REPL_ASYNC)
+ .async()
+ .asyncMarshalling()
+ .stateTransfer()
+ .fetchInMemoryState(false)
+ .eviction()
+ .strategy(EvictionStrategy.LIRS)
+ .maxEntries(100000)
+ .expiration()
+ .lifespan(30, TimeUnit.MINUTES)
+ .maxIdle(10, TimeUnit.MINUTES)
+ .build();
+ cacheManager = new DefaultCacheManager(globalConfiguration, defaultConfiguration, true);
+
+ log.info("initialised Infinispan replicated cache manager (cluster name: {})", globalConfiguration.transport().clusterName());
+ }
+
+
+ protected boolean isClustered() {
+ return config.getCacheMode() == org.apache.marmotta.kiwi.config.CacheMode.DISTRIBUTED ||
+ config.getCacheMode() == org.apache.marmotta.kiwi.config.CacheMode.REPLICATED;
+ }
+
+
+ private AdvancedExternalizer[] getExternalizers() {
+ return new AdvancedExternalizer[] {
+ new TripleExternalizer(),
+ new UriExternalizer(),
+ new BNodeExternalizer(),
+ new StringLiteralExternalizer(),
+ new DateLiteralExternalizer(),
+ new BooleanLiteralExternalizer(),
+ new IntLiteralExternalizer(),
+ new DoubleLiteralExternalizer()
+ };
+ }
+
+ /**
+ * Return the node id -> node cache from the cache manager. This cache is heavily used to lookup
+ * nodes when querying or loading triples and should therefore have a decent size (default 500.000 elements).
+ *
+ * @return an EHCache Cache instance containing the node id -> node mappings
+ */
+ public Cache getNodeCache() {
+ if(nodeCache == null) {
+ Configuration nodeConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
+ .eviction()
+ .maxEntries(1000000)
+ .expiration()
+ .lifespan(60, TimeUnit.MINUTES)
+ .maxIdle(30, TimeUnit.MINUTES)
+ .build();
+ cacheManager.defineConfiguration(NODE_CACHE, nodeConfiguration);
+
+ nodeCache = cacheManager.getCache(NODE_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
+ }
+
+ return nodeCache;
+ }
+
+ /**
+ * Return the triple id -> triple cache from the cache manager. This cache is used for speeding up the
+ * construction of query results.
+ *
+ * @return
+ */
+ public Cache getTripleCache() {
+ if(tripleCache == null) {
+ Configuration tripleConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
+ .clustering()
+ .cacheMode(CacheMode.LOCAL)
+ .eviction()
+ .maxEntries(config.getTripleCacheSize())
+ .expiration()
+ .lifespan(60, TimeUnit.MINUTES)
+ .maxIdle(30, TimeUnit.MINUTES)
+ .build();
+ cacheManager.defineConfiguration(TRIPLE_CACHE, tripleConfiguration);
+
+ tripleCache = cacheManager.getCache(TRIPLE_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
+ }
+ return tripleCache;
+ }
+
+
+ /**
+ * Return the uri -> KiWiUriResource cache from the cache manager. This cache is used when constructing new
+ * KiWiUriResources to avoid a database lookup.
+ *
+ * @return
+ */
+ public Cache getUriCache() {
+ if(uriCache == null) {
+ Configuration uriConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
+ .eviction()
+ .maxEntries(config.getUriCacheSize())
+ .build();
+ cacheManager.defineConfiguration(URI_CACHE, uriConfiguration);
+
+ uriCache = cacheManager.getCache(URI_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
+ }
+ return uriCache;
+ }
+
+
+ /**
+ * Return the anonId -> KiWiAnonResource cache from the cache manager. This cache is used when constructing new
+ * KiWiAnonResources to avoid a database lookup.
+ *
+ * @return
+ */
+ public Cache getBNodeCache() {
+ if(bnodeCache == null) {
+ Configuration bnodeConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
+ .eviction()
+ .maxEntries(config.getBNodeCacheSize())
+ .build();
+ cacheManager.defineConfiguration(BNODE_CACHE, bnodeConfiguration);
+
+ bnodeCache = cacheManager.getCache(BNODE_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
+ }
+ return bnodeCache;
+ }
+
+ /**
+ * Return the literal cache key -> KiWiLiteral cache from the cache manager. This cache is used when constructing new
+ * KiWiLiterals to avoid a database lookup.
+ *
+ * @see org.apache.marmotta.commons.sesame.model.LiteralCommons#createCacheKey(String, java.util.Locale, String)
+ * @return
+ */
+ public Cache getLiteralCache() {
+ if(literalCache == null) {
+ Configuration literalConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
+ .eviction()
+ .maxEntries(config.getLiteralCacheSize())
+ .build();
+ cacheManager.defineConfiguration(LITERAL_CACHE, literalConfiguration);
+
+ literalCache = cacheManager.getCache(LITERAL_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
+ }
+ return literalCache;
+ }
+
+
+ /**
+ * Return the URI -> namespace cache from the cache manager. Used for looking up namespaces
+ * @return
+ */
+ public Cache getNamespaceUriCache() {
+ if(nsUriCache == null) {
+ if(isClustered()) {
+ Configuration nsuriConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
+ .clustering()
+ .cacheMode(CacheMode.REPL_ASYNC)
+ .eviction()
+ .maxEntries(config.getNamespaceCacheSize())
+ .expiration()
+ .lifespan(1, TimeUnit.DAYS)
+ .build();
+ cacheManager.defineConfiguration(NAMESPACE_URI_CACHE, nsuriConfiguration);
+ } else {
+ Configuration nsuriConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
+ .eviction()
+ .maxEntries(config.getNamespaceCacheSize())
+ .expiration()
+ .lifespan(1, TimeUnit.HOURS)
+ .build();
+ cacheManager.defineConfiguration(NAMESPACE_URI_CACHE, nsuriConfiguration);
+ }
+
+ nsUriCache = cacheManager.getCache(NAMESPACE_URI_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
+ }
+ return nsUriCache;
+ }
+
+ /**
+ * Return the prefix -> namespace cache from the cache manager. Used for looking up namespaces
+ * @return
+ */
+ public Cache getNamespacePrefixCache() {
+ if(nsPrefixCache == null) {
+ if(isClustered()) {
+ Configuration nsprefixConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
+ .clustering()
+ .cacheMode(CacheMode.REPL_ASYNC)
+ .eviction()
+ .maxEntries(config.getNamespaceCacheSize())
+ .expiration()
+ .lifespan(1, TimeUnit.DAYS)
+ .build();
+ cacheManager.defineConfiguration(NAMESPACE_PREFIX_CACHE, nsprefixConfiguration);
+
+ } else {
+ Configuration nsprefixConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
+ .eviction()
+ .maxEntries(config.getNamespaceCacheSize())
+ .expiration()
+ .lifespan(1, TimeUnit.HOURS)
+ .build();
+ cacheManager.defineConfiguration(NAMESPACE_PREFIX_CACHE, nsprefixConfiguration);
+
+ }
+ nsPrefixCache = cacheManager.getCache(NAMESPACE_PREFIX_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
+ }
+ return nsPrefixCache;
+ }
+
+
+
+
+ /**
+ * Create and return the cache used by the CacheTripleRegistry. This is an unlimited synchronous replicated
+ * cache and should be used with care.
+ * @return
+ */
+ public Cache getRegistryCache() {
+ if(registryCache == null) {
+ if(isClustered()) {
+ Configuration registryConfiguration = new ConfigurationBuilder()
+ .clustering()
+ .cacheMode(CacheMode.REPL_SYNC)
+ .sync()
+ .replTimeout(15, TimeUnit.SECONDS)
+ .eviction()
+ .strategy(EvictionStrategy.NONE)
+ .build();
+ cacheManager.defineConfiguration(REGISTRY_CACHE, registryConfiguration);
+ } else {
+ Configuration registryConfiguration = new ConfigurationBuilder()
+ .clustering()
+ .cacheMode(CacheMode.LOCAL)
+ .eviction()
+ .strategy(EvictionStrategy.NONE)
+ .build();
+ cacheManager.defineConfiguration(REGISTRY_CACHE, registryConfiguration);
+ }
+
+ registryCache = cacheManager.getCache(REGISTRY_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
+ }
+ return registryCache;
+ }
+
+ /**
+ * Get the cache with the given name from the cache manager. Can be used to request additional
+ * caches from the cache manager that are not covered by explicit methods.
+ *
+ * @param name
+ * @return
+ */
+ public synchronized Cache getCacheByName(String name) {
+ if(!cacheManager.cacheExists(name)) {
+ cacheManager.defineConfiguration(name, new ConfigurationBuilder().read(defaultConfiguration).build());
+ }
+ return cacheManager.getCache(name).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
+
+ }
+
+ /**
+ * Clear all caches managed by this cache manager.
+ */
+ public void clear() {
+ Set<String> set = cacheManager.getCacheNames();
+ Iterator<String> iterator = set.iterator();
+ while(iterator.hasNext()){
+ String cacheName = iterator.next();
+ Cache<String,Object> cache = cacheManager.getCache(cacheName);
+ cache.clear();
+ }
+
+ nodeCache = null;
+ tripleCache = null;
+ uriCache = null;
+ literalCache = null;
+ bnodeCache = null;
+ nsPrefixCache = null;
+ nsUriCache = null;
+ registryCache = null;
+ }
+
+ /**
+ * Shutdown this cache manager instance. Will shutdown the underlying EHCache cache manager.
+ */
+ public void shutdown() {
+ try {
+ if(cacheManager.getStatus() == ComponentStatus.RUNNING) {
+ log.warn("shutting down cache manager ...");
+// if(cacheManager.getTransport() != null) {
+// log.info("... shutting down transport ...");
+// cacheManager.getTransport().stop();
+// }
+ log.info("... shutting down main component ...");
+ cacheManager.stop();
+ log.info("... done!");
+ }
+ } catch (CacheException ex) {
+ log.warn("error shutting down cache: {}", ex.getMessage());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2f22f5ca/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/embedded/InfinispanEmbeddedCacheManagerFactory.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/embedded/InfinispanEmbeddedCacheManagerFactory.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/embedded/InfinispanEmbeddedCacheManagerFactory.java
new file mode 100644
index 0000000..f3aa8cb
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/embedded/InfinispanEmbeddedCacheManagerFactory.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.infinispan.embedded;
+
+import org.apache.marmotta.kiwi.caching.CacheManager;
+import org.apache.marmotta.kiwi.caching.CacheManagerFactory;
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class InfinispanEmbeddedCacheManagerFactory implements CacheManagerFactory {
+
+ public InfinispanEmbeddedCacheManagerFactory() {
+ }
+
+ /**
+ * Create a new cache manager instance using the KiWiConfiguration passed as argument.
+ *
+ * @param configuration KiWi configuration used by the underlying triple store
+ * @return a new cache manager instance for this triple store
+ */
+ @Override
+ public CacheManager createCacheManager(KiWiConfiguration configuration) {
+ return new InfinispanEmbeddedCacheManager(configuration);
+ }
+}
[02/21] started working on cleaner cache API for KiWi
Posted by ss...@apache.org.
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/CacheManager.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/CacheManager.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/CacheManager.java
new file mode 100644
index 0000000..167b0c9
--- /dev/null
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/CacheManager.java
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.caching;
+
+import org.apache.marmotta.kiwi.model.rdf.*;
+
+import java.util.Map;
+
+/**
+ * A generic cache manager API implemented by different caching backends. Each cache should be made accessible
+ * using the Java Map interface.
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public interface CacheManager {
+
+
+ /**
+ * Return the node id -> node cache from the cache manager. This cache is heavily used to lookup
+ * nodes when querying or loading triples and should therefore have a decent size (default 500.000 elements).
+ *
+ * @return an EHCache Cache instance containing the node id -> node mappings
+ */
+ public Map<Long, KiWiNode> getNodeCache();
+
+
+ /**
+ * Return the triple id -> triple cache from the cache manager. This cache is used for speeding up the
+ * construction of query results.
+ *
+ * @return
+ */
+ public Map<Long, KiWiTriple> getTripleCache();
+
+
+ /**
+ * Return the uri -> KiWiUriResource cache from the cache manager. This cache is used when constructing new
+ * KiWiUriResources to avoid a database lookup.
+ *
+ * @return
+ */
+ public Map<String, KiWiUriResource> getUriCache();
+
+
+ /**
+ * Return the anonId -> KiWiAnonResource cache from the cache manager. This cache is used when constructing new
+ * KiWiAnonResources to avoid a database lookup.
+ *
+ * @return
+ */
+ public Map<String, KiWiAnonResource> getBNodeCache();
+
+
+
+ /**
+ * Return the literal cache key -> KiWiLiteral cache from the cache manager. This cache is used when constructing new
+ * KiWiLiterals to avoid a database lookup.
+ *
+ * @see org.apache.marmotta.commons.sesame.model.LiteralCommons#createCacheKey(String, java.util.Locale, String)
+ * @return
+ */
+ public Map<String, KiWiLiteral> getLiteralCache();
+
+
+ /**
+ * Return the URI -> namespace cache from the cache manager. Used for looking up namespaces
+ * @return
+ */
+ public Map<String, KiWiNamespace> getNamespaceUriCache();
+
+
+ /**
+ * Return the prefix -> namespace cache from the cache manager. Used for looking up namespaces
+ * @return
+ */
+ public Map<String, KiWiNamespace> getNamespacePrefixCache();
+
+
+ /**
+ * Create and return the cache used by the CacheTripleRegistry. This is an unlimited synchronous replicated
+ * cache and should be used with care.
+ * @return
+ */
+ public Map<Long,Long> getRegistryCache();
+
+
+
+ /**
+ * Get the cache with the given name from the cache manager. Can be used to request additional
+ * caches from the cache manager that are not covered by explicit methods.
+ *
+ * @param name
+ * @return
+ */
+ public Map getCacheByName(String name);
+
+
+ /**
+ * Clear all caches managed by this cache manager.
+ */
+ public void clear();
+
+ /**
+ * Shutdown this cache manager instance. Will shutdown the underlying EHCache cache manager.
+ */
+ public void shutdown();
+
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/CacheManagerFactory.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/CacheManagerFactory.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/CacheManagerFactory.java
new file mode 100644
index 0000000..3a33e05
--- /dev/null
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/CacheManagerFactory.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.caching;
+
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+
+/**
+ * Factory classes for creating cache manager instances.
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public interface CacheManagerFactory {
+
+ /**
+ * Create a new cache manager instance using the KiWiConfiguration passed as argument.
+ *
+ * @param configuration KiWi configuration used by the underlying triple store
+ * @return a new cache manager instance for this triple store
+ */
+ public CacheManager createCacheManager(KiWiConfiguration configuration);
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/DateLiteralExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/DateLiteralExternalizer.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/DateLiteralExternalizer.java
deleted file mode 100644
index ba0db2b..0000000
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/DateLiteralExternalizer.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.kiwi.caching;
-
-import org.apache.marmotta.kiwi.model.rdf.KiWiDateLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
-import org.infinispan.commons.marshall.AdvancedExternalizer;
-import org.infinispan.commons.util.Util;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Date;
-import java.util.Set;
-
-/**
- * Add file description here!
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class DateLiteralExternalizer implements AdvancedExternalizer<KiWiDateLiteral> {
-
- @Override
- public Set<Class<? extends KiWiDateLiteral>> getTypeClasses() {
- return Util.<Class<? extends KiWiDateLiteral>>asSet(KiWiDateLiteral.class);
- }
-
- @Override
- public Integer getId() {
- return ExternalizerIds.DATE_LITERAL;
- }
-
- @Override
- public void writeObject(ObjectOutput output, KiWiDateLiteral object) throws IOException {
- output.writeLong(object.getId());
- output.writeLong(object.getDateContent().getTime());
- output.writeObject(object.getDatatype());
-
- output.writeLong(object.getCreated().getTime());
-
- }
-
- @Override
- public KiWiDateLiteral readObject(ObjectInput input) throws IOException, ClassNotFoundException {
- long id = input.readLong();
- Date content = new Date(input.readLong());
-
- KiWiUriResource dtype = (KiWiUriResource) input.readObject();
-
- Date created = new Date(input.readLong());
-
- KiWiDateLiteral r = new KiWiDateLiteral(content, dtype, created);
- r.setId(id);
-
- return r;
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/DoubleLiteralExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/DoubleLiteralExternalizer.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/DoubleLiteralExternalizer.java
deleted file mode 100644
index 710a8a3..0000000
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/DoubleLiteralExternalizer.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.kiwi.caching;
-
-import org.apache.marmotta.kiwi.model.rdf.KiWiDoubleLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
-import org.infinispan.commons.marshall.AdvancedExternalizer;
-import org.infinispan.commons.util.Util;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Date;
-import java.util.Set;
-
-/**
- * Add file description here!
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class DoubleLiteralExternalizer implements AdvancedExternalizer<KiWiDoubleLiteral> {
-
- @Override
- public Set<Class<? extends KiWiDoubleLiteral>> getTypeClasses() {
- return Util.<Class<? extends KiWiDoubleLiteral>>asSet(KiWiDoubleLiteral.class);
- }
-
- @Override
- public Integer getId() {
- return ExternalizerIds.DOUBLE_LITERAL;
- }
-
- @Override
- public void writeObject(ObjectOutput output, KiWiDoubleLiteral object) throws IOException {
- output.writeLong(object.getId());
- output.writeDouble(object.getDoubleContent());
- output.writeObject(object.getDatatype());
-
- output.writeLong(object.getCreated().getTime());
-
- }
-
- @Override
- public KiWiDoubleLiteral readObject(ObjectInput input) throws IOException, ClassNotFoundException {
- long id = input.readLong();
- double content = input.readDouble();
-
- KiWiUriResource dtype = (KiWiUriResource) input.readObject();
-
- Date created = new Date(input.readLong());
-
- KiWiDoubleLiteral r = new KiWiDoubleLiteral(content, dtype, created);
- r.setId(id);
-
- return r;
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/ExternalizerIds.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/ExternalizerIds.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/ExternalizerIds.java
deleted file mode 100644
index da1eb64..0000000
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/ExternalizerIds.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.kiwi.caching;
-
-/**
- * Add file description here!
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class ExternalizerIds {
-
- public static final int URI = 17;
-
- public static final int BNODE = 23;
-
- public static final int STRING_LITERAL = 19;
-
- public static final int INT_LITERAL = 39;
-
- public static final int DOUBLE_LITERAL = 37;
-
- public static final int DATE_LITERAL = 29;
-
- public static final int BOOL_LITERAL = 31;
-
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/GuavaCacheManager.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/GuavaCacheManager.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/GuavaCacheManager.java
new file mode 100644
index 0000000..d60221c
--- /dev/null
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/GuavaCacheManager.java
@@ -0,0 +1,233 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.caching;
+
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+import org.apache.marmotta.kiwi.model.rdf.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * A simple implementation of a cache manager using the Guava caching functionality. Does not support clustered
+ * operation.
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class GuavaCacheManager implements CacheManager {
+
+ private static Logger log = LoggerFactory.getLogger(GuavaCacheManager.class);
+
+ private KiWiConfiguration configuration;
+
+ private Cache<Long,KiWiNode> nodeCache;
+ private Cache<Long,KiWiTriple> tripleCache;
+ private Cache<String,KiWiUriResource> uriCache;
+ private Cache<String,KiWiAnonResource> bnodeCache;
+ private Cache<String,KiWiLiteral> literalCache;
+ private Cache<String,KiWiNamespace> namespaceUriCache, namespacePrefixCache;
+ private ConcurrentHashMap<Long,Long> registryCache;
+
+ private Map<String,Cache> dynamicCaches;
+
+
+ public GuavaCacheManager(KiWiConfiguration configuration) {
+ this.configuration = configuration;
+
+ log.info("initialising Guava in-memory caching backend ...");
+
+ if(configuration.isClustered()) {
+ log.warn("clustering not supported by Guava in-memory caching backend; please use Infinispan or Hazelcast instead!");
+ }
+
+ nodeCache = CacheBuilder.newBuilder()
+ .maximumSize(configuration.getNodeCacheSize())
+ .expireAfterAccess(30, TimeUnit.MINUTES)
+ .build();
+
+ tripleCache = CacheBuilder.newBuilder()
+ .maximumSize(configuration.getTripleCacheSize())
+ .expireAfterAccess(30, TimeUnit.MINUTES)
+ .build();
+
+ uriCache = CacheBuilder.newBuilder()
+ .maximumSize(configuration.getUriCacheSize())
+ .expireAfterAccess(30, TimeUnit.MINUTES)
+ .build();
+
+ bnodeCache = CacheBuilder.newBuilder()
+ .maximumSize(configuration.getBNodeCacheSize())
+ .expireAfterAccess(30, TimeUnit.MINUTES)
+ .build();
+
+ literalCache = CacheBuilder.newBuilder()
+ .maximumSize(configuration.getLiteralCacheSize())
+ .expireAfterAccess(30, TimeUnit.MINUTES)
+ .build();
+
+ namespaceUriCache = CacheBuilder.newBuilder()
+ .maximumSize(configuration.getNamespaceCacheSize())
+ .expireAfterAccess(1, TimeUnit.DAYS)
+ .build();
+
+ namespacePrefixCache = CacheBuilder.newBuilder()
+ .maximumSize(configuration.getNamespaceCacheSize())
+ .expireAfterAccess(1, TimeUnit.DAYS)
+ .build();
+
+
+ registryCache = new ConcurrentHashMap<>();
+
+ dynamicCaches = new HashMap<>();
+
+ }
+
+ /**
+ * Return the node id -> node cache from the cache manager. This cache is heavily used to lookup
+ * nodes when querying or loading triples and should therefore have a decent size (default 500.000 elements).
+ *
+ * @return an EHCache Cache instance containing the node id -> node mappings
+ */
+ @Override
+ public Map<Long, KiWiNode> getNodeCache() {
+ return nodeCache.asMap();
+ }
+
+ /**
+ * Return the triple id -> triple cache from the cache manager. This cache is used for speeding up the
+ * construction of query results.
+ *
+ * @return
+ */
+ @Override
+ public Map<Long, KiWiTriple> getTripleCache() {
+ return tripleCache.asMap();
+ }
+
+ /**
+ * Return the uri -> KiWiUriResource cache from the cache manager. This cache is used when constructing new
+ * KiWiUriResources to avoid a database lookup.
+ *
+ * @return
+ */
+ @Override
+ public Map<String, KiWiUriResource> getUriCache() {
+ return uriCache.asMap();
+ }
+
+ /**
+ * Return the anonId -> KiWiAnonResource cache from the cache manager. This cache is used when constructing new
+ * KiWiAnonResources to avoid a database lookup.
+ *
+ * @return
+ */
+ @Override
+ public Map<String, KiWiAnonResource> getBNodeCache() {
+ return bnodeCache.asMap();
+ }
+
+ /**
+ * Return the literal cache key -> KiWiLiteral cache from the cache manager. This cache is used when constructing new
+ * KiWiLiterals to avoid a database lookup.
+ *
+ * @return
+ * @see org.apache.marmotta.commons.sesame.model.LiteralCommons#createCacheKey(String, java.util.Locale, String)
+ */
+ @Override
+ public Map<String, KiWiLiteral> getLiteralCache() {
+ return literalCache.asMap();
+ }
+
+ /**
+ * Return the URI -> namespace cache from the cache manager. Used for looking up namespaces
+ *
+ * @return
+ */
+ @Override
+ public Map<String, KiWiNamespace> getNamespaceUriCache() {
+ return namespaceUriCache.asMap();
+ }
+
+ /**
+ * Return the prefix -> namespace cache from the cache manager. Used for looking up namespaces
+ *
+ * @return
+ */
+ @Override
+ public Map<String, KiWiNamespace> getNamespacePrefixCache() {
+ return namespacePrefixCache.asMap();
+ }
+
+ /**
+ * Create and return the cache used by the CacheTripleRegistry. This is an unlimited synchronous replicated
+ * cache and should be used with care.
+ *
+ * @return
+ */
+ @Override
+ public Map<Long, Long> getRegistryCache() {
+ return registryCache;
+ }
+
+ /**
+ * Get the cache with the given name from the cache manager. Can be used to request additional
+ * caches from the cache manager that are not covered by explicit methods.
+ *
+ * @param name
+ * @return
+ */
+ @Override
+ public Map getCacheByName(String name) {
+ synchronized (dynamicCaches) {
+ if(!dynamicCaches.containsKey(name)) {
+ dynamicCaches.put(name, CacheBuilder.newBuilder().expireAfterAccess(30, TimeUnit.MINUTES).maximumSize(100000).build());
+ }
+ return dynamicCaches.get(name).asMap();
+ }
+ }
+
+ /**
+ * Clear all caches managed by this cache manager.
+ */
+ @Override
+ public void clear() {
+ for(Cache c : dynamicCaches.values()) {
+ c.invalidateAll();
+ }
+
+ for(Cache c : new Cache[] { nodeCache, uriCache, bnodeCache, literalCache, tripleCache, namespacePrefixCache, namespaceUriCache}) {
+ c.invalidateAll();
+ }
+
+ registryCache.clear();
+ }
+
+ /**
+ * Shutdown this cache manager instance. Will shutdown the underlying EHCache cache manager.
+ */
+ @Override
+ public void shutdown() {
+ dynamicCaches.clear();
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/GuavaCacheManagerFactory.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/GuavaCacheManagerFactory.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/GuavaCacheManagerFactory.java
new file mode 100644
index 0000000..70dfc86
--- /dev/null
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/GuavaCacheManagerFactory.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.caching;
+
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+
+/**
+ * Create simple Guava-based in-memory caches.
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class GuavaCacheManagerFactory implements CacheManagerFactory {
+
+ public GuavaCacheManagerFactory() {
+ }
+
+ /**
+ * Create a new cache manager instance using the KiWiConfiguration passed as argument.
+ *
+ * @param configuration KiWi configuration used by the underlying triple store
+ * @return a new cache manager instance for this triple store
+ */
+ @Override
+ public CacheManager createCacheManager(KiWiConfiguration configuration) {
+ return new GuavaCacheManager(configuration);
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/IntLiteralExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/IntLiteralExternalizer.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/IntLiteralExternalizer.java
deleted file mode 100644
index 8001f87..0000000
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/IntLiteralExternalizer.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.kiwi.caching;
-
-import org.apache.marmotta.kiwi.model.rdf.KiWiIntLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
-import org.infinispan.commons.marshall.AdvancedExternalizer;
-import org.infinispan.commons.util.Util;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Date;
-import java.util.Set;
-
-/**
- * Add file description here!
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class IntLiteralExternalizer implements AdvancedExternalizer<KiWiIntLiteral> {
-
- @Override
- public Set<Class<? extends KiWiIntLiteral>> getTypeClasses() {
- return Util.<Class<? extends KiWiIntLiteral>>asSet(KiWiIntLiteral.class);
- }
-
- @Override
- public Integer getId() {
- return ExternalizerIds.INT_LITERAL;
- }
-
- @Override
- public void writeObject(ObjectOutput output, KiWiIntLiteral object) throws IOException {
- output.writeLong(object.getId());
- output.writeLong(object.getIntContent());
- output.writeObject(object.getDatatype());
-
- output.writeLong(object.getCreated().getTime());
-
- }
-
- @Override
- public KiWiIntLiteral readObject(ObjectInput input) throws IOException, ClassNotFoundException {
- long id = input.readLong();
- long content = input.readLong();
-
- KiWiUriResource dtype = (KiWiUriResource) input.readObject();
-
- Date created = new Date(input.readLong());
-
- KiWiIntLiteral r = new KiWiIntLiteral(content, dtype, created);
- r.setId(id);
-
- return r;
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/KiWiCacheManager.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/KiWiCacheManager.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/KiWiCacheManager.java
deleted file mode 100644
index 9760a66..0000000
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/KiWiCacheManager.java
+++ /dev/null
@@ -1,528 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.marmotta.kiwi.caching;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.marmotta.kiwi.config.KiWiConfiguration;
-import org.infinispan.Cache;
-import org.infinispan.commons.CacheException;
-import org.infinispan.commons.marshall.AdvancedExternalizer;
-import org.infinispan.configuration.cache.CacheMode;
-import org.infinispan.configuration.cache.Configuration;
-import org.infinispan.configuration.cache.ConfigurationBuilder;
-import org.infinispan.configuration.global.GlobalConfiguration;
-import org.infinispan.configuration.global.GlobalConfigurationBuilder;
-import org.infinispan.context.Flag;
-import org.infinispan.distribution.ch.SyncConsistentHashFactory;
-import org.infinispan.eviction.EvictionStrategy;
-import org.infinispan.lifecycle.ComponentStatus;
-import org.infinispan.manager.DefaultCacheManager;
-import org.infinispan.manager.EmbeddedCacheManager;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.util.Iterator;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
-
-import static org.apache.marmotta.kiwi.config.CacheMode.DISTRIBUTED;
-import static org.apache.marmotta.kiwi.config.CacheMode.REPLICATED;
-
-/**
- * A class for managing the different caches that are used by the triple store.
- * <p/>
- * Author: Sebastian Schaffert
- */
-public class KiWiCacheManager {
-
- private static Logger log = LoggerFactory.getLogger(KiWiCacheManager.class);
-
- public static final String NODE_CACHE = "node-cache";
- public static final String TRIPLE_CACHE = "triple-cache";
- public static final String URI_CACHE = "uri-cache";
- public static final String BNODE_CACHE = "bnode-cache";
- public static final String LITERAL_CACHE = "literal-cache";
- public static final String NAMESPACE_URI_CACHE = "namespace-uri-cache";
- public static final String NAMESPACE_PREFIX_CACHE = "namespace-prefix-cache";
- public static final String LOADER_CACHE = "loader-cache";
- public static final String REGISTRY_CACHE = "registry-cache";
-
- private EmbeddedCacheManager cacheManager;
-
- private GlobalConfiguration globalConfiguration;
-
- // default configuration: distributed cache, 100000 entries, 300 seconds expiration, 60 seconds idle
- private Configuration defaultConfiguration;
-
- private boolean clustered, embedded;
-
- private KiWiConfiguration kiWiConfiguration;
-
-
- private Cache nodeCache, tripleCache, uriCache, literalCache, bnodeCache, nsPrefixCache, nsUriCache, loaderCache, registryCache;
-
-
- /**
- * Create a new cache manager with its own automatically created Infinispan instance.
- *
- * @param config
- */
- public KiWiCacheManager(KiWiConfiguration config, AdvancedExternalizer...externalizers) {
-
- this.clustered = config.isClustered();
- this.kiWiConfiguration = config;
-
- if(clustered && (config.getCacheMode() == DISTRIBUTED || config.getCacheMode() == REPLICATED)) {
- try {
- String jgroupsXml = IOUtils.toString(KiWiCacheManager.class.getResourceAsStream("/jgroups-kiwi.xml"));
-
- jgroupsXml = jgroupsXml.replaceAll("mcast_addr=\"[0-9.]+\"", String.format("mcast_addr=\"%s\"", config.getClusterAddress()));
- jgroupsXml = jgroupsXml.replaceAll("mcast_port=\"[0-9]+\"", String.format("mcast_port=\"%d\"", config.getClusterPort()));
-
-
- globalConfiguration = new GlobalConfigurationBuilder()
- .classLoader(KiWiCacheManager.class.getClassLoader())
- .transport()
- .defaultTransport()
- .clusterName(config.getClusterName())
- .machineId("instance-" + config.getDatacenterId())
- .addProperty("configurationXml", jgroupsXml)
- .globalJmxStatistics()
- .jmxDomain("org.apache.marmotta.kiwi")
- .allowDuplicateDomains(true)
- .serialization()
- .addAdvancedExternalizer(externalizers)
- .build();
- } catch (IOException ex) {
- log.warn("error loading JGroups configuration from archive: {}", ex.getMessage());
- log.warn("some configuration options will not be available");
-
- globalConfiguration = new GlobalConfigurationBuilder()
- .classLoader(KiWiCacheManager.class.getClassLoader())
- .transport()
- .defaultTransport()
- .clusterName(config.getClusterName())
- .machineId("instance-" + config.getDatacenterId())
- .addProperty("configurationFile", "jgroups-kiwi.xml")
- .globalJmxStatistics()
- .jmxDomain("org.apache.marmotta.kiwi")
- .allowDuplicateDomains(true)
- .serialization()
- .addAdvancedExternalizer(externalizers)
- .build();
-
- }
-
- if(config.getCacheMode() == DISTRIBUTED) {
- defaultConfiguration = new ConfigurationBuilder()
- .clustering()
- .cacheMode(CacheMode.DIST_ASYNC)
- .async()
- .asyncMarshalling()
- .l1()
- .lifespan(5, TimeUnit.MINUTES)
- .hash()
- .numOwners(2)
- .numSegments(40)
- .consistentHashFactory(new SyncConsistentHashFactory())
- .stateTransfer()
- .fetchInMemoryState(false)
- .eviction()
- .strategy(EvictionStrategy.LIRS)
- .maxEntries(100000)
- .expiration()
- .lifespan(30, TimeUnit.MINUTES)
- .maxIdle(10, TimeUnit.MINUTES)
- .build();
- } else {
- defaultConfiguration = new ConfigurationBuilder()
- .clustering()
- .cacheMode(CacheMode.REPL_ASYNC)
- .async()
- .asyncMarshalling()
- .stateTransfer()
- .fetchInMemoryState(false)
- .eviction()
- .strategy(EvictionStrategy.LIRS)
- .maxEntries(100000)
- .expiration()
- .lifespan(30, TimeUnit.MINUTES)
- .maxIdle(10, TimeUnit.MINUTES)
- .build();
- }
- } else {
- globalConfiguration = new GlobalConfigurationBuilder()
- .classLoader(KiWiCacheManager.class.getClassLoader())
- .globalJmxStatistics()
- .jmxDomain("org.apache.marmotta.kiwi")
- .allowDuplicateDomains(true)
- .build();
-
- defaultConfiguration = new ConfigurationBuilder()
- .clustering()
- .cacheMode(CacheMode.LOCAL)
- .eviction()
- .strategy(EvictionStrategy.LIRS)
- .maxEntries(100000)
- .expiration()
- .lifespan(5, TimeUnit.MINUTES)
- .maxIdle(1, TimeUnit.MINUTES)
- .build();
-
- }
-
-
- cacheManager = new DefaultCacheManager(globalConfiguration, defaultConfiguration, true);
-
- log.info("initialised cache manager ({})", globalConfiguration.isClustered() ? "cluster name: "+globalConfiguration.transport().clusterName() : "single host");
-
- this.embedded = true;
- }
-
- /**
- * Create a cache manager from an existing Infinispan cache manager.
- *
- * @param cacheManager
- * @param kiWiConfiguration
- */
- public KiWiCacheManager(EmbeddedCacheManager cacheManager, KiWiConfiguration kiWiConfiguration, AdvancedExternalizer...externalizers) {
- this.cacheManager = cacheManager;
- this.globalConfiguration = cacheManager.getCacheManagerConfiguration();
- this.defaultConfiguration = cacheManager.getDefaultCacheConfiguration();
- this.kiWiConfiguration = kiWiConfiguration;
-
- this.clustered = kiWiConfiguration.isClustered();
-
- for(AdvancedExternalizer e : externalizers) {
- this.globalConfiguration.serialization().advancedExternalizers().put(e.getId(), e);
- }
-
- log.info("initialised cache manager ({})", globalConfiguration.isClustered() ? "cluster name: "+globalConfiguration.transport().clusterName() : "single host");
-
- this.embedded = false;
- }
-
- /**
- * Return the node id -> node cache from the cache manager. This cache is heavily used to lookup
- * nodes when querying or loading triples and should therefore have a decent size (default 500.000 elements).
- *
- * @return an EHCache Cache instance containing the node id -> node mappings
- */
- public Cache getNodeCache() {
- if(nodeCache == null) {
- Configuration nodeConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
- .eviction()
- .maxEntries(1000000)
- .expiration()
- .lifespan(60, TimeUnit.MINUTES)
- .maxIdle(30, TimeUnit.MINUTES)
- .build();
- cacheManager.defineConfiguration(NODE_CACHE, nodeConfiguration);
-
- nodeCache = cacheManager.getCache(NODE_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
- }
-
- return nodeCache;
- }
-
- /**
- * Return the triple id -> triple cache from the cache manager. This cache is used for speeding up the
- * construction of query results.
- *
- * @return
- */
- public Cache getTripleCache() {
- if(tripleCache == null) {
- Configuration tripleConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
- .clustering()
- .cacheMode(CacheMode.LOCAL)
- .eviction()
- .maxEntries(kiWiConfiguration.getTripleCacheSize())
- .expiration()
- .lifespan(60, TimeUnit.MINUTES)
- .maxIdle(30, TimeUnit.MINUTES)
- .build();
- cacheManager.defineConfiguration(TRIPLE_CACHE, tripleConfiguration);
-
- tripleCache = cacheManager.getCache(TRIPLE_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
- }
- return tripleCache;
- }
-
-
- /**
- * Return the uri -> KiWiUriResource cache from the cache manager. This cache is used when constructing new
- * KiWiUriResources to avoid a database lookup.
- *
- * @return
- */
- public Cache getUriCache() {
- if(uriCache == null) {
- Configuration uriConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
- .eviction()
- .maxEntries(kiWiConfiguration.getUriCacheSize())
- .build();
- cacheManager.defineConfiguration(URI_CACHE, uriConfiguration);
-
- uriCache = cacheManager.getCache(URI_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
- }
- return uriCache;
- }
-
-
- /**
- * Return the anonId -> KiWiAnonResource cache from the cache manager. This cache is used when constructing new
- * KiWiAnonResources to avoid a database lookup.
- *
- * @return
- */
- public Cache getBNodeCache() {
- if(bnodeCache == null) {
- Configuration bnodeConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
- .eviction()
- .maxEntries(kiWiConfiguration.getBNodeCacheSize())
- .build();
- cacheManager.defineConfiguration(BNODE_CACHE, bnodeConfiguration);
-
- bnodeCache = cacheManager.getCache(BNODE_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
- }
- return bnodeCache;
- }
-
- /**
- * Return the literal cache key -> KiWiLiteral cache from the cache manager. This cache is used when constructing new
- * KiWiLiterals to avoid a database lookup.
- *
- * @see org.apache.marmotta.commons.sesame.model.LiteralCommons#createCacheKey(String, java.util.Locale, String)
- * @return
- */
- public Cache getLiteralCache() {
- if(literalCache == null) {
- Configuration literalConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
- .eviction()
- .maxEntries(kiWiConfiguration.getLiteralCacheSize())
- .build();
- cacheManager.defineConfiguration(LITERAL_CACHE, literalConfiguration);
-
- literalCache = cacheManager.getCache(LITERAL_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
- }
- return literalCache;
- }
-
-
- /**
- * Return the URI -> namespace cache from the cache manager. Used for looking up namespaces
- * @return
- */
- public Cache getNamespaceUriCache() {
- if(nsUriCache == null) {
- if(clustered) {
- Configuration nsuriConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
- .clustering()
- .cacheMode(CacheMode.REPL_ASYNC)
- .eviction()
- .maxEntries(kiWiConfiguration.getNamespaceCacheSize())
- .expiration()
- .lifespan(1, TimeUnit.DAYS)
- .build();
- cacheManager.defineConfiguration(NAMESPACE_URI_CACHE, nsuriConfiguration);
- } else {
- Configuration nsuriConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
- .eviction()
- .maxEntries(kiWiConfiguration.getNamespaceCacheSize())
- .expiration()
- .lifespan(1, TimeUnit.HOURS)
- .build();
- cacheManager.defineConfiguration(NAMESPACE_URI_CACHE, nsuriConfiguration);
- }
-
- nsUriCache = cacheManager.getCache(NAMESPACE_URI_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
- }
- return nsUriCache;
- }
-
- /**
- * Return the prefix -> namespace cache from the cache manager. Used for looking up namespaces
- * @return
- */
- public Cache getNamespacePrefixCache() {
- if(nsPrefixCache == null) {
- if(clustered) {
- Configuration nsprefixConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
- .clustering()
- .cacheMode(CacheMode.REPL_ASYNC)
- .eviction()
- .maxEntries(kiWiConfiguration.getNamespaceCacheSize())
- .expiration()
- .lifespan(1, TimeUnit.DAYS)
- .build();
- cacheManager.defineConfiguration(NAMESPACE_PREFIX_CACHE, nsprefixConfiguration);
-
- } else {
- Configuration nsprefixConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
- .eviction()
- .maxEntries(kiWiConfiguration.getNamespaceCacheSize())
- .expiration()
- .lifespan(1, TimeUnit.HOURS)
- .build();
- cacheManager.defineConfiguration(NAMESPACE_PREFIX_CACHE, nsprefixConfiguration);
-
- }
- nsPrefixCache = cacheManager.getCache(NAMESPACE_PREFIX_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
- }
- return nsPrefixCache;
- }
-
-
- /**
- * Return the cache used by the KiWiLoader. Used for mapping from Sesame nodes to KiWi nodes.
- * @return
- */
- public Cache getLoaderCache() {
- if(loaderCache == null) {
- Configuration loaderConfiguration = new ConfigurationBuilder().read(defaultConfiguration)
- .eviction()
- .maxEntries(100000)
- .expiration()
- .lifespan(10, TimeUnit.MINUTES)
- .maxIdle(30, TimeUnit.SECONDS)
- .build();
- cacheManager.defineConfiguration(LOADER_CACHE, loaderConfiguration);
-
- loaderCache = cacheManager.getCache(LOADER_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
- }
- return loaderCache;
- }
-
-
- /**
- * Create and return the cache used by the CacheTripleRegistry. This is an unlimited synchronous replicated
- * cache and should be used with care.
- * @return
- */
- public Cache getRegistryCache() {
- if(registryCache == null) {
- if(clustered) {
- Configuration registryConfiguration = new ConfigurationBuilder()
- .clustering()
- .cacheMode(CacheMode.REPL_SYNC)
- .sync()
- .replTimeout(15, TimeUnit.SECONDS)
- .eviction()
- .strategy(EvictionStrategy.NONE)
- .build();
- cacheManager.defineConfiguration(REGISTRY_CACHE, registryConfiguration);
- } else {
- Configuration registryConfiguration = new ConfigurationBuilder()
- .clustering()
- .cacheMode(CacheMode.LOCAL)
- .eviction()
- .strategy(EvictionStrategy.NONE)
- .build();
- cacheManager.defineConfiguration(REGISTRY_CACHE, registryConfiguration);
- }
-
- registryCache = cacheManager.getCache(REGISTRY_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
- }
- return registryCache;
- }
-
- /**
- * Get the cache with the given name from the cache manager. Can be used to request additional
- * caches from the cache manager that are not covered by explicit methods.
- *
- * @param name
- * @return
- */
- public synchronized Cache getCacheByName(String name) {
- if(!cacheManager.cacheExists(name)) {
- cacheManager.defineConfiguration(name, new ConfigurationBuilder().read(defaultConfiguration).build());
- }
- return cacheManager.getCache(name).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
-
- }
-
- /**
- * Return the Infinispan cache manager used by the caching infrastructure.
- *
- * @return
- */
- public EmbeddedCacheManager getCacheManager() {
- return cacheManager;
- }
-
- /**
- * Return the global cache manager configuration used by the caching infrastructure.
- * @return
- */
- public GlobalConfiguration getGlobalConfiguration() {
- return globalConfiguration;
- }
-
- /**
- * Return the default cache configuration used by the caching infrastructure.
- * @return
- */
- public Configuration getDefaultConfiguration() {
- return defaultConfiguration;
- }
-
- /**
- * Clear all caches managed by this cache manager.
- */
- public void clear() {
- Set<String> set = cacheManager.getCacheNames();
- Iterator<String> iterator = set.iterator();
- while(iterator.hasNext()){
- String cacheName = iterator.next();
- Cache<String,Object> cache = cacheManager.getCache(cacheName);
- cache.clear();
- }
-
- nodeCache = null;
- tripleCache = null;
- uriCache = null;
- literalCache = null;
- bnodeCache = null;
- nsPrefixCache = null;
- nsUriCache = null;
- loaderCache = null;
- registryCache = null;
- }
-
- /**
- * Shutdown this cache manager instance. Will shutdown the underlying EHCache cache manager.
- */
- public void shutdown() {
- try {
- if(embedded && cacheManager.getStatus() == ComponentStatus.RUNNING) {
- log.warn("shutting down cache manager ...");
-// if(cacheManager.getTransport() != null) {
-// log.info("... shutting down transport ...");
-// cacheManager.getTransport().stop();
-// }
- log.info("... shutting down main component ...");
- cacheManager.stop();
- log.info("... done!");
- }
- } catch (CacheException ex) {
- log.warn("error shutting down cache: {}", ex.getMessage());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/StringLiteralExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/StringLiteralExternalizer.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/StringLiteralExternalizer.java
deleted file mode 100644
index 0d0559b..0000000
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/StringLiteralExternalizer.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.kiwi.caching;
-
-import org.apache.marmotta.kiwi.model.rdf.KiWiStringLiteral;
-import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
-import org.infinispan.commons.marshall.AdvancedExternalizer;
-import org.infinispan.commons.util.Util;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Date;
-import java.util.Locale;
-import java.util.Set;
-
-/**
- * Add file description here!
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class StringLiteralExternalizer implements AdvancedExternalizer<KiWiStringLiteral> {
-
- @Override
- public Set<Class<? extends KiWiStringLiteral>> getTypeClasses() {
- return Util.<Class<? extends KiWiStringLiteral>>asSet(KiWiStringLiteral.class);
- }
-
- @Override
- public Integer getId() {
- return ExternalizerIds.STRING_LITERAL;
- }
-
- @Override
- public void writeObject(ObjectOutput output, KiWiStringLiteral object) throws IOException {
- output.writeLong(object.getId());
- output.writeInt(object.getContent().length());
- output.writeChars(object.getContent());
- if(object.getLanguage() != null) {
- output.writeInt(object.getLanguage().length());
- output.writeChars(object.getLanguage());
- } else {
- output.writeInt(0);
- }
-
- output.writeObject(object.getDatatype());
-
- output.writeLong(object.getCreated().getTime());
-
- }
-
- @Override
- public KiWiStringLiteral readObject(ObjectInput input) throws IOException, ClassNotFoundException {
- long id = input.readLong();
- int clen = input.readInt();
- char[] content = new char[clen];
- for(int i=0; i<clen; i++) {
- content[i]=input.readChar();
- }
-
- int llen = input.readInt();
- String lang = null;
- if(llen > 0) {
- char[] lb = new char[llen];
- for(int i=0; i<llen; i++) {
- lb[i] = input.readChar();
- }
- lang = new String(lb);
- }
-
- KiWiUriResource dtype = (KiWiUriResource) input.readObject();
-
- Date created = new Date(input.readLong());
-
- KiWiStringLiteral r = new KiWiStringLiteral(new String(content), lang != null ? Locale.forLanguageTag(lang) : null, dtype, created);
- r.setId(id);
-
- return r;
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/TripleExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/TripleExternalizer.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/TripleExternalizer.java
deleted file mode 100644
index 22bfb6c..0000000
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/TripleExternalizer.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.kiwi.caching;
-
-import org.apache.marmotta.kiwi.model.rdf.KiWiNode;
-import org.apache.marmotta.kiwi.model.rdf.KiWiResource;
-import org.apache.marmotta.kiwi.model.rdf.KiWiTriple;
-import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
-import org.apache.marmotta.kiwi.persistence.KiWiConnection;
-import org.apache.marmotta.kiwi.persistence.KiWiPersistence;
-import org.infinispan.commons.marshall.AdvancedExternalizer;
-import org.infinispan.commons.util.Util;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.sql.SQLException;
-import java.util.Date;
-import java.util.Set;
-
-/**
- * An externalizer for Infinispan allowing to more efficiently transport triples by only serializing the node
- * IDs instead of the whole nodes.
- */
-public class TripleExternalizer implements AdvancedExternalizer<KiWiTriple> {
-
- private static Logger log = LoggerFactory.getLogger(TripleExternalizer.class);
-
- private KiWiPersistence persistence;
-
- public TripleExternalizer(KiWiPersistence persistence) {
- this.persistence = persistence;
- }
-
- @Override
- public Set<Class<? extends KiWiTriple>> getTypeClasses() {
- return Util.<Class<? extends KiWiTriple>>asSet(KiWiTriple.class);
- }
-
- @Override
- public Integer getId() {
- return 13;
- }
-
- @Override
- public void writeObject(ObjectOutput output, KiWiTriple object) throws IOException {
- output.writeLong(object.getId());
- output.writeLong(object.getSubject().getId());
- output.writeLong(object.getPredicate().getId());
- output.writeLong(object.getObject().getId());
- output.writeLong(object.getContext() != null ? object.getContext().getId() : -1L);
- output.writeLong(object.getCreator() != null ? object.getCreator().getId() : -1L);
- output.writeBoolean(object.isDeleted());
- output.writeBoolean(object.isInferred());
- output.writeBoolean(object.isNewTriple());
- output.writeLong(object.getCreated().getTime());
- if(object.getDeletedAt() != null) {
- output.writeLong(object.getDeletedAt().getTime());
- } else {
- output.writeLong(0);
- }
- }
-
- @Override
- public KiWiTriple readObject(ObjectInput input) throws IOException, ClassNotFoundException {
- try {
- KiWiConnection con = persistence.getConnection();
- try {
- KiWiTriple result = new KiWiTriple();
- result.setId(input.readLong());
-
- long[] nodeIds = new long[5];
- for(int i=0; i<5; i++) {
- nodeIds[0] = input.readLong();
- }
- KiWiNode[] nodes = con.loadNodesByIds(nodeIds);
-
- result.setSubject((KiWiResource) nodes[0]);
- result.setPredicate((KiWiUriResource) nodes[1]);
- result.setObject(nodes[2]);
-
- if(nodes[3] != null) {
- result.setContext((KiWiResource) nodes[3]);
- }
- if(nodes[4] != null) {
- result.setCreator((KiWiResource) nodes[4]);
- }
-
- result.setDeleted(input.readBoolean());
- result.setInferred(input.readBoolean());
- result.setNewTriple(input.readBoolean());
-
- result.setCreated(new Date(input.readLong()));
-
- long deletedAt = input.readLong();
- if(deletedAt > 0) {
- result.setDeletedAt(new Date(deletedAt));
- }
-
-
- return result;
- } finally {
- con.commit();
- con.close();
- }
- } catch (SQLException ex) {
- throw new IOException(ex);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/UriExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/UriExternalizer.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/UriExternalizer.java
deleted file mode 100644
index 3139db1..0000000
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/caching/UriExternalizer.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.kiwi.caching;
-
-import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
-import org.infinispan.commons.marshall.AdvancedExternalizer;
-import org.infinispan.commons.util.Util;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Date;
-import java.util.Set;
-
-/**
- * Add file description here!
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class UriExternalizer implements AdvancedExternalizer<KiWiUriResource> {
-
- @Override
- public Set<Class<? extends KiWiUriResource>> getTypeClasses() {
- return Util.<Class<? extends KiWiUriResource>>asSet(KiWiUriResource.class);
- }
-
- @Override
- public Integer getId() {
- return ExternalizerIds.URI;
- }
-
- @Override
- public void writeObject(ObjectOutput output, KiWiUriResource object) throws IOException {
- output.writeLong(object.getId());
- output.writeInt(object.stringValue().length());
- output.writeChars(object.stringValue());
- output.writeLong(object.getCreated().getTime());
- }
-
- @Override
- public KiWiUriResource readObject(ObjectInput input) throws IOException, ClassNotFoundException {
- long id = input.readLong();
- int len = input.readInt();
-
- char[] uri = new char[len];
- for(int i=0; i<len; i++) {
- uri[i] = input.readChar();
- }
-
- Date created = new Date(input.readLong());
-
- KiWiUriResource r = new KiWiUriResource(new String(uri),created);
- r.setId(id);
-
- return r;
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java
index 3658d25..a445112 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java
@@ -91,6 +91,14 @@ public class KiWiConfiguration {
private String[] fulltextLanguages;
+ /**
+ * Fully qualified class name of the cache manager factory to use. Falls back to the Guava
+ * cache manager if not found
+ */
+ private String cacheManagerFactory = "org.apache.marmotta.kiwi.caching.GuavaCacheManagerFactory";
+
+ private int nodeCacheSize = 1000000;
+
private int uriCacheSize = 500000;
private int bNodeCacheSize = 10000;
@@ -289,6 +297,37 @@ public class KiWiConfiguration {
/**
+ * Fully qualified class name of the cache manager factory to use. Falls back to the Guava
+ * cache manager if not found
+ */
+ public String getCacheManagerFactory() {
+ return cacheManagerFactory;
+ }
+
+ /**
+ * Fully qualified class name of the cache manager factory to use. Falls back to the Guava
+ * cache manager if not found
+ */
+ public void setCacheManagerFactory(String cacheManagerFactory) {
+ this.cacheManagerFactory = cacheManagerFactory;
+ }
+
+ /**
+ * The maximum size of the node ID cache used by the KiWiValueFactory (default: 1000000)
+ * @return
+ */
+ public int getNodeCacheSize() {
+ return nodeCacheSize;
+ }
+
+ /**
+ * The maximum size of the node ID cache used by the KiWiValueFactory (default: 1000000)
+ */
+ public void setNodeCacheSize(int nodeCacheSize) {
+ this.nodeCacheSize = nodeCacheSize;
+ }
+
+ /**
* The maximum size of the literal cache used by the KiWiValueFactory (default: 100000)
* @return
*/
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiConnection.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiConnection.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiConnection.java
index 5cd363e..28edf7f 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiConnection.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiConnection.java
@@ -18,8 +18,6 @@
package org.apache.marmotta.kiwi.persistence;
import com.google.common.base.Preconditions;
-import com.google.common.hash.Hasher;
-import com.google.common.hash.Hashing;
import com.google.common.primitives.Longs;
import info.aduna.iteration.*;
import org.apache.commons.lang3.math.NumberUtils;
@@ -27,13 +25,12 @@ import org.apache.marmotta.commons.sesame.model.LiteralCommons;
import org.apache.marmotta.commons.sesame.model.Namespaces;
import org.apache.marmotta.commons.sesame.tripletable.TripleTable;
import org.apache.marmotta.commons.util.DateUtils;
-import org.apache.marmotta.kiwi.caching.KiWiCacheManager;
+import org.apache.marmotta.kiwi.caching.CacheManager;
import org.apache.marmotta.kiwi.config.KiWiConfiguration;
import org.apache.marmotta.kiwi.exception.ResultInterruptedException;
import org.apache.marmotta.kiwi.model.rdf.*;
import org.apache.marmotta.kiwi.persistence.util.ResultSetIteration;
import org.apache.marmotta.kiwi.persistence.util.ResultTransformerFunction;
-import org.infinispan.Cache;
import org.openrdf.model.Literal;
import org.openrdf.model.Resource;
import org.openrdf.model.Statement;
@@ -65,47 +62,47 @@ public class KiWiConnection implements AutoCloseable {
protected KiWiPersistence persistence;
- protected KiWiCacheManager cacheManager;
+ protected CacheManager cacheManager;
protected TripleTable<KiWiTriple> tripleBatch;
/**
* Cache nodes by database ID
*/
- private Cache<Long,KiWiNode> nodeCache;
+ private Map<Long,KiWiNode> nodeCache;
/**
* Cache triples by database ID
*/
- private Cache<Long,KiWiTriple> tripleCache;
+ private Map<Long,KiWiTriple> tripleCache;
/**
* Cache URI resources by uri
*/
- private Cache<Long,KiWiUriResource> uriCache;
+ private Map<String,KiWiUriResource> uriCache;
/**
* Cache BNodes by BNode ID
*/
- private Cache<Long,KiWiAnonResource> bnodeCache;
+ private Map<String,KiWiAnonResource> bnodeCache;
/**
* Cache literals by literal cache key (LiteralCommons#createCacheKey(String,Locale,URI))
*/
- private Cache<String,KiWiLiteral> literalCache;
+ private Map<String,KiWiLiteral> literalCache;
/**
* Look up namespaces by URI
*/
- private Cache<String,KiWiNamespace> namespaceUriCache;
+ private Map<String,KiWiNamespace> namespaceUriCache;
/**
* Look up namespaces by prefix
*/
- private Cache<String,KiWiNamespace> namespacePrefixCache;
+ private Map<String,KiWiNamespace> namespacePrefixCache;
/**
* Cache instances of locales for language tags
@@ -141,7 +138,7 @@ public class KiWiConnection implements AutoCloseable {
private int QUERY_BATCH_SIZE = 1024;
- public KiWiConnection(KiWiPersistence persistence, KiWiDialect dialect, KiWiCacheManager cacheManager) throws SQLException {
+ public KiWiConnection(KiWiPersistence persistence, KiWiDialect dialect, CacheManager cacheManager) throws SQLException {
this.cacheManager = cacheManager;
this.dialect = dialect;
this.persistence = persistence;
@@ -211,7 +208,7 @@ public class KiWiConnection implements AutoCloseable {
* Return the cache manager used by this connection
* @return
*/
- public KiWiCacheManager getCacheManager() {
+ public CacheManager getCacheManager() {
return cacheManager;
}
@@ -571,7 +568,7 @@ public class KiWiConnection implements AutoCloseable {
Preconditions.checkNotNull(uri);
// look in cache
- KiWiUriResource element = uriCache.get(createCacheKey(uri));
+ KiWiUriResource element = uriCache.get(uri);
if(element != null) {
return element;
}
@@ -617,7 +614,7 @@ public class KiWiConnection implements AutoCloseable {
*/
public KiWiAnonResource loadAnonResource(String id) throws SQLException {
// look in cache
- KiWiAnonResource element = bnodeCache.get(createCacheKey(id));
+ KiWiAnonResource element = bnodeCache.get(id);
if(element != null) {
return element;
}
@@ -1272,7 +1269,6 @@ public class KiWiConnection implements AutoCloseable {
if (triple.getId() < 0) {
log.warn("attempting to remove non-persistent triple: {}", triple);
- removeCachedTriple(triple);
} else {
if (batchCommit) {
// need to remove from triple batch and from database
@@ -1302,8 +1298,8 @@ public class KiWiConnection implements AutoCloseable {
}
- removeCachedTriple(triple);
}
+ removeCachedTriple(triple);
}
return null;
@@ -2035,26 +2031,26 @@ public class KiWiConnection implements AutoCloseable {
private void cacheNode(KiWiNode node) {
if(node.getId() >= 0) {
- nodeCache.putForExternalRead(node.getId(), node);
+ nodeCache.put(node.getId(), node);
}
if(node instanceof KiWiUriResource) {
- uriCache.putForExternalRead(createCacheKey(node.stringValue()), (KiWiUriResource) node);
+ uriCache.put(node.stringValue(), (KiWiUriResource) node);
} else if(node instanceof KiWiAnonResource) {
- bnodeCache.putForExternalRead(createCacheKey(node.stringValue()), (KiWiAnonResource) node);
+ bnodeCache.put(node.stringValue(), (KiWiAnonResource) node);
} else if(node instanceof KiWiLiteral) {
- literalCache.putForExternalRead(LiteralCommons.createCacheKey((Literal) node), (KiWiLiteral) node);
+ literalCache.put(LiteralCommons.createCacheKey((Literal) node), (KiWiLiteral) node);
}
}
private void cacheTriple(KiWiTriple triple) {
if(triple.getId() >= 0) {
- tripleCache.putForExternalRead(triple.getId(), triple);
+ tripleCache.put(triple.getId(), triple);
}
}
private void removeCachedTriple(KiWiTriple triple) {
if(triple.getId() >= 0) {
- tripleCache.removeAsync(triple.getId());
+ tripleCache.remove(triple.getId());
}
}
@@ -2569,11 +2565,5 @@ public class KiWiConnection implements AutoCloseable {
}
- private static Long createCacheKey(String svalue) {
- Hasher hasher = Hashing.goodFastHash(64).newHasher();
- hasher.putString(svalue);
- return hasher.hash().asLong();
- }
-
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiPersistence.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiPersistence.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiPersistence.java
index a3cf60c..6d81065 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiPersistence.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiPersistence.java
@@ -17,7 +17,9 @@
*/
package org.apache.marmotta.kiwi.persistence;
-import org.apache.marmotta.kiwi.caching.*;
+import org.apache.marmotta.kiwi.caching.CacheManager;
+import org.apache.marmotta.kiwi.caching.CacheManagerFactory;
+import org.apache.marmotta.kiwi.caching.GuavaCacheManagerFactory;
import org.apache.marmotta.kiwi.config.KiWiConfiguration;
import org.apache.marmotta.kiwi.generator.IDGenerator;
import org.apache.marmotta.kiwi.generator.SnowflakeIDGenerator;
@@ -25,8 +27,6 @@ import org.apache.marmotta.kiwi.persistence.util.ScriptRunner;
import org.apache.marmotta.kiwi.sail.KiWiValueFactory;
import org.apache.tomcat.jdbc.pool.DataSource;
import org.apache.tomcat.jdbc.pool.PoolProperties;
-import org.infinispan.commons.marshall.AdvancedExternalizer;
-import org.infinispan.manager.EmbeddedCacheManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -55,7 +55,7 @@ public class KiWiPersistence {
private PoolProperties poolConfig;
- private KiWiCacheManager cacheManager;
+ private CacheManager cacheManager;
private KiWiGarbageCollector garbageCollector;
@@ -82,9 +82,6 @@ public class KiWiPersistence {
private boolean initialized = false;
- // in case the cache manager comes from outside, it is passed over here
- private EmbeddedCacheManager infinispan;
-
@Deprecated
public KiWiPersistence(String name, String jdbcUrl, String db_user, String db_password, KiWiDialect dialect) {
this(new KiWiConfiguration(name,jdbcUrl,db_user,db_password,dialect));
@@ -95,12 +92,6 @@ public class KiWiPersistence {
this.maintenance = false;
}
- public KiWiPersistence(KiWiConfiguration configuration, EmbeddedCacheManager infinispan) {
- this.configuration = configuration;
- this.maintenance = false;
- this.infinispan = infinispan;
- }
-
public void initialise() {
// init JDBC connection pool
@@ -132,27 +123,21 @@ public class KiWiPersistence {
return configuration.getDialect();
}
- public KiWiCacheManager getCacheManager() {
+ public CacheManager getCacheManager() {
return cacheManager;
}
private void initCachePool() {
- AdvancedExternalizer[] externalizers = new AdvancedExternalizer[] {
- new TripleExternalizer(this),
- new UriExternalizer(),
- new BNodeExternalizer(),
- new StringLiteralExternalizer(),
- new DateLiteralExternalizer(),
- new BooleanLiteralExternalizer(),
- new IntLiteralExternalizer(),
- new DoubleLiteralExternalizer()
- };
-
- if(infinispan != null) {
- cacheManager = new KiWiCacheManager(infinispan,configuration, externalizers);
- } else {
- cacheManager = new KiWiCacheManager(configuration, externalizers);
+
+ try {
+ Class factory = Class.forName(configuration.getCacheManagerFactory());
+ cacheManager = ((CacheManagerFactory)factory.newInstance()).createCacheManager(configuration);
+ } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
+ log.warn("cache manager factory {} not found on classpath (error: {}); falling back to Guava in-memory cache backend!", configuration.getCacheManagerFactory(), e.getMessage());
+
+ CacheManagerFactory factory = new GuavaCacheManagerFactory();
+ cacheManager = factory.createCacheManager(configuration);
}
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/registry/CacheTripleRegistry.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/registry/CacheTripleRegistry.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/registry/CacheTripleRegistry.java
index 8f81531..7e4d14d 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/registry/CacheTripleRegistry.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/registry/CacheTripleRegistry.java
@@ -18,8 +18,7 @@
package org.apache.marmotta.kiwi.persistence.registry;
import org.apache.marmotta.commons.sesame.tripletable.IntArray;
-import org.apache.marmotta.kiwi.caching.KiWiCacheManager;
-import org.infinispan.Cache;
+import org.apache.marmotta.kiwi.caching.CacheManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -38,13 +37,13 @@ public class CacheTripleRegistry implements KiWiTripleRegistry {
private static Logger log = LoggerFactory.getLogger(CacheTripleRegistry.class);
- private Cache<Long,Long> cache;
+ private Map<Long,Long> cache;
private Map<Long,List<Long>> transactions;
- public CacheTripleRegistry(KiWiCacheManager cacheManager) {
+ public CacheTripleRegistry(CacheManager cacheManager) {
cache = cacheManager.getRegistryCache();
transactions = new HashMap<>();
@@ -65,7 +64,7 @@ public class CacheTripleRegistry implements KiWiTripleRegistry {
transaction = new ArrayList<>();
transactions.put(transactionId, transaction);
}
- cache.putForExternalRead(key.longHashCode(),tripleId);
+ cache.put(key.longHashCode(), tripleId);
transaction.add(key.longHashCode());
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiStore.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiStore.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiStore.java
index ea5fb79..899b941 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiStore.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiStore.java
@@ -20,7 +20,6 @@ package org.apache.marmotta.kiwi.sail;
import org.apache.marmotta.kiwi.config.KiWiConfiguration;
import org.apache.marmotta.kiwi.persistence.KiWiDialect;
import org.apache.marmotta.kiwi.persistence.KiWiPersistence;
-import org.infinispan.manager.EmbeddedCacheManager;
import org.openrdf.model.ValueFactory;
import org.openrdf.sail.SailException;
import org.openrdf.sail.helpers.NotifyingSailBase;
@@ -98,10 +97,6 @@ public class KiWiStore extends NotifyingSailBase {
this(new KiWiPersistence(configuration), configuration.getDefaultContext(), configuration.getInferredContext());
}
- public KiWiStore(KiWiConfiguration configuration, EmbeddedCacheManager infinispan) {
- this(new KiWiPersistence(configuration, infinispan), configuration.getDefaultContext(), configuration.getInferredContext());
- }
-
/**
* Do store-specific operations to initialize the store. The default
* implementation of this method does nothing.
http://git-wip-us.apache.org/repos/asf/marmotta/blob/c6d0cc13/libraries/kiwi/kiwi-triplestore/src/main/resources/META-INF/services/org.apache.marmotta.kiwi.caching.CacheManagerFactory
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/resources/META-INF/services/org.apache.marmotta.kiwi.caching.CacheManagerFactory b/libraries/kiwi/kiwi-triplestore/src/main/resources/META-INF/services/org.apache.marmotta.kiwi.caching.CacheManagerFactory
new file mode 100644
index 0000000..5d45ff7
--- /dev/null
+++ b/libraries/kiwi/kiwi-triplestore/src/main/resources/META-INF/services/org.apache.marmotta.kiwi.caching.CacheManagerFactory
@@ -0,0 +1 @@
+org.apache.marmotta.kiwi.caching.GuavaCacheManagerFactory
\ No newline at end of file
[08/21] git commit: started implementing Hazelcast cache manager
Posted by ss...@apache.org.
started implementing Hazelcast cache manager
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/27a05239
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/27a05239
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/27a05239
Branch: refs/heads/MARMOTTA-450
Commit: 27a05239fbf44f3a44be1ea99cc3710dfdd39882
Parents: 4d26a1b
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Mon Mar 3 18:51:40 2014 +0100
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Mon Mar 3 18:51:40 2014 +0100
----------------------------------------------------------------------
.../caching/HazelcastCacheManager.java | 164 ++++++++++++++++++-
.../caching/HazelcastCacheManagerFactory.java | 20 ++-
2 files changed, 182 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/27a05239/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/caching/HazelcastCacheManager.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/caching/HazelcastCacheManager.java b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/caching/HazelcastCacheManager.java
index 83ba267..446fa4b 100644
--- a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/caching/HazelcastCacheManager.java
+++ b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/caching/HazelcastCacheManager.java
@@ -17,10 +17,172 @@
package org.apache.marmotta.kiwi.hazelcast.caching;
+import com.hazelcast.config.Config;
+import com.hazelcast.config.SerializerConfig;
+import org.apache.marmotta.kiwi.caching.CacheManager;
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+import org.apache.marmotta.kiwi.hazelcast.serializer.*;
+import org.apache.marmotta.kiwi.model.rdf.*;
+
+import java.util.Map;
+
/**
* Add file description here!
*
* @author Sebastian Schaffert (sschaffert@apache.org)
*/
-public class HazelcastCacheManager {
+public class HazelcastCacheManager implements CacheManager {
+
+ private KiWiConfiguration configuration;
+
+ private Config hcConfiguration;
+
+ public HazelcastCacheManager(KiWiConfiguration configuration) {
+ this.configuration = configuration;
+
+ hcConfiguration = new Config();
+
+ setupSerializers();
+ }
+
+ private void setupSerializers() {
+ SerializerConfig scBNode = new SerializerConfig().setImplementation(new BNodeSerializer()).setTypeClass(KiWiAnonResource.class);
+ hcConfiguration.getSerializationConfig().addSerializerConfig(scBNode);
+
+ SerializerConfig scBoolean = new SerializerConfig().setImplementation(new BooleanLiteralSerializer()).setTypeClass(KiWiBooleanLiteral.class);
+ hcConfiguration.getSerializationConfig().addSerializerConfig(scBoolean);
+
+ SerializerConfig scDate = new SerializerConfig().setImplementation(new DateLiteralSerializer()).setTypeClass(KiWiDateLiteral.class);
+ hcConfiguration.getSerializationConfig().addSerializerConfig(scDate);
+
+ SerializerConfig scDouble = new SerializerConfig().setImplementation(new DoubleLiteralSerializer()).setTypeClass(KiWiDoubleLiteral.class);
+ hcConfiguration.getSerializationConfig().addSerializerConfig(scDouble);
+
+ SerializerConfig scInt = new SerializerConfig().setImplementation(new IntLiteralSerializer()).setTypeClass(KiWiIntLiteral.class);
+ hcConfiguration.getSerializationConfig().addSerializerConfig(scInt);
+
+ SerializerConfig scString = new SerializerConfig().setImplementation(new StringLiteralSerializer()).setTypeClass(KiWiStringLiteral.class);
+ hcConfiguration.getSerializationConfig().addSerializerConfig(scString);
+
+ SerializerConfig scTriple = new SerializerConfig().setImplementation(new TripleSerializer()).setTypeClass(KiWiTriple.class);
+ hcConfiguration.getSerializationConfig().addSerializerConfig(scTriple);
+
+ SerializerConfig scUri = new SerializerConfig().setImplementation(new UriSerializer()).setTypeClass(KiWiUriResource.class);
+ hcConfiguration.getSerializationConfig().addSerializerConfig(scUri);
+ }
+
+ /**
+ * Return the node id -> node cache from the cache manager. This cache is heavily used to lookup
+ * nodes when querying or loading triples and should therefore have a decent size (default 500.000 elements).
+ *
+ * @return an EHCache Cache instance containing the node id -> node mappings
+ */
+ @Override
+ public Map<Long, KiWiNode> getNodeCache() {
+ return null;
+ }
+
+ /**
+ * Return the triple id -> triple cache from the cache manager. This cache is used for speeding up the
+ * construction of query results.
+ *
+ * @return
+ */
+ @Override
+ public Map<Long, KiWiTriple> getTripleCache() {
+ return null;
+ }
+
+ /**
+ * Return the uri -> KiWiUriResource cache from the cache manager. This cache is used when constructing new
+ * KiWiUriResources to avoid a database lookup.
+ *
+ * @return
+ */
+ @Override
+ public Map<String, KiWiUriResource> getUriCache() {
+ return null;
+ }
+
+ /**
+ * Return the anonId -> KiWiAnonResource cache from the cache manager. This cache is used when constructing new
+ * KiWiAnonResources to avoid a database lookup.
+ *
+ * @return
+ */
+ @Override
+ public Map<String, KiWiAnonResource> getBNodeCache() {
+ return null;
+ }
+
+ /**
+ * Return the literal cache key -> KiWiLiteral cache from the cache manager. This cache is used when constructing new
+ * KiWiLiterals to avoid a database lookup.
+ *
+ * @return
+ * @see org.apache.marmotta.commons.sesame.model.LiteralCommons#createCacheKey(String, java.util.Locale, String)
+ */
+ @Override
+ public Map<String, KiWiLiteral> getLiteralCache() {
+ return null;
+ }
+
+ /**
+ * Return the URI -> namespace cache from the cache manager. Used for looking up namespaces
+ *
+ * @return
+ */
+ @Override
+ public Map<String, KiWiNamespace> getNamespaceUriCache() {
+ return null;
+ }
+
+ /**
+ * Return the prefix -> namespace cache from the cache manager. Used for looking up namespaces
+ *
+ * @return
+ */
+ @Override
+ public Map<String, KiWiNamespace> getNamespacePrefixCache() {
+ return null;
+ }
+
+ /**
+ * Create and return the cache used by the CacheTripleRegistry. This is an unlimited synchronous replicated
+ * cache and should be used with care.
+ *
+ * @return
+ */
+ @Override
+ public Map<Long, Long> getRegistryCache() {
+ return null;
+ }
+
+ /**
+ * Get the cache with the given name from the cache manager. Can be used to request additional
+ * caches from the cache manager that are not covered by explicit methods.
+ *
+ * @param name
+ * @return
+ */
+ @Override
+ public Map getCacheByName(String name) {
+ return null;
+ }
+
+ /**
+ * Clear all caches managed by this cache manager.
+ */
+ @Override
+ public void clear() {
+
+ }
+
+ /**
+ * Shutdown this cache manager instance. Will shutdown the underlying EHCache cache manager.
+ */
+ @Override
+ public void shutdown() {
+
+ }
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/27a05239/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/caching/HazelcastCacheManagerFactory.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/caching/HazelcastCacheManagerFactory.java b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/caching/HazelcastCacheManagerFactory.java
index dee0b13..011e261 100644
--- a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/caching/HazelcastCacheManagerFactory.java
+++ b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/caching/HazelcastCacheManagerFactory.java
@@ -17,10 +17,28 @@
package org.apache.marmotta.kiwi.hazelcast.caching;
+import org.apache.marmotta.kiwi.caching.CacheManager;
+import org.apache.marmotta.kiwi.caching.CacheManagerFactory;
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+
/**
* Add file description here!
*
* @author Sebastian Schaffert (sschaffert@apache.org)
*/
-public class HazelcastCacheManagerFactory {
+public class HazelcastCacheManagerFactory implements CacheManagerFactory {
+
+ public HazelcastCacheManagerFactory() {
+ }
+
+ /**
+ * Create a new cache manager instance using the KiWiConfiguration passed as argument.
+ *
+ * @param configuration KiWi configuration used by the underlying triple store
+ * @return a new cache manager instance for this triple store
+ */
+ @Override
+ public CacheManager createCacheManager(KiWiConfiguration configuration) {
+ return new HazelcastCacheManager(configuration);
+ }
}
[15/21] git commit: test for remote cache working
Posted by ss...@apache.org.
test for remote cache working
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/d46c684b
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/d46c684b
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/d46c684b
Branch: refs/heads/MARMOTTA-450
Commit: d46c684b8a39d15ef597973f89042ba181cad894
Parents: 1497768
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Tue Mar 4 20:39:19 2014 +0100
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Tue Mar 4 20:39:19 2014 +0100
----------------------------------------------------------------------
.../marmotta/kiwi/test/RemoteClusterTest.java | 26 +++++++++-----------
1 file changed, 12 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d46c684b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/RemoteClusterTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/RemoteClusterTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/RemoteClusterTest.java
index 630f64e..4295c28 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/RemoteClusterTest.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/RemoteClusterTest.java
@@ -17,7 +17,6 @@
package org.apache.marmotta.kiwi.test;
-import org.apache.marmotta.commons.vocabulary.XSD;
import org.apache.marmotta.kiwi.caching.CacheManager;
import org.apache.marmotta.kiwi.config.CacheManagerType;
import org.apache.marmotta.kiwi.config.KiWiConfiguration;
@@ -26,12 +25,13 @@ import org.apache.marmotta.kiwi.infinispan.remote.CustomJBossMarshaller;
import org.apache.marmotta.kiwi.test.cluster.BaseClusterTest;
import org.infinispan.client.hotrod.RemoteCache;
import org.infinispan.client.hotrod.RemoteCacheManager;
+import org.infinispan.commons.api.BasicCacheContainer;
+import org.infinispan.commons.equivalence.ByteArrayEquivalence;
import org.infinispan.configuration.cache.CacheMode;
import org.infinispan.configuration.cache.Configuration;
import org.infinispan.configuration.cache.ConfigurationBuilder;
import org.infinispan.configuration.global.GlobalConfiguration;
import org.infinispan.configuration.global.GlobalConfigurationBuilder;
-import org.infinispan.eviction.EvictionStrategy;
import org.infinispan.manager.DefaultCacheManager;
import org.infinispan.manager.EmbeddedCacheManager;
import org.infinispan.server.hotrod.HotRodServer;
@@ -42,8 +42,6 @@ import org.junit.BeforeClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.concurrent.TimeUnit;
-
/**
* Add file description here!
*
@@ -91,6 +89,8 @@ public class RemoteClusterTest extends BaseClusterTest {
.proxyHost("127.0.0.1")
.proxyPort(port)
.topologyStateTransfer(false)
+ .defaultCacheName(BasicCacheContainer.DEFAULT_CACHE_NAME)
+ .idleTimeout(0)
.workerThreads(2)
.build(true);
@@ -104,13 +104,11 @@ public class RemoteClusterTest extends BaseClusterTest {
Configuration defaultConfiguration = new ConfigurationBuilder()
.clustering()
- .cacheMode(CacheMode.LOCAL)
- .eviction()
- .strategy(EvictionStrategy.LIRS)
- .maxEntries(100000)
- .expiration()
- .lifespan(5, TimeUnit.MINUTES)
- .maxIdle(1, TimeUnit.MINUTES)
+ .cacheMode(CacheMode.LOCAL)
+ .sync()
+ .dataContainer()
+ .keyEquivalence(ByteArrayEquivalence.INSTANCE)
+ .valueEquivalence(ByteArrayEquivalence.INSTANCE)
.build();
EmbeddedCacheManager cacheManager = new DefaultCacheManager(globalConfiguration, defaultConfiguration, true);
@@ -129,7 +127,7 @@ public class RemoteClusterTest extends BaseClusterTest {
cacheManager.getCache(CacheManager.LITERAL_CACHE, true);
cacheManager.getCache(CacheManager.NS_PREFIX_CACHE, true);
cacheManager.getCache(CacheManager.NS_URI_CACHE, true);
- cacheManager.getCache(CacheManager.REGISTRY_CACHE,true);
+ cacheManager.getCache(CacheManager.REGISTRY_CACHE, true);
hotRodServer.start(hotrodConfig, cacheManager);
@@ -148,8 +146,8 @@ public class RemoteClusterTest extends BaseClusterTest {
RemoteCache<String, String> m = remoteCacheManager.getCache();
- m.put(XSD.AnyURI.stringValue(), XSD.AnyURI.stringValue());
- String n = m.get(XSD.AnyURI.stringValue());
+ m.put("xyz", "abc");
+ String n = m.get("xyz");
Assert.assertNotNull(n);
[09/21] git commit: - implementation of Hazelcast cache backend -
common base class for cache cluster tests
Posted by ss...@apache.org.
- implementation of Hazelcast cache backend
- common base class for cache cluster tests
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/62c44dea
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/62c44dea
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/62c44dea
Branch: refs/heads/MARMOTTA-450
Commit: 62c44deafc9cf6332087368a8372dad37cb3032f
Parents: 27a0523
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Mon Mar 3 22:30:09 2014 +0100
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Mon Mar 3 22:30:09 2014 +0100
----------------------------------------------------------------------
.../org/apache/marmotta/commons/io/DataIO.java | 11 +-
libraries/kiwi/kiwi-caching-hazelcast/pom.xml | 59 +++++
.../caching/HazelcastCacheManager.java | 130 +++++++++-
.../marmotta/kiwi/hazelcast/util/AsyncMap.java | 102 ++++++++
.../kiwi/test/cluster/HazelcastClusterTest.java | 36 +++
.../kiwi/test/cluster/SerializerTest.java | 241 +++++++++++++++++++
.../InfinispanEmbeddedCacheManager.java | 6 +-
.../apache/marmotta/kiwi/test/ClusterTest.java | 160 ------------
.../kiwi/test/cluster/BaseClusterTest.java | 160 ++++++++++++
9 files changed, 727 insertions(+), 178 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/62c44dea/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/io/DataIO.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/io/DataIO.java b/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/io/DataIO.java
index d236ef7..ca4b53d 100644
--- a/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/io/DataIO.java
+++ b/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/io/DataIO.java
@@ -33,7 +33,9 @@ public class DataIO {
public static void writeString(DataOutput out, String s) throws IOException {
if(s != null) {
out.writeInt(s.length());
- out.writeChars(s);
+ for(int i=0; i<s.length(); i++) {
+ out.writeChar(s.charAt(i));
+ }
} else {
out.writeInt(-1);
}
@@ -44,11 +46,12 @@ public class DataIO {
int len = in.readInt();
if(len >= 0) {
- StringBuilder builder = new StringBuilder();
+ char[] result = new char[len];
+
for(int i=0; i<len; i++) {
- builder.append(in.readChar());
+ result[i] = in.readChar();
}
- return builder.toString();
+ return new String(result);
} else {
return null;
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/62c44dea/libraries/kiwi/kiwi-caching-hazelcast/pom.xml
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/pom.xml b/libraries/kiwi/kiwi-caching-hazelcast/pom.xml
index 833fece..b1f406a 100644
--- a/libraries/kiwi/kiwi-caching-hazelcast/pom.xml
+++ b/libraries/kiwi/kiwi-caching-hazelcast/pom.xml
@@ -48,6 +48,65 @@
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
</dependency>
+
+
+ <!-- Testing -->
+ <dependency>
+ <artifactId>junit</artifactId>
+ <groupId>junit</groupId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.marmotta</groupId>
+ <artifactId>kiwi-triplestore</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <artifactId>hamcrest-core</artifactId>
+ <groupId>org.hamcrest</groupId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <artifactId>hamcrest-library</artifactId>
+ <groupId>org.hamcrest</groupId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.postgresql</groupId>
+ <artifactId>postgresql</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ <scope>test</scope>
+ <optional>true</optional> <!-- GPL licensed, no dependency -->
+ </dependency>
+ <dependency>
+ <groupId>org.openrdf.sesame</groupId>
+ <artifactId>sesame-rio-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.openrdf.sesame</groupId>
+ <artifactId>sesame-rio-rdfxml</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/marmotta/blob/62c44dea/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/caching/HazelcastCacheManager.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/caching/HazelcastCacheManager.java b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/caching/HazelcastCacheManager.java
index 446fa4b..cc037c9 100644
--- a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/caching/HazelcastCacheManager.java
+++ b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/caching/HazelcastCacheManager.java
@@ -18,11 +18,19 @@
package org.apache.marmotta.kiwi.hazelcast.caching;
import com.hazelcast.config.Config;
+import com.hazelcast.config.MapConfig;
+import com.hazelcast.config.MaxSizeConfig;
import com.hazelcast.config.SerializerConfig;
+import com.hazelcast.core.Hazelcast;
+import com.hazelcast.core.HazelcastInstance;
import org.apache.marmotta.kiwi.caching.CacheManager;
+import org.apache.marmotta.kiwi.config.CacheMode;
import org.apache.marmotta.kiwi.config.KiWiConfiguration;
import org.apache.marmotta.kiwi.hazelcast.serializer.*;
+import org.apache.marmotta.kiwi.hazelcast.util.AsyncMap;
import org.apache.marmotta.kiwi.model.rdf.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.util.Map;
@@ -33,16 +41,56 @@ import java.util.Map;
*/
public class HazelcastCacheManager implements CacheManager {
+ public static final String TRIPLE_CACHE = "triple-cache";
+ public static final String URI_CACHE = "uri-cache";
+ public static final String BNODE_CACHE = "bnode-cache";
+ public static final String LITERAL_CACHE = "literal-cache";
+ public static final String NODE_CACHE = "node-cache";
+ public static final String NS_PREFIX_CACHE = "ns-prefix-cache";
+ public static final String NS_URI_CACHE = "ns-uri-cache";
+ public static final String REGISTRY_CACHE = "registry-cache";
+
+ private static Logger log = LoggerFactory.getLogger(HazelcastCacheManager.class);
+
private KiWiConfiguration configuration;
private Config hcConfiguration;
+ private HazelcastInstance hazelcast;
+
+ private AsyncMap<Long,KiWiNode> nodeCache;
+ private AsyncMap<Long,KiWiTriple> tripleCache;
+ private AsyncMap<String,KiWiUriResource> uriCache;
+ private AsyncMap<String,KiWiAnonResource> bnodeCache;
+ private AsyncMap<String,KiWiLiteral> literalCache;
+ private AsyncMap<String,KiWiNamespace> nsPrefixCache;
+ private AsyncMap<String,KiWiNamespace> nsUriCache;
+
+ private Map<Long,Long> registryCache;
+
public HazelcastCacheManager(KiWiConfiguration configuration) {
this.configuration = configuration;
hcConfiguration = new Config();
+ hcConfiguration.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(true);
+ hcConfiguration.getNetworkConfig().getJoin().getMulticastConfig().setMulticastPort(configuration.getClusterPort());
+ hcConfiguration.getNetworkConfig().getJoin().getMulticastConfig().setMulticastGroup(configuration.getClusterAddress());
+ hcConfiguration.getGroupConfig().setName(configuration.getClusterName());
+
+
+
setupSerializers();
+ setupCaches();
+
+ hazelcast = Hazelcast.newHazelcastInstance(hcConfiguration);
+
+
+ log.info("initialised Hazelcast distributed cache manager (cluster name: {})", configuration.getClusterName());
+
+ if(configuration.getCacheMode() != CacheMode.DISTRIBUTED) {
+ log.warn("Hazelcast only supports distributed cache mode (mode configuration was {})", configuration.getCacheMode());
+ }
}
private void setupSerializers() {
@@ -71,6 +119,30 @@ public class HazelcastCacheManager implements CacheManager {
hcConfiguration.getSerializationConfig().addSerializerConfig(scUri);
}
+ private void setupCaches() {
+ setupMapConfig(NODE_CACHE, configuration.getNodeCacheSize());
+ setupMapConfig(TRIPLE_CACHE, configuration.getTripleCacheSize());
+ setupMapConfig(URI_CACHE, configuration.getUriCacheSize());
+ setupMapConfig(BNODE_CACHE, configuration.getBNodeCacheSize());
+ setupMapConfig(LITERAL_CACHE, configuration.getLiteralCacheSize());
+ setupMapConfig(NS_PREFIX_CACHE, configuration.getNamespaceCacheSize());
+ setupMapConfig(NS_URI_CACHE, configuration.getNamespaceCacheSize());
+
+ }
+
+
+ private void setupMapConfig(String name, int size) {
+ MapConfig cfg = new MapConfig(NODE_CACHE);
+ cfg.setMaxSizeConfig(new MaxSizeConfig(size, MaxSizeConfig.MaxSizePolicy.PER_PARTITION));
+ cfg.setAsyncBackupCount(1);
+ cfg.setBackupCount(0);
+ cfg.setEvictionPolicy(MapConfig.EvictionPolicy.LRU);
+ cfg.setMaxIdleSeconds(600); // 10 minutes
+ cfg.setTimeToLiveSeconds(3600); // 1 hour
+
+ hcConfiguration.addMapConfig(cfg);
+ }
+
/**
* Return the node id -> node cache from the cache manager. This cache is heavily used to lookup
* nodes when querying or loading triples and should therefore have a decent size (default 500.000 elements).
@@ -79,7 +151,11 @@ public class HazelcastCacheManager implements CacheManager {
*/
@Override
public Map<Long, KiWiNode> getNodeCache() {
- return null;
+ if(nodeCache == null) {
+ nodeCache = new AsyncMap<>(hazelcast.<Long,KiWiNode>getMap(NODE_CACHE));
+ }
+
+ return nodeCache;
}
/**
@@ -90,7 +166,11 @@ public class HazelcastCacheManager implements CacheManager {
*/
@Override
public Map<Long, KiWiTriple> getTripleCache() {
- return null;
+ if(tripleCache == null) {
+ tripleCache = new AsyncMap<>(hazelcast.<Long,KiWiTriple>getMap(TRIPLE_CACHE));
+ }
+
+ return tripleCache;
}
/**
@@ -101,7 +181,11 @@ public class HazelcastCacheManager implements CacheManager {
*/
@Override
public Map<String, KiWiUriResource> getUriCache() {
- return null;
+ if(uriCache == null) {
+ uriCache = new AsyncMap<>(hazelcast.<String,KiWiUriResource>getMap(URI_CACHE));
+ }
+
+ return uriCache;
}
/**
@@ -112,7 +196,11 @@ public class HazelcastCacheManager implements CacheManager {
*/
@Override
public Map<String, KiWiAnonResource> getBNodeCache() {
- return null;
+ if(bnodeCache == null) {
+ bnodeCache = new AsyncMap<>(hazelcast.<String,KiWiAnonResource>getMap(BNODE_CACHE));
+ }
+
+ return bnodeCache;
}
/**
@@ -124,7 +212,11 @@ public class HazelcastCacheManager implements CacheManager {
*/
@Override
public Map<String, KiWiLiteral> getLiteralCache() {
- return null;
+ if(literalCache == null) {
+ literalCache = new AsyncMap<>(hazelcast.<String,KiWiLiteral>getMap(LITERAL_CACHE));
+ }
+
+ return literalCache;
}
/**
@@ -134,7 +226,11 @@ public class HazelcastCacheManager implements CacheManager {
*/
@Override
public Map<String, KiWiNamespace> getNamespaceUriCache() {
- return null;
+ if(nsUriCache == null) {
+ nsUriCache = new AsyncMap<>(hazelcast.<String,KiWiNamespace>getMap(NS_URI_CACHE));
+ }
+
+ return nsUriCache;
}
/**
@@ -144,7 +240,11 @@ public class HazelcastCacheManager implements CacheManager {
*/
@Override
public Map<String, KiWiNamespace> getNamespacePrefixCache() {
- return null;
+ if(nsPrefixCache == null) {
+ nsPrefixCache = new AsyncMap<>(hazelcast.<String,KiWiNamespace>getMap(NS_PREFIX_CACHE));
+ }
+
+ return nsPrefixCache;
}
/**
@@ -155,7 +255,11 @@ public class HazelcastCacheManager implements CacheManager {
*/
@Override
public Map<Long, Long> getRegistryCache() {
- return null;
+ if(registryCache == null) {
+ registryCache = hazelcast.<Long, Long>getMap(REGISTRY_CACHE);
+ }
+
+ return registryCache;
}
/**
@@ -167,7 +271,7 @@ public class HazelcastCacheManager implements CacheManager {
*/
@Override
public Map getCacheByName(String name) {
- return null;
+ return hazelcast.getMap(name);
}
/**
@@ -175,7 +279,11 @@ public class HazelcastCacheManager implements CacheManager {
*/
@Override
public void clear() {
-
+ for(Map m : new Map[] { nodeCache, tripleCache, uriCache, bnodeCache, literalCache, nsPrefixCache, nsUriCache, registryCache}) {
+ if(m != null) {
+ m.clear();
+ }
+ }
}
/**
@@ -183,6 +291,6 @@ public class HazelcastCacheManager implements CacheManager {
*/
@Override
public void shutdown() {
-
+ hazelcast.shutdown();
}
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/62c44dea/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/util/AsyncMap.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/util/AsyncMap.java b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/util/AsyncMap.java
new file mode 100644
index 0000000..7aa4722
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/util/AsyncMap.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.hazelcast.util;
+
+import com.hazelcast.core.IMap;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A Map wrapper mapping write methods to their asynchronous equivalents in Hazelcast.
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class AsyncMap<K,V> implements Map<K,V> {
+
+ private IMap<K,V> delegate;
+
+ public AsyncMap(IMap<K, V> delegate) {
+ this.delegate = delegate;
+ }
+
+ @Override
+ public int size() {
+ return delegate.size();
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return delegate.isEmpty();
+ }
+
+ @Override
+ public boolean containsKey(Object o) {
+ return delegate.containsKey(o);
+ }
+
+ @Override
+ public boolean containsValue(Object o) {
+ return delegate.containsValue(o);
+ }
+
+ @Override
+ public V get(Object o) {
+ return delegate.get(o);
+ }
+
+ @Override
+ public V put(K k, V v) {
+ delegate.putAsync(k,v);
+ return null;
+ }
+
+ @Override
+ public V remove(Object o) {
+ delegate.removeAsync((K)o);
+ return null;
+ }
+
+ @Override
+ public void putAll(Map<? extends K, ? extends V> map) {
+ for(Entry<? extends K, ? extends V> entry : map.entrySet()) {
+ delegate.putAsync(entry.getKey(),entry.getValue());
+ }
+ }
+
+ @Override
+ public void clear() {
+ delegate.clear();
+ }
+
+ @Override
+ public Set<K> keySet() {
+ return delegate.keySet();
+ }
+
+ @Override
+ public Collection<V> values() {
+ return delegate.values();
+ }
+
+ @Override
+ public Set<Entry<K, V>> entrySet() {
+ return delegate.entrySet();
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/62c44dea/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastClusterTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastClusterTest.java b/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastClusterTest.java
new file mode 100644
index 0000000..c53b704
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastClusterTest.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.test.cluster;
+
+import org.apache.marmotta.kiwi.caching.CacheManagerType;
+import org.junit.BeforeClass;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class HazelcastClusterTest extends BaseClusterTest {
+
+
+ @BeforeClass
+ public static void setup() {
+ ClusterTestSupport s = new ClusterTestSupport(CacheManagerType.HAZELCAST);
+ s.setup();
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/62c44dea/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/SerializerTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/SerializerTest.java b/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/SerializerTest.java
new file mode 100644
index 0000000..675db87
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/SerializerTest.java
@@ -0,0 +1,241 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.test.cluster;
+
+import com.hazelcast.config.SerializationConfig;
+import com.hazelcast.config.SerializerConfig;
+import com.hazelcast.nio.serialization.*;
+import org.apache.commons.lang3.RandomStringUtils;
+import org.apache.marmotta.commons.vocabulary.XSD;
+import org.apache.marmotta.kiwi.hazelcast.serializer.*;
+import org.apache.marmotta.kiwi.model.rdf.*;
+import org.apache.marmotta.kiwi.test.TestValueFactory;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.openrdf.model.Value;
+import org.openrdf.model.ValueFactory;
+import org.openrdf.model.vocabulary.OWL;
+import org.openrdf.model.vocabulary.RDFS;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.util.Random;
+
+/**
+ * Test the different externalizer implementations we provide for Infinispan
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class SerializerTest {
+
+ private static ValueFactory valueFactory = new TestValueFactory();
+
+ private static Random rnd = new Random();
+
+ private static Logger log = LoggerFactory.getLogger(SerializerTest.class);
+
+
+ private static SerializationService simpleService, fullService;
+
+ @BeforeClass
+ public static void setup() {
+ simpleService = new SerializationServiceBuilder().build();
+
+
+ SerializationConfig config = new SerializationConfig();
+ SerializerConfig scBNode = new SerializerConfig().setImplementation(new BNodeSerializer()).setTypeClass(KiWiAnonResource.class);
+ config.addSerializerConfig(scBNode);
+
+ SerializerConfig scBoolean = new SerializerConfig().setImplementation(new BooleanLiteralSerializer()).setTypeClass(KiWiBooleanLiteral.class);
+ config.addSerializerConfig(scBoolean);
+
+ SerializerConfig scDate = new SerializerConfig().setImplementation(new DateLiteralSerializer()).setTypeClass(KiWiDateLiteral.class);
+ config.addSerializerConfig(scDate);
+
+ SerializerConfig scDouble = new SerializerConfig().setImplementation(new DoubleLiteralSerializer()).setTypeClass(KiWiDoubleLiteral.class);
+ config.addSerializerConfig(scDouble);
+
+ SerializerConfig scInt = new SerializerConfig().setImplementation(new IntLiteralSerializer()).setTypeClass(KiWiIntLiteral.class);
+ config.addSerializerConfig(scInt);
+
+ SerializerConfig scString = new SerializerConfig().setImplementation(new StringLiteralSerializer()).setTypeClass(KiWiStringLiteral.class);
+ config.addSerializerConfig(scString);
+
+ SerializerConfig scTriple = new SerializerConfig().setImplementation(new TripleSerializer()).setTypeClass(KiWiTriple.class);
+ config.addSerializerConfig(scTriple);
+
+ SerializerConfig scUri = new SerializerConfig().setImplementation(new UriSerializer()).setTypeClass(KiWiUriResource.class);
+ config.addSerializerConfig(scUri);
+
+
+ fullService = new SerializationServiceBuilder().setConfig(config).build();
+
+
+ }
+
+
+ @Test
+ public void testUriResource() throws Exception {
+ marshall((KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8)), new UriSerializer());
+ }
+
+ @Test
+ public void testCompressedUriResource() throws Exception {
+ marshall((KiWiUriResource) valueFactory.createURI(XSD.Double.stringValue()), new UriSerializer());
+ marshall((KiWiUriResource) valueFactory.createURI(RDFS.LABEL.stringValue()), new UriSerializer());
+ marshall((KiWiUriResource) valueFactory.createURI(OWL.SAMEAS.stringValue()), new UriSerializer());
+ }
+
+
+ @Test
+ public void testBNode() throws Exception {
+ marshall((KiWiAnonResource) valueFactory.createBNode(), new BNodeSerializer());
+ }
+
+ @Test
+ public void testStringLiteral() throws Exception {
+ marshall((KiWiStringLiteral) valueFactory.createLiteral(RandomStringUtils.randomAscii(40)), new StringLiteralSerializer());
+ }
+
+ @Test
+ public void testLangLiteral() throws Exception {
+ marshall((KiWiStringLiteral) valueFactory.createLiteral(RandomStringUtils.randomAscii(40),"en"), new StringLiteralSerializer());
+ }
+
+ @Test
+ public void testTypeLiteral() throws Exception {
+ marshall((KiWiStringLiteral) valueFactory.createLiteral(RandomStringUtils.randomAscii(40),valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8))), new StringLiteralSerializer());
+ }
+
+
+ @Test
+ public void testIntLiteral() throws Exception {
+ marshall((KiWiIntLiteral) valueFactory.createLiteral(rnd.nextInt()), new IntLiteralSerializer());
+ }
+
+
+ @Test
+ public void testTriple() throws Exception {
+ KiWiUriResource s = (KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
+ KiWiUriResource p = (KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
+ KiWiNode o = (KiWiNode) randomNode();
+ KiWiTriple t = (KiWiTriple) valueFactory.createStatement(s,p,o);
+
+ marshall(t, new TripleSerializer());
+ }
+
+ @Test
+ public void testPrefixCompressedTriple() throws Exception {
+ KiWiUriResource s = (KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
+ KiWiUriResource p = (KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
+ KiWiUriResource o = (KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
+ KiWiTriple t = (KiWiTriple) valueFactory.createStatement(s,p,o);
+
+ marshall(t, new TripleSerializer());
+ }
+
+
+ /**
+ * Run the given object through the marshaller using an in-memory stream.
+ * @param origin
+ * @param <T>
+ * @return
+ */
+ private <T> void marshall(T origin, StreamSerializer<T> externalizer) throws IOException, ClassNotFoundException, InterruptedException {
+ log.info("- testing Java ObjectStream ...");
+ ByteArrayOutputStream outBytesOS = new ByteArrayOutputStream();
+ ObjectOutputStream outOS = new ObjectOutputStream(outBytesOS);
+
+ outOS.writeObject(origin);
+
+ outOS.close();
+
+ log.info(" object {}: serialized with {} bytes", origin, outBytesOS.size());
+
+
+ log.info("- testing serializer directly ...");
+ ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
+ ObjectDataOutputStream out = new ObjectDataOutputStream(outBytes, simpleService);
+
+ externalizer.write(out, origin);
+ out.close();
+
+ log.info(" object {}: serialized with {} bytes", origin, outBytes.size());
+
+ ByteArrayInputStream inBytes = new ByteArrayInputStream(outBytes.toByteArray());
+ ObjectDataInputStream in = new ObjectDataInputStream(inBytes, simpleService);
+
+ T destination1 = externalizer.read(in);
+
+ Assert.assertEquals(origin,destination1);
+
+
+
+ log.info("- testing serializer with Hazelcast serialization service ...");
+
+
+ ByteArrayOutputStream outBytesFull = new ByteArrayOutputStream();
+ ObjectDataOutputStream outFull = new ObjectDataOutputStream(outBytesFull, fullService);
+
+ fullService.writeObject(outFull, origin);
+ outFull.close();
+
+ log.info(" object {}: serialized with {} bytes", origin, outBytesFull.size());
+
+ ByteArrayInputStream inBytesFull = new ByteArrayInputStream(outBytesFull.toByteArray());
+ ObjectDataInputStream inFull = new ObjectDataInputStream(inBytesFull, fullService);
+
+ T destination2 = (T) fullService.readObject(inFull);
+
+ Assert.assertEquals(origin, destination2);
+
+ }
+
+
+ /**
+ * Return a random RDF value, either a reused object (10% chance) or of any other kind.
+ * @return
+ */
+ protected Value randomNode() {
+ Value object;
+ switch(rnd.nextInt(6)) {
+ case 0: object = valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
+ break;
+ case 1: object = valueFactory.createBNode();
+ break;
+ case 2: object = valueFactory.createLiteral(RandomStringUtils.randomAscii(40));
+ break;
+ case 3: object = valueFactory.createLiteral(rnd.nextInt());
+ break;
+ case 4: object = valueFactory.createLiteral(rnd.nextDouble());
+ break;
+ case 5: object = valueFactory.createLiteral(rnd.nextBoolean());
+ break;
+ default: object = valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
+ break;
+
+ }
+ return object;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/62c44dea/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/embedded/InfinispanEmbeddedCacheManager.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/embedded/InfinispanEmbeddedCacheManager.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/embedded/InfinispanEmbeddedCacheManager.java
index 5818e0b..85ed56b 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/embedded/InfinispanEmbeddedCacheManager.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/embedded/InfinispanEmbeddedCacheManager.java
@@ -129,7 +129,7 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
.build();
cacheManager = new DefaultCacheManager(globalConfiguration, defaultConfiguration, true);
- log.info("initialised local cache manager");
+ log.info("initialised Infinispan local cache manager");
}
/**
@@ -182,7 +182,7 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
.build();
cacheManager = new DefaultCacheManager(globalConfiguration, defaultConfiguration, true);
- log.info("initialised distributed cache manager (cluster name: {})", globalConfiguration.transport().clusterName());
+ log.info("initialised Infinispan distributed cache manager (cluster name: {})", globalConfiguration.transport().clusterName());
}
@@ -229,7 +229,7 @@ public class InfinispanEmbeddedCacheManager implements CacheManager {
.build();
cacheManager = new DefaultCacheManager(globalConfiguration, defaultConfiguration, true);
- log.info("initialised replicated cache manager (cluster name: {})", globalConfiguration.transport().clusterName());
+ log.info("initialised Infinispan replicated cache manager (cluster name: {})", globalConfiguration.transport().clusterName());
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/62c44dea/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/ClusterTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/ClusterTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/ClusterTest.java
deleted file mode 100644
index 981e595..0000000
--- a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/ClusterTest.java
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.kiwi.test;
-
-import com.google.common.hash.Hasher;
-import com.google.common.hash.Hashing;
-import org.apache.marmotta.kiwi.caching.CacheManager;
-import org.apache.marmotta.kiwi.config.KiWiConfiguration;
-import org.apache.marmotta.kiwi.embedded.InfinispanEmbeddedCacheManagerFactory;
-import org.apache.marmotta.kiwi.persistence.h2.H2Dialect;
-import org.apache.marmotta.kiwi.sail.KiWiStore;
-import org.junit.*;
-import org.openrdf.model.URI;
-import org.openrdf.repository.Repository;
-import org.openrdf.repository.RepositoryException;
-import org.openrdf.repository.sail.SailRepository;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Add file description here!
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class ClusterTest {
-
- private static Logger log = LoggerFactory.getLogger(ClusterTest.class);
-
- KiWiConfiguration config1, config2;
-
- KiWiStore store1, store2;
-
- Repository repository1, repository2;
-
- CacheManager cacheManager1, cacheManager2;
-
- @Before
- public void setup() throws RepositoryException {
- config1 = new KiWiConfiguration(
- "default-H2",
- "jdbc:h2:mem:kiwitest;MVCC=true;DB_CLOSE_ON_EXIT=TRUE;DB_CLOSE_DELAY=-1",
- "kiwi", "kiwi",
- new H2Dialect());
- config1.setDatacenterId(1);
- config1.setClustered(true);
- config1.setCacheManager(InfinispanEmbeddedCacheManagerFactory.class.getName());
-
- config2 = new KiWiConfiguration(
- "default-H2",
- "jdbc:h2:mem:kiwitest;MVCC=true;DB_CLOSE_ON_EXIT=TRUE;DB_CLOSE_DELAY=-1",
- "kiwi", "kiwi",
- new H2Dialect());
- config2.setDatacenterId(2);
- config2.setClustered(true);
- config2.setCacheManager(InfinispanEmbeddedCacheManagerFactory.class.getName());
-
-
-
- }
-
- public void setupCluster(int port1, int port2) throws RepositoryException {
- config1.setClusterPort(port1);
- config2.setClusterPort(port2);
-
- store1 = new KiWiStore(config1);
- store2 = new KiWiStore(config2);
-
- repository1 = new SailRepository(store1);
- repository2 = new SailRepository(store2);
-
- repository1.initialize();
- repository2.initialize();
-
- cacheManager1 = store1.getPersistence().getCacheManager();
- cacheManager2 = store2.getPersistence().getCacheManager();
- }
-
-
- @After
- public void teardown() throws RepositoryException {
- repository1.shutDown();
- repository2.shutDown();
- }
-
-
- @Test
- @Ignore
- public void testClusteredCacheSync() throws InterruptedException, RepositoryException {
- setupCluster(61222,61222);
-
- log.info("testing cache synchronization ...");
-
- URI u = repository1.getValueFactory().createURI("http://localhost/test1");
-
-
- // give the cluster some time to performance asynchronous balancing
- Thread.sleep(100);
-
-
- log.debug("test if resource is in cache where it was created ...");
- URI u1 = (URI) cacheManager1.getUriCache().get(createCacheKey("http://localhost/test1"));
-
- Assert.assertNotNull(u1);
- Assert.assertEquals(u,u1);
-
- log.debug("test if resource has been synced to other cache in cluster ...");
- URI u2 = (URI) cacheManager2.getUriCache().get(createCacheKey("http://localhost/test1"));
-
- Assert.assertNotNull(u2);
- Assert.assertEquals(u,u2);
- }
-
- @Test
- @Ignore
- public void testDisjointClusters() throws InterruptedException, RepositoryException {
- setupCluster(61224,61225);
-
- log.info("testing caches on different ports ...");
-
- URI u = repository1.getValueFactory().createURI("http://localhost/test1");
-
-
- // give the cluster some time to performance asynchronous balancing
- Thread.sleep(100);
-
- log.debug("test if resource is in cache where it was created ...");
- URI u1 = (URI) cacheManager1.getUriCache().get(createCacheKey("http://localhost/test1"));
-
- Assert.assertNotNull(u1);
- Assert.assertEquals(u,u1);
-
- log.debug("test if resource has been synced to other cache in cluster ...");
- URI u2 = (URI) cacheManager2.getUriCache().get(createCacheKey("http://localhost/test1"));
-
- Assert.assertNull(u2);
- }
-
-
- private static Long createCacheKey(String svalue) {
- Hasher hasher = Hashing.goodFastHash(64).newHasher();
- hasher.putString(svalue);
- return hasher.hash().asLong();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/62c44dea/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/cluster/BaseClusterTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/cluster/BaseClusterTest.java b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/cluster/BaseClusterTest.java
new file mode 100644
index 0000000..4733aa9
--- /dev/null
+++ b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/cluster/BaseClusterTest.java
@@ -0,0 +1,160 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.test.cluster;
+
+import org.apache.marmotta.kiwi.caching.CacheManager;
+import org.apache.marmotta.kiwi.caching.CacheManagerType;
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+import org.apache.marmotta.kiwi.persistence.h2.H2Dialect;
+import org.apache.marmotta.kiwi.sail.KiWiStore;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Test;
+import org.openrdf.model.URI;
+import org.openrdf.repository.Repository;
+import org.openrdf.repository.RepositoryException;
+import org.openrdf.repository.sail.SailRepository;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public abstract class BaseClusterTest {
+
+ private static Logger log = LoggerFactory.getLogger(BaseClusterTest.class);
+
+ private static int datacenterIds = 1;
+
+ private static Repository repositorySync1, repositorySync2, repositoryAsync1, repositoryAsync2;
+
+ private static CacheManager cacheManagerSync1, cacheManagerSync2, cacheManagerAsync1, cacheManagerAsync2;
+
+
+ @AfterClass
+ public static void teardown() throws RepositoryException {
+ repositorySync1.shutDown();
+ repositorySync2.shutDown();
+ repositoryAsync1.shutDown();
+ repositoryAsync2.shutDown();
+ }
+
+
+ @Test
+ public void testClusteredCacheSync() throws InterruptedException, RepositoryException {
+
+ log.info("testing cache synchronization ...");
+
+ URI u = repositorySync1.getValueFactory().createURI("http://localhost/test1");
+
+
+ // give the cluster some time to performance asynchronous balancing
+ Thread.sleep(100);
+
+
+ log.debug("test if resource is in cache where it was created ...");
+ URI u1 = (URI) cacheManagerSync1.getUriCache().get("http://localhost/test1");
+
+ Assert.assertNotNull(u1);
+ Assert.assertEquals(u,u1);
+
+ log.debug("test if resource has been synced to other cache in cluster ...");
+ URI u2 = (URI) cacheManagerSync2.getUriCache().get("http://localhost/test1");
+
+ Assert.assertNotNull(u2);
+ Assert.assertEquals(u,u2);
+ }
+
+ @Test
+ public void testDisjointClusters() throws InterruptedException, RepositoryException {
+
+ log.info("testing caches on different ports ...");
+
+ URI u = repositoryAsync1.getValueFactory().createURI("http://localhost/test1");
+
+
+ // give the cluster some time to performance asynchronous balancing
+ Thread.sleep(100);
+
+ log.debug("test if resource is in cache where it was created ...");
+ URI u1 = (URI) cacheManagerAsync1.getUriCache().get("http://localhost/test1");
+
+ Assert.assertNotNull(u1);
+ Assert.assertEquals(u,u1);
+
+ log.debug("test if resource has been synced to other cache in cluster ...");
+ URI u2 = (URI) cacheManagerAsync2.getUriCache().get("http://localhost/test1");
+
+ Assert.assertNull(u2);
+ }
+
+
+ protected static class ClusterTestSupport {
+
+ CacheManagerType type;
+
+ protected ClusterTestSupport(CacheManagerType type) {
+ this.type = type;
+ }
+
+ public void setup() {
+ try {
+ repositorySync1 = createConfiguration(61222);
+ repositorySync2 = createConfiguration(61222);
+ repositoryAsync1 = createConfiguration(61223);
+ repositoryAsync2 = createConfiguration(61224);
+
+ cacheManagerSync1 = getCacheManager(repositorySync1);
+ cacheManagerSync2 = getCacheManager(repositorySync2);
+ cacheManagerAsync1 = getCacheManager(repositoryAsync1);
+ cacheManagerAsync2 = getCacheManager(repositoryAsync2);
+
+
+ } catch (RepositoryException ex) {
+ Assert.fail(ex.getMessage());
+ }
+ }
+
+
+ private Repository createConfiguration(int port) throws RepositoryException {
+ KiWiConfiguration config = new KiWiConfiguration(
+ "default-H2",
+ "jdbc:h2:mem:kiwitest;MVCC=true;DB_CLOSE_ON_EXIT=TRUE;DB_CLOSE_DELAY=-1",
+ "kiwi", "kiwi",
+ new H2Dialect());
+ config.setDatacenterId(datacenterIds++);
+ config.setClustered(true);
+ config.setCacheManager(type);
+ config.setClusterPort(port);
+
+ KiWiStore store = new KiWiStore(config);
+
+ Repository repository = new SailRepository(store);
+ repository.initialize();
+
+ return repository;
+ }
+
+ private static CacheManager getCacheManager(Repository repository) {
+ return ((KiWiStore)((SailRepository)repository).getSail()).getPersistence().getCacheManager();
+ }
+
+ }
+}
[21/21] git commit: start cleaning up the modules that depend on KiWi
so they do not depend on a specific caching backend
Posted by ss...@apache.org.
start cleaning up the modules that depend on KiWi so they do not depend on a specific caching backend
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/766bef0a
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/766bef0a
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/766bef0a
Branch: refs/heads/MARMOTTA-450
Commit: 766bef0a758e7e766cd57336eb6c68aa67e1c1b6
Parents: 673b4f9
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Wed Mar 5 13:22:43 2014 +0100
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Wed Mar 5 13:22:43 2014 +0100
----------------------------------------------------------------------
.../kiwi/test/cluster/HazelcastClusterTest.java | 4 +-
.../HazelcastRepositoryConnectionTest.java | 4 +-
.../test/cluster/HazelcastRepositoryTest.java | 4 +-
.../remote/InfinispanRemoteCacheManager.java | 1 +
.../kiwi/test/embedded/EmbeddedClusterTest.java | 4 +-
.../EmbeddedRepositoryConnectionTest.java | 4 +-
.../test/embedded/EmbeddedRepositoryTest.java | 4 +-
.../kiwi/test/remote/HotRodClusterTest.java | 4 +-
.../kiwi/test/remote/HotRodPersistenceTest.java | 4 +-
.../remote/HotRodRepositoryConnectionTest.java | 6 +-
.../kiwi/test/remote/HotRodRepositoryTest.java | 4 +-
.../marmotta/kiwi/config/CacheManagerType.java | 58 ------
.../marmotta/kiwi/config/CachingBackends.java | 58 ++++++
.../marmotta/kiwi/config/KiWiConfiguration.java | 10 +-
.../kiwi/persistence/KiWiPersistence.java | 4 +-
.../kiwi/test/cluster/BaseClusterTest.java | 8 +-
libraries/kiwi/pom.xml | 4 +-
.../platform/backend/kiwi/KiWiOptions.java | 51 +++++
.../backend/kiwi/KiWiStoreProvider.java | 116 +++++------
.../main/resources/config-defaults.properties | 12 +-
.../resources/config-descriptions.properties | 31 ++-
platform/marmotta-core/pom.xml | 11 --
.../platform/core/api/cache/CachingService.java | 32 +++-
.../platform/core/model/config/CoreOptions.java | 36 ++++
.../core/services/cache/CachingServiceImpl.java | 192 +++----------------
.../config/ConfigurationServiceImpl.java | 69 +++----
.../services/http/HttpClientServiceImpl.java | 19 +-
.../modules/MarmottaResourceServiceImpl.java | 4 +-
.../core/startup/MarmottaStartupService.java | 33 ++--
.../main/resources/config-defaults.properties | 10 +-
.../resources/config-descriptions.properties | 29 +--
.../user/services/AccountServiceImpl.java | 4 +-
32 files changed, 374 insertions(+), 460 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/766bef0a/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastClusterTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastClusterTest.java b/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastClusterTest.java
index 5cbbe7f..1683541 100644
--- a/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastClusterTest.java
+++ b/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastClusterTest.java
@@ -17,7 +17,7 @@
package org.apache.marmotta.kiwi.test.cluster;
-import org.apache.marmotta.kiwi.config.CacheManagerType;
+import org.apache.marmotta.kiwi.config.CachingBackends;
import org.junit.BeforeClass;
/**
@@ -30,7 +30,7 @@ public class HazelcastClusterTest extends BaseClusterTest {
@BeforeClass
public static void setup() {
- ClusterTestSupport s = new ClusterTestSupport(CacheManagerType.HAZELCAST);
+ ClusterTestSupport s = new ClusterTestSupport(CachingBackends.HAZELCAST);
s.setup();
}
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/766bef0a/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastRepositoryConnectionTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastRepositoryConnectionTest.java b/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastRepositoryConnectionTest.java
index ef75821..7b0be4b 100644
--- a/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastRepositoryConnectionTest.java
+++ b/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastRepositoryConnectionTest.java
@@ -17,8 +17,8 @@
package org.apache.marmotta.kiwi.test.cluster;
-import org.apache.marmotta.kiwi.config.CacheManagerType;
import org.apache.marmotta.kiwi.config.CacheMode;
+import org.apache.marmotta.kiwi.config.CachingBackends;
import org.apache.marmotta.kiwi.config.KiWiConfiguration;
import org.apache.marmotta.kiwi.sail.KiWiStore;
import org.apache.marmotta.kiwi.test.junit.KiWiDatabaseRunner;
@@ -44,7 +44,7 @@ public class HazelcastRepositoryConnectionTest extends RepositoryConnectionTest
config.setClustered(false);
config.setClusterPort(61222);
config.setCacheMode(CacheMode.DISTRIBUTED);
- config.setCacheManager(CacheManagerType.HAZELCAST);
+ config.setCachingBackend(CachingBackends.HAZELCAST);
}
/* (non-Javadoc)
http://git-wip-us.apache.org/repos/asf/marmotta/blob/766bef0a/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastRepositoryTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastRepositoryTest.java b/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastRepositoryTest.java
index 3b080ef..b686d77 100644
--- a/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastRepositoryTest.java
+++ b/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastRepositoryTest.java
@@ -17,8 +17,8 @@
package org.apache.marmotta.kiwi.test.cluster;
-import org.apache.marmotta.kiwi.config.CacheManagerType;
import org.apache.marmotta.kiwi.config.CacheMode;
+import org.apache.marmotta.kiwi.config.CachingBackends;
import org.apache.marmotta.kiwi.config.KiWiConfiguration;
import org.apache.marmotta.kiwi.sail.KiWiStore;
import org.apache.marmotta.kiwi.test.junit.KiWiDatabaseRunner;
@@ -44,7 +44,7 @@ public class HazelcastRepositoryTest extends RepositoryTest {
config.setClustered(true);
config.setClusterPort(61222);
config.setCacheMode(CacheMode.DISTRIBUTED);
- config.setCacheManager(CacheManagerType.HAZELCAST);
+ config.setCachingBackend(CachingBackends.HAZELCAST);
}
/* (non-Javadoc)
http://git-wip-us.apache.org/repos/asf/marmotta/blob/766bef0a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/InfinispanRemoteCacheManager.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/InfinispanRemoteCacheManager.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/InfinispanRemoteCacheManager.java
index 8455fdd..5fb6a67 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/InfinispanRemoteCacheManager.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/InfinispanRemoteCacheManager.java
@@ -55,6 +55,7 @@ public class InfinispanRemoteCacheManager implements CacheManager {
.port(configuration.getClusterPort())
.marshaller(new CustomJBossMarshaller())
.socketTimeout(configuration.getClusterTimeout())
+ .connectionTimeout(configuration.getClusterTimeout())
.build();
cacheManager = new RemoteCacheManager(remoteCfg);
http://git-wip-us.apache.org/repos/asf/marmotta/blob/766bef0a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedClusterTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedClusterTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedClusterTest.java
index 7405e0f..cfd61eb 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedClusterTest.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedClusterTest.java
@@ -17,7 +17,7 @@
package org.apache.marmotta.kiwi.test.embedded;
-import org.apache.marmotta.kiwi.config.CacheManagerType;
+import org.apache.marmotta.kiwi.config.CachingBackends;
import org.apache.marmotta.kiwi.test.cluster.BaseClusterTest;
import org.junit.BeforeClass;
@@ -31,7 +31,7 @@ public class EmbeddedClusterTest extends BaseClusterTest {
@BeforeClass
public static void setup() {
- ClusterTestSupport s = new ClusterTestSupport(CacheManagerType.INFINISPAN_CLUSTERED);
+ ClusterTestSupport s = new ClusterTestSupport(CachingBackends.INFINISPAN_CLUSTERED);
s.setup();
}
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/766bef0a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedRepositoryConnectionTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedRepositoryConnectionTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedRepositoryConnectionTest.java
index 8fffa88..910d16f 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedRepositoryConnectionTest.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedRepositoryConnectionTest.java
@@ -17,8 +17,8 @@
package org.apache.marmotta.kiwi.test.embedded;
-import org.apache.marmotta.kiwi.config.CacheManagerType;
import org.apache.marmotta.kiwi.config.CacheMode;
+import org.apache.marmotta.kiwi.config.CachingBackends;
import org.apache.marmotta.kiwi.config.KiWiConfiguration;
import org.apache.marmotta.kiwi.sail.KiWiStore;
import org.apache.marmotta.kiwi.test.junit.KiWiDatabaseRunner;
@@ -45,7 +45,7 @@ public class EmbeddedRepositoryConnectionTest extends RepositoryConnectionTest {
config.setClusterPort(61222);
config.setCacheMode(CacheMode.LOCAL);
config.setClusterTimeout(10000);
- config.setCacheManager(CacheManagerType.INFINISPAN_CLUSTERED);
+ config.setCachingBackend(CachingBackends.INFINISPAN_CLUSTERED);
}
/* (non-Javadoc)
http://git-wip-us.apache.org/repos/asf/marmotta/blob/766bef0a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedRepositoryTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedRepositoryTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedRepositoryTest.java
index 3796d68..acb51a7 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedRepositoryTest.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedRepositoryTest.java
@@ -17,8 +17,8 @@
package org.apache.marmotta.kiwi.test.embedded;
-import org.apache.marmotta.kiwi.config.CacheManagerType;
import org.apache.marmotta.kiwi.config.CacheMode;
+import org.apache.marmotta.kiwi.config.CachingBackends;
import org.apache.marmotta.kiwi.config.KiWiConfiguration;
import org.apache.marmotta.kiwi.sail.KiWiStore;
import org.apache.marmotta.kiwi.test.junit.KiWiDatabaseRunner;
@@ -45,7 +45,7 @@ public class EmbeddedRepositoryTest extends RepositoryTest {
config.setClusterPort(61222);
config.setCacheMode(CacheMode.LOCAL);
config.setClusterTimeout(10000);
- config.setCacheManager(CacheManagerType.INFINISPAN_CLUSTERED);
+ config.setCachingBackend(CachingBackends.INFINISPAN_CLUSTERED);
}
/* (non-Javadoc)
http://git-wip-us.apache.org/repos/asf/marmotta/blob/766bef0a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodClusterTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodClusterTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodClusterTest.java
index 3f4fa2a..14544c3 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodClusterTest.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodClusterTest.java
@@ -17,7 +17,7 @@
package org.apache.marmotta.kiwi.test.remote;
-import org.apache.marmotta.kiwi.config.CacheManagerType;
+import org.apache.marmotta.kiwi.config.CachingBackends;
import org.apache.marmotta.kiwi.config.KiWiConfiguration;
import org.apache.marmotta.kiwi.test.cluster.BaseClusterTest;
import org.junit.BeforeClass;
@@ -46,7 +46,7 @@ public class HotRodClusterTest extends BaseClusterTest {
@BeforeClass
public static void setup() {
- ClusterTestSupport s = new ClusterTestSupport(CacheManagerType.INFINISPAN_HOTROD);
+ ClusterTestSupport s = new ClusterTestSupport(CachingBackends.INFINISPAN_HOTROD);
KiWiConfiguration base = s.buildBaseConfiguration();
base.setClusterAddress("127.0.0.1");
http://git-wip-us.apache.org/repos/asf/marmotta/blob/766bef0a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodPersistenceTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodPersistenceTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodPersistenceTest.java
index 406fa9c..61ad5fc 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodPersistenceTest.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodPersistenceTest.java
@@ -17,7 +17,7 @@
package org.apache.marmotta.kiwi.test.remote;
-import org.apache.marmotta.kiwi.config.CacheManagerType;
+import org.apache.marmotta.kiwi.config.CachingBackends;
import org.apache.marmotta.kiwi.config.KiWiConfiguration;
import org.apache.marmotta.kiwi.test.PersistenceTest;
import org.junit.ClassRule;
@@ -37,6 +37,6 @@ public class HotRodPersistenceTest extends PersistenceTest {
kiwiConfig.setClusterAddress("127.0.0.1");
kiwiConfig.setClusterPort(61222);
- kiwiConfig.setCacheManager(CacheManagerType.INFINISPAN_HOTROD);
+ kiwiConfig.setCachingBackend(CachingBackends.INFINISPAN_HOTROD);
}
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/766bef0a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryConnectionTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryConnectionTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryConnectionTest.java
index 7890df0..b28c79b 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryConnectionTest.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryConnectionTest.java
@@ -17,7 +17,7 @@
package org.apache.marmotta.kiwi.test.remote;
-import org.apache.marmotta.kiwi.config.CacheManagerType;
+import org.apache.marmotta.kiwi.config.CachingBackends;
import org.apache.marmotta.kiwi.config.KiWiConfiguration;
import org.apache.marmotta.kiwi.sail.KiWiStore;
import org.apache.marmotta.kiwi.test.junit.KiWiDatabaseRunner;
@@ -47,8 +47,8 @@ public class HotRodRepositoryConnectionTest extends RepositoryConnectionTest {
config.setClusterAddress("127.0.0.1");
config.setClustered(true);
config.setClusterPort(61222);
- config.setClusterTimeout(10000);
- config.setCacheManager(CacheManagerType.INFINISPAN_HOTROD);
+ config.setClusterTimeout(1000);
+ config.setCachingBackend(CachingBackends.INFINISPAN_HOTROD);
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/766bef0a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryTest.java
index a026114..26ab7d6 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryTest.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryTest.java
@@ -17,7 +17,7 @@
package org.apache.marmotta.kiwi.test.remote;
-import org.apache.marmotta.kiwi.config.CacheManagerType;
+import org.apache.marmotta.kiwi.config.CachingBackends;
import org.apache.marmotta.kiwi.config.KiWiConfiguration;
import org.apache.marmotta.kiwi.sail.KiWiStore;
import org.apache.marmotta.kiwi.test.junit.KiWiDatabaseRunner;
@@ -49,7 +49,7 @@ public class HotRodRepositoryTest extends RepositoryTest {
config.setClustered(true);
config.setClusterPort(61222);
config.setClusterTimeout(10000);
- config.setCacheManager(CacheManagerType.INFINISPAN_HOTROD);
+ config.setCachingBackend(CachingBackends.INFINISPAN_HOTROD);
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/766bef0a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/CacheManagerType.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/CacheManagerType.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/CacheManagerType.java
deleted file mode 100644
index 783a79d..0000000
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/CacheManagerType.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.kiwi.config;
-
-/**
- * Add file description here!
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public enum CacheManagerType {
-
- /**
- * Simple in-memory cache backend using the Guava library; no clustering support
- */
- GUAVA("org.apache.marmotta.kiwi.caching.GuavaCacheManagerFactory"),
-
- /**
- * Cache backend based on Infinispan using a dynamic cluster setup (UDP multicast)
- */
- INFINISPAN_CLUSTERED("org.apache.marmotta.kiwi.infinispan.embedded.InfinispanEmbeddedCacheManagerFactory"),
-
- /**
- * Cache backend based on Infinispan using a client-server setup (Hotrod)
- */
- INFINISPAN_HOTROD("org.apache.marmotta.kiwi.infinispan.remote.InfinispanRemoteCacheManagerFactory"),
-
-
- /**
- * Cache backend based on Hazelcast using a dynamic cluster setup
- */
- HAZELCAST("org.apache.marmotta.kiwi.hazelcast.caching.HazelcastCacheManagerFactory");
-
-
- CacheManagerType(String factoryClass) {
- this.factoryClass = factoryClass;
- }
-
- private String factoryClass;
-
- public String getFactoryClass() {
- return factoryClass;
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/766bef0a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/CachingBackends.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/CachingBackends.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/CachingBackends.java
new file mode 100644
index 0000000..9698259
--- /dev/null
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/CachingBackends.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.config;
+
+/**
+ * Enumeration of the different caching backends currently supported
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public enum CachingBackends {
+
+ /**
+ * Simple in-memory cache backend using the Guava library; no clustering support
+ */
+ GUAVA("org.apache.marmotta.kiwi.caching.GuavaCacheManagerFactory"),
+
+ /**
+ * Cache backend based on Infinispan using a dynamic cluster setup (UDP multicast)
+ */
+ INFINISPAN_CLUSTERED("org.apache.marmotta.kiwi.infinispan.embedded.InfinispanEmbeddedCacheManagerFactory"),
+
+ /**
+ * Cache backend based on Infinispan using a client-server setup (Hotrod)
+ */
+ INFINISPAN_HOTROD("org.apache.marmotta.kiwi.infinispan.remote.InfinispanRemoteCacheManagerFactory"),
+
+
+ /**
+ * Cache backend based on Hazelcast using a dynamic cluster setup
+ */
+ HAZELCAST("org.apache.marmotta.kiwi.hazelcast.caching.HazelcastCacheManagerFactory");
+
+
+ CachingBackends(String factoryClass) {
+ this.factoryClass = factoryClass;
+ }
+
+ private String factoryClass;
+
+ public String getFactoryClass() {
+ return factoryClass;
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/766bef0a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java
index 6cf8ab4..0e1ce3f 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/config/KiWiConfiguration.java
@@ -95,7 +95,7 @@ public class KiWiConfiguration {
* Fully qualified class name of the cache manager factory to use. Falls back to the Guava
* cache manager if not found
*/
- private CacheManagerType cacheManager = CacheManagerType.GUAVA;
+ private CachingBackends cachingBackend = CachingBackends.GUAVA;
private int nodeCacheSize = 1000000;
@@ -306,16 +306,16 @@ public class KiWiConfiguration {
* Fully qualified class name of the cache manager factory to use. Falls back to the Guava
* cache manager if not found
*/
- public CacheManagerType getCacheManager() {
- return cacheManager;
+ public CachingBackends getCachingBackend() {
+ return cachingBackend;
}
/**
* Fully qualified class name of the cache manager factory to use. Falls back to the Guava
* cache manager if not found
*/
- public void setCacheManager(CacheManagerType cacheManager) {
- this.cacheManager = cacheManager;
+ public void setCachingBackend(CachingBackends cachingBackend) {
+ this.cachingBackend = cachingBackend;
}
/**
http://git-wip-us.apache.org/repos/asf/marmotta/blob/766bef0a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiPersistence.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiPersistence.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiPersistence.java
index 54e60a9..be4536e 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiPersistence.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/persistence/KiWiPersistence.java
@@ -131,10 +131,10 @@ public class KiWiPersistence {
private void initCachePool() {
try {
- Class factory = Class.forName(configuration.getCacheManager().getFactoryClass());
+ Class factory = Class.forName(configuration.getCachingBackend().getFactoryClass());
cacheManager = ((CacheManagerFactory)factory.newInstance()).createCacheManager(configuration);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
- log.warn("cache manager factory {} not found on classpath (error: {}); falling back to Guava in-memory cache backend!", configuration.getCacheManager(), e.getMessage());
+ log.warn("cache manager factory {} not found on classpath (error: {}); falling back to Guava in-memory cache backend!", configuration.getCachingBackend(), e.getMessage());
CacheManagerFactory factory = new GuavaCacheManagerFactory();
cacheManager = factory.createCacheManager(configuration);
http://git-wip-us.apache.org/repos/asf/marmotta/blob/766bef0a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/cluster/BaseClusterTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/cluster/BaseClusterTest.java b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/cluster/BaseClusterTest.java
index d5f7e16..939ba30 100644
--- a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/cluster/BaseClusterTest.java
+++ b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/cluster/BaseClusterTest.java
@@ -18,7 +18,7 @@
package org.apache.marmotta.kiwi.test.cluster;
import org.apache.marmotta.kiwi.caching.CacheManager;
-import org.apache.marmotta.kiwi.config.CacheManagerType;
+import org.apache.marmotta.kiwi.config.CachingBackends;
import org.apache.marmotta.kiwi.config.KiWiConfiguration;
import org.apache.marmotta.kiwi.model.rdf.KiWiAnonResource;
import org.apache.marmotta.kiwi.model.rdf.KiWiUriResource;
@@ -159,9 +159,9 @@ public abstract class BaseClusterTest {
protected static class ClusterTestSupport {
- CacheManagerType type;
+ CachingBackends type;
- public ClusterTestSupport(CacheManagerType type) {
+ public ClusterTestSupport(CachingBackends type) {
this.type = type;
}
@@ -205,7 +205,7 @@ public abstract class BaseClusterTest {
}
config.setDatacenterId(datacenterIds++);
config.setClustered(true);
- config.setCacheManager(type);
+ config.setCachingBackend(type);
config.setClusterPort(port);
KiWiStore store = new KiWiStore(config);
http://git-wip-us.apache.org/repos/asf/marmotta/blob/766bef0a/libraries/kiwi/pom.xml
----------------------------------------------------------------------
diff --git a/libraries/kiwi/pom.xml b/libraries/kiwi/pom.xml
index f47b8de..034464a 100644
--- a/libraries/kiwi/pom.xml
+++ b/libraries/kiwi/pom.xml
@@ -44,12 +44,12 @@
<configuration>
<systemPropertyVariables>
<!-- enable or pass on command line for testing local PostgreSQL -->
- <postgresql.url>jdbc:postgresql://localhost:5433/kiwitest?prepareThreshold=3</postgresql.url>
+ <postgresql.url>jdbc:postgresql://localhost:5433/kiwitest?prepareThreshold=3&socketTimeout=2</postgresql.url>
<postgresql.user>lmf</postgresql.user>
<postgresql.pass>lmf</postgresql.pass>
<!-- enable or pass on command line for testing local MySQL -->
- <mysql.url>jdbc:mysql://localhost:3306/kiwitest</mysql.url>
+ <mysql.url>jdbc:mysql://localhost:3306/kiwitest?socketTimeout=2000</mysql.url>
<mysql.user>lmf</mysql.user>
<mysql.pass>lmf</mysql.pass>
</systemPropertyVariables>
http://git-wip-us.apache.org/repos/asf/marmotta/blob/766bef0a/platform/backends/marmotta-backend-kiwi/src/main/java/org/apache/marmotta/platform/backend/kiwi/KiWiOptions.java
----------------------------------------------------------------------
diff --git a/platform/backends/marmotta-backend-kiwi/src/main/java/org/apache/marmotta/platform/backend/kiwi/KiWiOptions.java b/platform/backends/marmotta-backend-kiwi/src/main/java/org/apache/marmotta/platform/backend/kiwi/KiWiOptions.java
new file mode 100644
index 0000000..c9eff98
--- /dev/null
+++ b/platform/backends/marmotta-backend-kiwi/src/main/java/org/apache/marmotta/platform/backend/kiwi/KiWiOptions.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.platform.backend.kiwi;
+
+/**
+ * Class with static constants for configuration options.
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class KiWiOptions {
+ public static final String SPARQL_STRATEGY = "sparql.strategy";
+ public static final String DATACENTER_ID = "database.datacenter.id";
+ public static final String FULLTEXT_ENABLED = "database.fulltext.enabled";
+ public static final String FULLTEXT_LANGUAGES = "database.fulltext.languages";
+ public static final String DEBUG_SLOWQUERIES = "database.debug.slowqueries";
+ public static final String CLUSTERING_ENABLED = "clustering.enabled";
+ public static final String CACHING_LITERAL_SIZE = "caching.literal.size";
+ public static final String CACHING_BNODE_SIZE = "caching.bnode.size";
+ public static final String CACHING_URI_SIZE = "caching.uri.size";
+ public static final String CACHING_TRIPLE_SIZE = "caching.triple.size";
+ public static final String CLUSTERING_NAME = "clustering.name";
+ public static final String CACHING_QUERY_ENABLED = "caching.query.enabled";
+ public static final String CONTEXTS_DEFAULT = "contexts.default";
+ public static final String CONTEXTS_INFERRED = "contexts.inferred";
+ public static final String CLUSTERING_PORT = "clustering.port";
+ public static final String CLUSTERING_ADDRESS = "clustering.address";
+
+ public static final String DATABASE_URL = "database.url";
+ public static final String DATABASE_USER = "database.user";
+ public static final String DATABASE_PASSWORD = "database.password";
+
+ public static final String TRIPLES_BATCHCOMMIT = "database.triples.batchcommit";
+ public static final String TRIPLES_BATCHSIZE = "database.triples.batchsize";
+ public static final String CLUSTERING_BACKEND = "clustering.backend";
+ public static final String CLUSTERING_MODE = "clustering.mode";
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/766bef0a/platform/backends/marmotta-backend-kiwi/src/main/java/org/apache/marmotta/platform/backend/kiwi/KiWiStoreProvider.java
----------------------------------------------------------------------
diff --git a/platform/backends/marmotta-backend-kiwi/src/main/java/org/apache/marmotta/platform/backend/kiwi/KiWiStoreProvider.java b/platform/backends/marmotta-backend-kiwi/src/main/java/org/apache/marmotta/platform/backend/kiwi/KiWiStoreProvider.java
index 29cc2b0..2091b0e 100644
--- a/platform/backends/marmotta-backend-kiwi/src/main/java/org/apache/marmotta/platform/backend/kiwi/KiWiStoreProvider.java
+++ b/platform/backends/marmotta-backend-kiwi/src/main/java/org/apache/marmotta/platform/backend/kiwi/KiWiStoreProvider.java
@@ -18,6 +18,8 @@
package org.apache.marmotta.platform.backend.kiwi;
import com.google.common.collect.ImmutableList;
+import org.apache.marmotta.kiwi.config.CacheMode;
+import org.apache.marmotta.kiwi.config.CachingBackends;
import org.apache.marmotta.kiwi.config.KiWiConfiguration;
import org.apache.marmotta.kiwi.exception.DriverNotFoundException;
import org.apache.marmotta.kiwi.persistence.KiWiDialect;
@@ -30,7 +32,6 @@ import org.apache.marmotta.platform.core.api.config.ConfigurationService;
import org.apache.marmotta.platform.core.api.triplestore.SesameService;
import org.apache.marmotta.platform.core.api.triplestore.StoreProvider;
import org.apache.marmotta.platform.core.events.ConfigurationChangedEvent;
-import org.infinispan.manager.EmbeddedCacheManager;
import org.openrdf.repository.sail.SailRepository;
import org.openrdf.sail.NotifyingSail;
import org.openrdf.sail.Sail;
@@ -60,25 +61,6 @@ import javax.inject.Inject;
@ApplicationScoped
public class KiWiStoreProvider implements StoreProvider {
- public static final String SPARQL_STRATEGY = "sparql.strategy";
- public static final String DATACENTER_ID = "database.datacenter.id";
- public static final String FULLTEXT_ENABLED = "database.fulltext.enabled";
- public static final String FULLTEXT_LANGUAGES = "database.fulltext.languages";
- public static final String DEBUG_SLOWQUERIES = "database.debug.slowqueries";
- public static final String CLUSTERING_ENABLED = "clustering.enabled";
- public static final String CACHING_LITERAL_SIZE = "caching.literal.size";
- public static final String CACHING_BNODE_SIZE = "caching.bnode.size";
- public static final String CACHING_URI_SIZE = "caching.uri.size";
- public static final String CACHING_TRIPLE_SIZE = "caching.triple.size";
- public static final String CLUSTERING_NAME = "clustering.name";
- public static final String CACHING_QUERY_ENABLED = "caching.query.enabled";
- public static final String CACHING_QUERY_SIZE = "caching.query.size";
- public static final String CACHING_QUERY_LIMIT = "caching.query.limit";
- public static final String CONTEXTS_DEFAULT = "contexts.default";
- public static final String CONTEXTS_INFERRED = "contexts.inferred";
- public static final String CLUSTERING_PORT = "clustering.port";
- public static final String CLUSTERING_ADDRESS = "clustering.address";
-
@Inject
private Logger log;
@@ -89,9 +71,6 @@ public class KiWiStoreProvider implements StoreProvider {
private SesameService sesameService;
- @Inject
- private EmbeddedCacheManager cacheManager;
-
/**
* Create the store provided by this SailProvider
*
@@ -117,44 +96,37 @@ public class KiWiStoreProvider implements StoreProvider {
throw dnf;
}
- String jdbcUrl = configurationService.getStringConfiguration("database.url");
- String dbUser = configurationService.getStringConfiguration("database.user");
- String dbPass = configurationService.getStringConfiguration("database.password");
-
- KiWiConfiguration configuration = new KiWiConfiguration(configurationService.getStringConfiguration(CLUSTERING_NAME, "Marmotta") + " KiWi", jdbcUrl, dbUser, dbPass, dialect, configurationService.getDefaultContext(), configurationService.getInferredContext());
- configuration.setQueryLoggingEnabled(configurationService.getBooleanConfiguration(DEBUG_SLOWQUERIES, false));
- configuration.setTripleBatchCommit(configurationService.getBooleanConfiguration("database.triples.batchcommit", true));
- configuration.setTripleBatchSize(configurationService.getIntConfiguration("database.triples.batchsize", 10000));
-
- configuration.setDatacenterId(configurationService.getIntConfiguration(DATACENTER_ID,0));
- configuration.setFulltextEnabled(configurationService.getBooleanConfiguration(FULLTEXT_ENABLED, true));
- configuration.setFulltextLanguages(configurationService.getListConfiguration(FULLTEXT_LANGUAGES, ImmutableList.of("en")));
-
- configuration.setClustered(configurationService.getBooleanConfiguration(CLUSTERING_ENABLED, false));
- configuration.setClusterName(configurationService.getStringConfiguration(CLUSTERING_NAME, "Marmotta"));
-
- configuration.setLiteralCacheSize(configurationService.getIntConfiguration(CACHING_LITERAL_SIZE, 100000));
- configuration.setBNodeCacheSize(configurationService.getIntConfiguration(CACHING_BNODE_SIZE, 10000));
- configuration.setUriCacheSize(configurationService.getIntConfiguration(CACHING_URI_SIZE, 500000));
- configuration.setTripleCacheSize(configurationService.getIntConfiguration(CACHING_TRIPLE_SIZE, 100000));
-
- configuration.setClusterPort(configurationService.getIntConfiguration(CLUSTERING_PORT, 46655));
- configuration.setClusterAddress(configurationService.getStringConfiguration(CLUSTERING_ADDRESS, "228.6.7.8"));
-
- NotifyingSail base = new KiWiStore(configuration, cacheManager);
-
- /*
- if(configurationService.getBooleanConfiguration(CACHING_QUERY_ENABLED,true)) {
- log.info(" - enabling query caching support");
- KiWiQueryCacheConfiguration qcfg = new KiWiQueryCacheConfiguration();
- qcfg.setMaxCacheSize(configurationService.getIntConfiguration(CACHING_QUERY_SIZE, 100000));
- qcfg.setMaxEntrySize(configurationService.getIntConfiguration(CACHING_QUERY_LIMIT, 150));
- base = new KiWiCachingSail(base, qcfg);
- }
- */
+ String jdbcUrl = configurationService.getStringConfiguration(KiWiOptions.DATABASE_URL);
+ String dbUser = configurationService.getStringConfiguration(KiWiOptions.DATABASE_USER);
+ String dbPass = configurationService.getStringConfiguration(KiWiOptions.DATABASE_PASSWORD);
+
+ KiWiConfiguration configuration = new KiWiConfiguration(configurationService.getStringConfiguration(KiWiOptions.CLUSTERING_NAME, "Marmotta") + " KiWi", jdbcUrl, dbUser, dbPass, dialect, configurationService.getDefaultContext(), configurationService.getInferredContext());
+ configuration.setQueryLoggingEnabled(configurationService.getBooleanConfiguration(KiWiOptions.DEBUG_SLOWQUERIES, false));
+ configuration.setTripleBatchCommit(configurationService.getBooleanConfiguration(KiWiOptions.TRIPLES_BATCHCOMMIT, true));
+ configuration.setTripleBatchSize(configurationService.getIntConfiguration(KiWiOptions.TRIPLES_BATCHSIZE, 10000));
+
+ configuration.setDatacenterId(configurationService.getIntConfiguration(KiWiOptions.DATACENTER_ID,0));
+ configuration.setFulltextEnabled(configurationService.getBooleanConfiguration(KiWiOptions.FULLTEXT_ENABLED, true));
+ configuration.setFulltextLanguages(configurationService.getListConfiguration(KiWiOptions.FULLTEXT_LANGUAGES, ImmutableList.of("en")));
+
+ configuration.setClustered(configurationService.getBooleanConfiguration(KiWiOptions.CLUSTERING_ENABLED, false));
+ configuration.setClusterName(configurationService.getStringConfiguration(KiWiOptions.CLUSTERING_NAME, "Marmotta"));
+
+ configuration.setLiteralCacheSize(configurationService.getIntConfiguration(KiWiOptions.CACHING_LITERAL_SIZE, 100000));
+ configuration.setBNodeCacheSize(configurationService.getIntConfiguration(KiWiOptions.CACHING_BNODE_SIZE, 10000));
+ configuration.setUriCacheSize(configurationService.getIntConfiguration(KiWiOptions.CACHING_URI_SIZE, 500000));
+ configuration.setTripleCacheSize(configurationService.getIntConfiguration(KiWiOptions.CACHING_TRIPLE_SIZE, 100000));
+
+ configuration.setClusterPort(configurationService.getIntConfiguration(KiWiOptions.CLUSTERING_PORT, 46655));
+ configuration.setClusterAddress(configurationService.getStringConfiguration(KiWiOptions.CLUSTERING_ADDRESS, "228.6.7.8"));
+
+ configuration.setCachingBackend(CachingBackends.valueOf(configurationService.getStringConfiguration(KiWiOptions.CLUSTERING_BACKEND, "GUAVA")));
+ configuration.setCacheMode(CacheMode.valueOf(configurationService.getStringConfiguration(KiWiOptions.CLUSTERING_MODE,"LOCAL")));
+
+ NotifyingSail base = new KiWiStore(configuration);
- if("native".equalsIgnoreCase(configurationService.getStringConfiguration(SPARQL_STRATEGY))) {
+ if("native".equalsIgnoreCase(configurationService.getStringConfiguration(KiWiOptions.SPARQL_STRATEGY))) {
log.info(" - enabling native SPARQL support");
base = new KiWiSparqlSail(base);
}
@@ -196,19 +168,19 @@ public class KiWiStoreProvider implements StoreProvider {
public void configurationChanged(@Observes ConfigurationChangedEvent e) {
log.info("configuration changed: {}", e.getKeys());
- if(e.containsChangedKey(SPARQL_STRATEGY) ||
- e.containsChangedKey(DATACENTER_ID) ||
- e.containsChangedKey(CONTEXTS_DEFAULT) ||
- e.containsChangedKey(CONTEXTS_INFERRED) ||
- e.containsChangedKey(FULLTEXT_ENABLED) ||
- e.containsChangedKey(FULLTEXT_LANGUAGES) ||
- e.containsChangedKey(DEBUG_SLOWQUERIES) ||
- e.containsChangedKey(CLUSTERING_ENABLED) ||
- e.containsChangedKey(CACHING_LITERAL_SIZE) ||
- e.containsChangedKey(CACHING_TRIPLE_SIZE) ||
- e.containsChangedKey(CACHING_URI_SIZE) ||
- e.containsChangedKey(CACHING_BNODE_SIZE) ||
- e.containsChangedKey(CACHING_QUERY_ENABLED)
+ if(e.containsChangedKey(KiWiOptions.SPARQL_STRATEGY) ||
+ e.containsChangedKey(KiWiOptions.DATACENTER_ID) ||
+ e.containsChangedKey(KiWiOptions.CONTEXTS_DEFAULT) ||
+ e.containsChangedKey(KiWiOptions.CONTEXTS_INFERRED) ||
+ e.containsChangedKey(KiWiOptions.FULLTEXT_ENABLED) ||
+ e.containsChangedKey(KiWiOptions.FULLTEXT_LANGUAGES) ||
+ e.containsChangedKey(KiWiOptions.DEBUG_SLOWQUERIES) ||
+ e.containsChangedKey(KiWiOptions.CLUSTERING_ENABLED) ||
+ e.containsChangedKey(KiWiOptions.CACHING_LITERAL_SIZE) ||
+ e.containsChangedKey(KiWiOptions.CACHING_TRIPLE_SIZE) ||
+ e.containsChangedKey(KiWiOptions.CACHING_URI_SIZE) ||
+ e.containsChangedKey(KiWiOptions.CACHING_BNODE_SIZE) ||
+ e.containsChangedKey(KiWiOptions.CACHING_QUERY_ENABLED)
) {
log.info("KiWi backend configuration changed, re-initialising triple store");
http://git-wip-us.apache.org/repos/asf/marmotta/blob/766bef0a/platform/backends/marmotta-backend-kiwi/src/main/resources/config-defaults.properties
----------------------------------------------------------------------
diff --git a/platform/backends/marmotta-backend-kiwi/src/main/resources/config-defaults.properties b/platform/backends/marmotta-backend-kiwi/src/main/resources/config-defaults.properties
index 7fdbb11..0e33673 100644
--- a/platform/backends/marmotta-backend-kiwi/src/main/resources/config-defaults.properties
+++ b/platform/backends/marmotta-backend-kiwi/src/main/resources/config-defaults.properties
@@ -74,10 +74,12 @@ caching.uri.size = 500000
caching.bnode.size = 10000
caching.triple.size = 100000
-caching.query.enabled = true
-caching.query.limit = 150
-caching.query.size = 100000
-
-
+# Turn on cluster-specific configuration options (e.g. replicated and distributed caching, synchronization, ...)
+clustering.enabled = false
+clustering.name = Marmotta
+clustering.mode = REPLICATED
+clustering.address = 228.6.7.8
+clustering.port = 46655
+clustering.backend = GUAVA
http://git-wip-us.apache.org/repos/asf/marmotta/blob/766bef0a/platform/backends/marmotta-backend-kiwi/src/main/resources/config-descriptions.properties
----------------------------------------------------------------------
diff --git a/platform/backends/marmotta-backend-kiwi/src/main/resources/config-descriptions.properties b/platform/backends/marmotta-backend-kiwi/src/main/resources/config-descriptions.properties
index b2394e9..3cb207b 100644
--- a/platform/backends/marmotta-backend-kiwi/src/main/resources/config-descriptions.properties
+++ b/platform/backends/marmotta-backend-kiwi/src/main/resources/config-descriptions.properties
@@ -64,10 +64,29 @@ caching.bnode.size.type = java.lang.Integer(10|0|*)
caching.triple.size.description = size of triple lookup cache
caching.triple.size.type = java.lang.Integer(10|0|*)
-caching.query.enabled.description = enable query caching (performance improvement but requires more memory)
-caching.query.enabled.type = java.lang.Boolean
-caching.query.size.description = size of query cache
-caching.query.size.type = java.lang.Integer(10|0|*)
-caching.query.limit.description = maximum result size to cache
-caching.query.limit.type = java.lang.Integer(10|0|*)
+clustering.enabled.description = Turn on cluster-specific configuration options (e.g. replicated and distributed caching, synchronization, ...)
+clustering.enabled.type = java.lang.Boolean
+
+clustering.name.description = Cluster name to use in cluster configuration (e.g. cache cluster name)
+clustering.name.type = java.lang.String
+
+clustering.mode.description = Set the cache mode for the KiWi triple store. The following cluster modes are available: \
+ LOCAL: In local cache mode, the cache is not shared among the servers in a cluster. Each machine keeps a local cache. \
+ This allows quick startups and eliminates network traffic in the cluster, but subsequent requests to different \
+ cluster members cannot benefit from the cached data. \
+ DISTRIBUTED: In distributed cache mode, the cluster forms a big hash table used as a cache. This allows to make efficient \
+ use of the large amount of memory available, but requires cache rebalancing and a lot of network transfers, \
+ especially in case cluster members are restarted often. \
+ REPLICATED: In replicated cache mode, each node in the cluster has an identical copy of all cache data. This allows \
+ very efficient cache lookups and reduces the rebalancing effort, but requires more memory.
+clustering.mode.type = java.lang.Enum("LOCAL"|"DISTRIBUTED"|"REPLICATED")
+
+clustering.address.description = Set the address used for sending UDP multicast packages in the cluster or the name of the remote server
+clustering.address.type = java.lang.String
+
+clustering.port.description = Set the port used for sending UDP multicast packages in the cluster or the port on the remote server
+clustering.port.type = java.lang.Integer(1|1024|65535)
+
+clustering.backend.description = Caching backend used by KiWi (either Guava, Infinispan Cluster, Infinispan Hotrod, Hazelcast or EHCache)
+clustering.backend.type = java.lang.enum("GUAVA","INFINISPAN_CLUSTER","INFINISPAN_HOTROD", "HAZELCAST", "EHCACHE")
http://git-wip-us.apache.org/repos/asf/marmotta/blob/766bef0a/platform/marmotta-core/pom.xml
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/pom.xml b/platform/marmotta-core/pom.xml
index 3c2bb95..85030fe 100644
--- a/platform/marmotta-core/pom.xml
+++ b/platform/marmotta-core/pom.xml
@@ -335,17 +335,6 @@
<artifactId>marmotta-client-js</artifactId>
</dependency>
- <!-- Persistence -->
- <dependency>
- <groupId>org.infinispan</groupId>
- <artifactId>infinispan-core</artifactId>
- </dependency>
- <!-- TODO: we still use our own CDI implementation here...
- <dependency>
- <groupId>org.infinispan</groupId>
- <artifactId>infinispan-cdi</artifactId>
- </dependency>
- -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
http://git-wip-us.apache.org/repos/asf/marmotta/blob/766bef0a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/api/cache/CachingService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/api/cache/CachingService.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/api/cache/CachingService.java
index 00cb18f..e405d0c 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/api/cache/CachingService.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/api/cache/CachingService.java
@@ -17,28 +17,44 @@
*/
package org.apache.marmotta.platform.core.api.cache;
-import org.infinispan.Cache;
-import org.infinispan.manager.EmbeddedCacheManager;
-
import javax.enterprise.inject.spi.InjectionPoint;
import java.util.Set;
+import java.util.concurrent.ConcurrentMap;
/**
- * Add file description here!
+ * Simple caching functionality for the Marmotta Platform modules. Note that the KiWi triplestore (and other
+ * triple stores) come with their own custom caching implementations.
* <p/>
* User: sschaffe
*/
public interface CachingService {
+ /**
+ * Inject a cache at the given injection point. Creates a new cache if needed.
+ *
+ * @param injectionPoint
+ * @return
+ */
+ public ConcurrentMap getCache(InjectionPoint injectionPoint);
- public Cache getCache(InjectionPoint injectionPoint);
-
+ /**
+ * Return the names of all caches registered in the caching service
+ * @return
+ */
public Set<String> getCacheNames();
+ /**
+ * Clear all caches registered in the caching service
+ */
public void clearAll();
- public Cache getCacheByName(String cacheName);
+ /**
+ * Get the cache with the given name. Creates a new cache if needed.
+ *
+ * @param cacheName
+ * @return
+ */
+ public ConcurrentMap getCacheByName(String cacheName);
- public EmbeddedCacheManager getCacheManager();
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/766bef0a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/model/config/CoreOptions.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/model/config/CoreOptions.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/model/config/CoreOptions.java
new file mode 100644
index 0000000..38c7a2b
--- /dev/null
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/model/config/CoreOptions.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.platform.core.model.config;
+
+/**
+ * Class with static constants for configuration options
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class CoreOptions {
+ public static final String BASE_URI = "kiwi.context";
+ public static final String SERVER_URI = "kiwi.host";
+
+ public static final String CACHING_EXPIRATION = "caching.expiration";
+ public static final String CACHING_MAXIMUM_SIZE = "caching.maximum_size";
+
+ // HTTP connection service
+ public static final String HTTP_MAX_CONNECTIONS = "core.http.max_connections";
+ public static final String HTTP_MAX_CONNECTIONS_PER_ROUTE = "core.http.max_connections_per_route";
+ public static final String HTTP_CLIENT_CACHE_ENABLE = "core.http.client_cache_enable";
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/766bef0a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/cache/CachingServiceImpl.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/cache/CachingServiceImpl.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/cache/CachingServiceImpl.java
index f53cdc6..3498e69 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/cache/CachingServiceImpl.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/cache/CachingServiceImpl.java
@@ -17,23 +17,13 @@
*/
package org.apache.marmotta.platform.core.services.cache;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang3.StringUtils;
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
import org.apache.marmotta.platform.core.api.cache.CachingService;
import org.apache.marmotta.platform.core.api.config.ConfigurationService;
import org.apache.marmotta.platform.core.events.SystemRestartingEvent;
+import org.apache.marmotta.platform.core.model.config.CoreOptions;
import org.apache.marmotta.platform.core.qualifiers.cache.MarmottaCache;
-import org.infinispan.Cache;
-import org.infinispan.configuration.cache.CacheMode;
-import org.infinispan.configuration.cache.Configuration;
-import org.infinispan.configuration.cache.ConfigurationBuilder;
-import org.infinispan.configuration.global.GlobalConfiguration;
-import org.infinispan.configuration.global.GlobalConfigurationBuilder;
-import org.infinispan.distribution.ch.SyncConsistentHashFactory;
-import org.infinispan.eviction.EvictionStrategy;
-import org.infinispan.lifecycle.ComponentStatus;
-import org.infinispan.manager.DefaultCacheManager;
-import org.infinispan.manager.EmbeddedCacheManager;
import org.slf4j.Logger;
import javax.annotation.PostConstruct;
@@ -43,9 +33,10 @@ import javax.enterprise.event.Observes;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.inject.Inject;
-import java.io.IOException;
-import java.util.Iterator;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Set;
+import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
/**
@@ -56,11 +47,6 @@ import java.util.concurrent.TimeUnit;
@ApplicationScoped
public class CachingServiceImpl implements CachingService {
- public static final String CLUSTERING_PORT = "clustering.port";
- public static final String CLUSTERING_ADDRESS = "clustering.address";
- public static final String CLUSTERING_ENABLED = "clustering.enabled";
- public static final String CLUSTERING_MODE = "clustering.mode";
-
/**
* Get the seam logger for issuing logging statements.
*/
@@ -70,12 +56,8 @@ public class CachingServiceImpl implements CachingService {
@Inject
private ConfigurationService configurationService;
- private EmbeddedCacheManager cacheManager;
-
- private GlobalConfiguration globalConfiguration;
- // default configuration: distributed cache, 100000 entries, 300 seconds expiration, 60 seconds idle
- private Configuration defaultConfiguration;
+ private Map<String,Cache> caches;
public CachingServiceImpl() {
@@ -84,158 +66,53 @@ public class CachingServiceImpl implements CachingService {
@PostConstruct
public void initialize() {
- boolean clustered = configurationService.getBooleanConfiguration(CLUSTERING_ENABLED, false);
- String cacheMode = configurationService.getStringConfiguration(CLUSTERING_MODE,"replicated");
-
-
- log.info("Apache Marmotta Caching Service starting up ({}) ...", clustered ? "cluster name: " + configurationService.getStringConfiguration("clustering.name", "Marmotta") : "single host" );
- if(clustered && (StringUtils.equalsIgnoreCase(cacheMode,"replicated") || StringUtils.equalsIgnoreCase(cacheMode, "distributed"))) {
-
- try {
- String jgroupsXml = IOUtils.toString(CachingService.class.getResourceAsStream("/jgroups-marmotta.xml"));
-
- jgroupsXml = jgroupsXml.replaceAll("mcast_addr=\"[0-9.]+\"", String.format("mcast_addr=\"%s\"", configurationService.getStringConfiguration(CLUSTERING_ADDRESS, "228.6.7.8")));
- jgroupsXml = jgroupsXml.replaceAll("mcast_port=\"[0-9]+\"", String.format("mcast_port=\"%d\"", configurationService.getIntConfiguration(CLUSTERING_PORT, 46655)));
-
- globalConfiguration = new GlobalConfigurationBuilder()
- .transport()
- .defaultTransport()
- .clusterName(configurationService.getStringConfiguration("clustering.name", "Marmotta"))
- .machineId(configurationService.getServerName())
- .addProperty("configurationXml", jgroupsXml)
- .globalJmxStatistics()
- .jmxDomain("org.apache.marmotta.platform")
- .allowDuplicateDomains(true)
- .build();
- } catch (IOException ex) {
- log.warn("error loading JGroups configuration from archive: {}", ex.getMessage());
- log.warn("some configuration options will not be available");
-
- globalConfiguration = new GlobalConfigurationBuilder()
- .transport()
- .defaultTransport()
- .clusterName(configurationService.getStringConfiguration("clustering.name", "Marmotta"))
- .machineId(configurationService.getServerName())
- .addProperty("configurationFile", "jgroups-marmotta.xml")
- .globalJmxStatistics()
- .jmxDomain("org.apache.marmotta.platform")
- .allowDuplicateDomains(true)
- .build();
- }
-
-
- if(StringUtils.equalsIgnoreCase(cacheMode, "distributed")) {
- defaultConfiguration = new ConfigurationBuilder()
- .clustering()
- .cacheMode(CacheMode.DIST_ASYNC)
- .async()
- .asyncMarshalling()
- .l1()
- .lifespan(5, TimeUnit.MINUTES)
- .hash()
- .numOwners(2)
- .numSegments(40)
- .consistentHashFactory(new SyncConsistentHashFactory())
- .stateTransfer()
- .fetchInMemoryState(false)
- .eviction()
- .strategy(EvictionStrategy.LIRS)
- .maxEntries(100000)
- .expiration()
- .lifespan(30, TimeUnit.MINUTES)
- .maxIdle(10, TimeUnit.MINUTES)
- .build();
- } else {
- defaultConfiguration = new ConfigurationBuilder()
- .clustering()
- .cacheMode(CacheMode.REPL_ASYNC)
- .async()
- .asyncMarshalling()
- .stateTransfer()
- .fetchInMemoryState(false)
- .eviction()
- .strategy(EvictionStrategy.LIRS)
- .maxEntries(100000)
- .expiration()
- .lifespan(30, TimeUnit.MINUTES)
- .maxIdle(10, TimeUnit.MINUTES)
- .build();
- }
- } else {
- globalConfiguration = new GlobalConfigurationBuilder()
- .globalJmxStatistics()
- .jmxDomain("org.apache.marmotta.platform")
- .allowDuplicateDomains(true)
- .build();
-
- defaultConfiguration = new ConfigurationBuilder()
- .clustering()
- .cacheMode(CacheMode.LOCAL)
- .eviction()
- .strategy(EvictionStrategy.LIRS)
- .maxEntries(100000)
- .expiration()
- .lifespan(5, TimeUnit.MINUTES)
- .maxIdle(1, TimeUnit.MINUTES)
- .build();
-
- }
-
-
- cacheManager = new DefaultCacheManager(globalConfiguration, defaultConfiguration, true);
-
- log.info("initialised cache manager ({})", globalConfiguration.isClustered() ? "cluster name: "+globalConfiguration.transport().clusterName() : "single host");
+ caches = new HashMap<>();
}
/**
* Return the cache with the name provided to the KiWiCache annotation of the injection.
- *
- *
+ *
+ *
* Usage: <code><pre>
* @Inject @KiWiCache("cache-name")
* private Ehcache cache;
* </pre></code>
- *
- *
+ *
+ *
* @param injectionPoint
* @return
*/
@Override
@Produces @MarmottaCache("")
- public Cache getCache(InjectionPoint injectionPoint) {
+ public ConcurrentMap getCache(InjectionPoint injectionPoint) {
String cacheName = injectionPoint.getAnnotated().getAnnotation(MarmottaCache.class).value();
return getCacheByName(cacheName);
}
- /**
- * Allow CDI injection of the default cache
- * @return
- */
- @Produces
- public Configuration getDefaultConfiguration() {
- return defaultConfiguration;
- }
-
@Override
- public Cache getCacheByName(String cacheName) {
- return cacheManager.getCache(cacheName, true);
+ public ConcurrentMap getCacheByName(String cacheName) {
+ synchronized (caches) {
+ if(!caches.containsKey(cacheName)) {
+ Cache c = CacheBuilder.newBuilder()
+ .expireAfterAccess(configurationService.getIntConfiguration(CoreOptions.CACHING_EXPIRATION,30), TimeUnit.MINUTES)
+ .maximumSize(configurationService.getLongConfiguration(CoreOptions.CACHING_MAXIMUM_SIZE,10000L))
+ .build();
+ caches.put(cacheName,c);
+ }
+ }
+
+ return caches.get(cacheName).asMap();
}
@Override
public Set<String> getCacheNames() {
- return cacheManager.getCacheNames();
+ return caches.keySet();
}
- @Override
- @Produces
- @ApplicationScoped
- public EmbeddedCacheManager getCacheManager() {
- return cacheManager;
- }
/**
@@ -244,31 +121,20 @@ public class CachingServiceImpl implements CachingService {
*/
public void systemRestart(@Observes SystemRestartingEvent e) {
log.warn("system restarted, flushing caches ...");
- cacheManager.stop();
- cacheManager.start();
+ caches.clear();
}
@Override
public void clearAll() {
- Set<String> set = cacheManager.getCacheNames();
- Iterator<String> iterator = set.iterator();
- while(iterator.hasNext()){
- String cacheName = iterator.next();
- Cache<String,Object> cache = cacheManager.getCache(cacheName);
- cache.clear();
- }
+ caches.clear();
}
@PreDestroy
public void destroy() {
log.info("Apache Marmotta Caching Service shutting down ...");
- if(cacheManager.getStatus() == ComponentStatus.RUNNING) {
- log.info("- shutting down Infinispan cache manager ...");
- cacheManager.stop();
- log.info(" ... success!");
- }
+ caches.clear();
log.info("Apache Marmotta Caching Service shut down successfully.");
}
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/766bef0a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/config/ConfigurationServiceImpl.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/config/ConfigurationServiceImpl.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/config/ConfigurationServiceImpl.java
index 152ebbf..416d9c4 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/config/ConfigurationServiceImpl.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/config/ConfigurationServiceImpl.java
@@ -17,6 +17,29 @@
*/
package org.apache.marmotta.platform.core.services.config;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import org.apache.commons.configuration.*;
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.marmotta.platform.core.api.config.ConfigurationService;
+import org.apache.marmotta.platform.core.events.ConfigurationChangedEvent;
+import org.apache.marmotta.platform.core.events.ConfigurationServiceInitEvent;
+import org.apache.marmotta.platform.core.events.LoggingStartEvent;
+import org.apache.marmotta.platform.core.model.config.CoreOptions;
+import org.apache.marmotta.platform.core.util.FallbackConfiguration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.PreDestroy;
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Event;
+import javax.enterprise.inject.Any;
+import javax.inject.Inject;
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.ObjectName;
+import javax.servlet.ServletContext;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Array;
@@ -26,53 +49,13 @@ import java.nio.file.AtomicMoveNotSupportedException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-import java.util.Timer;
-import java.util.TimerTask;
+import java.util.*;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import javax.annotation.PreDestroy;
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.event.Event;
-import javax.enterprise.inject.Any;
-import javax.inject.Inject;
-import javax.management.MBeanServer;
-import javax.management.MBeanServerFactory;
-import javax.management.ObjectName;
-import javax.servlet.ServletContext;
-
-import org.apache.commons.configuration.AbstractConfiguration;
-import org.apache.commons.configuration.CompositeConfiguration;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.MapConfiguration;
-import org.apache.commons.configuration.PropertiesConfiguration;
-import org.apache.commons.lang3.ObjectUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.marmotta.platform.core.api.config.ConfigurationService;
-import org.apache.marmotta.platform.core.events.ConfigurationChangedEvent;
-import org.apache.marmotta.platform.core.events.ConfigurationServiceInitEvent;
-import org.apache.marmotta.platform.core.events.LoggingStartEvent;
-import org.apache.marmotta.platform.core.util.FallbackConfiguration;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
-
/**
* This service offers access to the system configuration of the LMF and takes care of initialising the system
* properly on startup.
@@ -417,7 +400,7 @@ public class ConfigurationServiceImpl implements ConfigurationService {
@Override
public String getBaseUri() {
- return getStringConfiguration("kiwi.context");
+ return getStringConfiguration(CoreOptions.BASE_URI);
}
/**
@@ -440,7 +423,7 @@ public class ConfigurationServiceImpl implements ConfigurationService {
*/
@Override
public String getServerUri() {
- String serverUrl = getStringConfiguration("kiwi.host");
+ String serverUrl = getStringConfiguration(CoreOptions.SERVER_URI);
if (serverUrl.endsWith("/"))
return serverUrl;
http://git-wip-us.apache.org/repos/asf/marmotta/blob/766bef0a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/http/HttpClientServiceImpl.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/http/HttpClientServiceImpl.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/http/HttpClientServiceImpl.java
index 7d27576..94258f3 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/http/HttpClientServiceImpl.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/http/HttpClientServiceImpl.java
@@ -50,11 +50,11 @@ import org.apache.marmotta.platform.core.api.statistics.StatisticsService;
import org.apache.marmotta.platform.core.api.task.Task;
import org.apache.marmotta.platform.core.api.task.TaskManagerService;
import org.apache.marmotta.platform.core.events.ConfigurationChangedEvent;
+import org.apache.marmotta.platform.core.model.config.CoreOptions;
import org.apache.marmotta.platform.core.qualifiers.cache.MarmottaCache;
import org.apache.marmotta.platform.core.services.http.response.LastModifiedResponseHandler;
import org.apache.marmotta.platform.core.services.http.response.StatusCodeResponseHandler;
import org.apache.marmotta.platform.core.services.http.response.StringBodyResponseHandler;
-import org.infinispan.Cache;
import org.slf4j.Logger;
import javax.annotation.PostConstruct;
@@ -68,6 +68,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.*;
+import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.ReentrantReadWriteLock;
@@ -101,7 +102,7 @@ public class HttpClientServiceImpl implements HttpClientService {
@Inject
@MarmottaCache("http-client-cache")
- private Cache httpCache;
+ private ConcurrentMap httpCache;
private HttpClient httpClient;
private IdleConnectionMonitorThread idleConnectionMonitorThread;
@@ -293,8 +294,8 @@ public class HttpClientServiceImpl implements HttpClientService {
schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));
PoolingClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry);
- cm.setMaxTotal(configurationService.getIntConfiguration("core.http.max_connections", 20));
- cm.setDefaultMaxPerRoute(configurationService.getIntConfiguration("core.http.max_connections_per_route", 10));
+ cm.setMaxTotal(configurationService.getIntConfiguration(CoreOptions.HTTP_MAX_CONNECTIONS, 20));
+ cm.setDefaultMaxPerRoute(configurationService.getIntConfiguration(CoreOptions.HTTP_MAX_CONNECTIONS_PER_ROUTE, 10));
final DefaultHttpClient hc = new DefaultHttpClient(cm, httpParams);
hc.setRedirectStrategy(new LMFRedirectStrategy());
@@ -302,13 +303,13 @@ public class HttpClientServiceImpl implements HttpClientService {
hc.removeRequestInterceptorByClass(org.apache.http.protocol.RequestUserAgent.class);
hc.addRequestInterceptor(new LMFRequestUserAgent(userAgentString));
- if (configurationService.getBooleanConfiguration("core.http.client_cache_enable", true)) {
+ if (configurationService.getBooleanConfiguration(CoreOptions.HTTP_CLIENT_CACHE_ENABLE, true)) {
CacheConfig cacheConfig = new CacheConfig();
// FIXME: Hardcoded constants - is this useful?
cacheConfig.setMaxCacheEntries(1000);
cacheConfig.setMaxObjectSize(81920);
- final HttpCacheStorage cacheStore = new InfinispanHttpCacheStorage(httpCache);
+ final HttpCacheStorage cacheStore = new MapHttpCacheStorage(httpCache);
this.httpClient = new MonitoredHttpClient(new CachingHttpClient(hc, cacheStore, cacheConfig));
} else {
@@ -809,14 +810,14 @@ public class HttpClientServiceImpl implements HttpClientService {
- private static class InfinispanHttpCacheStorage implements HttpCacheStorage {
+ private static class MapHttpCacheStorage implements HttpCacheStorage {
- Cache<String, byte[]> cache;
+ ConcurrentMap<String, byte[]> cache;
private final HttpCacheEntrySerializer serializer;
- private InfinispanHttpCacheStorage(Cache<String, byte[]> cache) {
+ private MapHttpCacheStorage(ConcurrentMap<String, byte[]> cache) {
this.cache = cache;
this.serializer = new DefaultHttpCacheEntrySerializer();
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/766bef0a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/modules/MarmottaResourceServiceImpl.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/modules/MarmottaResourceServiceImpl.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/modules/MarmottaResourceServiceImpl.java
index 0b837e1..480f541 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/modules/MarmottaResourceServiceImpl.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/modules/MarmottaResourceServiceImpl.java
@@ -27,7 +27,6 @@ import org.apache.marmotta.platform.core.api.modules.ResourceEntry;
import org.apache.marmotta.platform.core.events.SystemStartupEvent;
import org.apache.marmotta.platform.core.model.module.ModuleConfiguration;
import org.apache.marmotta.platform.core.qualifiers.cache.MarmottaCache;
-import org.infinispan.Cache;
import org.slf4j.Logger;
import javax.annotation.PostConstruct;
@@ -39,6 +38,7 @@ import java.net.URL;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.ConcurrentMap;
/**
* A service for resolving and accessing resources contained in the Apache Marmotta modules. The resource service takes care
@@ -64,7 +64,7 @@ public class MarmottaResourceServiceImpl implements MarmottaResourceService {
@Inject @MarmottaCache("resource-cache")
- private Cache resourceCache;
+ private ConcurrentMap resourceCache;
/**
* Used for detecting the mime type of resources contained in KiWi modules
http://git-wip-us.apache.org/repos/asf/marmotta/blob/766bef0a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/startup/MarmottaStartupService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/startup/MarmottaStartupService.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/startup/MarmottaStartupService.java
index 07bc0cc..6929501 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/startup/MarmottaStartupService.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/startup/MarmottaStartupService.java
@@ -17,18 +17,8 @@
*/
package org.apache.marmotta.platform.core.startup;
-import java.io.File;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.locks.ReentrantLock;
-
-import javax.annotation.PostConstruct;
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.event.Event;
-import javax.enterprise.inject.Any;
-import javax.inject.Inject;
-import javax.servlet.ServletContext;
-
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.lang3.StringUtils;
import org.apache.marmotta.platform.core.api.config.ConfigurationService;
import org.apache.marmotta.platform.core.api.modules.ModuleService;
import org.apache.marmotta.platform.core.api.triplestore.SesameService;
@@ -36,14 +26,23 @@ import org.apache.marmotta.platform.core.api.ui.MarmottaSystrayLink;
import org.apache.marmotta.platform.core.api.user.UserService;
import org.apache.marmotta.platform.core.events.SesameStartupEvent;
import org.apache.marmotta.platform.core.events.SystemStartupEvent;
+import org.apache.marmotta.platform.core.model.config.CoreOptions;
import org.apache.marmotta.platform.core.model.module.ModuleConfiguration;
import org.apache.marmotta.platform.core.util.CDIContext;
-
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Event;
+import javax.enterprise.inject.Any;
+import javax.inject.Inject;
+import javax.servlet.ServletContext;
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.locks.ReentrantLock;
+
/**
* This service unifies the different steps in the Apache Marmotta startup. It offers several methods
* for triggering the different startup sequences and can be used e.g. by web applications or
@@ -231,8 +230,8 @@ public class MarmottaStartupService {
if(!isSetup) {
log.info("SETUP: Setting up initial host and resource configuration ({}) ...", hostUrl);
- configurationService.setConfiguration("kiwi.context", contextUrl);
- configurationService.setConfiguration("kiwi.host", hostUrl);
+ configurationService.setConfiguration(CoreOptions.BASE_URI, contextUrl);
+ configurationService.setConfiguration(CoreOptions.SERVER_URI, hostUrl);
configurationService.setConfiguration("kiwi.setup.host", true);
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/766bef0a/platform/marmotta-core/src/main/resources/config-defaults.properties
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/resources/config-defaults.properties b/platform/marmotta-core/src/main/resources/config-defaults.properties
index 4ac724d..a6cbad2 100644
--- a/platform/marmotta-core/src/main/resources/config-defaults.properties
+++ b/platform/marmotta-core/src/main/resources/config-defaults.properties
@@ -199,13 +199,9 @@ contexts.inferred = ${kiwi.context}context/inferred
###############################################################################
-# Clustering Configuration
+# Clustering/Caching Configuration
###############################################################################
+caching.maximum_size = 10000
+caching.expiration = 30
-# Turn on cluster-specific configuration options (e.g. replicated and distributed caching, synchronization, ...)
-clustering.enabled = false
-clustering.name = Marmotta
-clustering.mode = REPLICATED
-clustering.address = 228.6.7.8
-clustering.port = 46655
http://git-wip-us.apache.org/repos/asf/marmotta/blob/766bef0a/platform/marmotta-core/src/main/resources/config-descriptions.properties
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/resources/config-descriptions.properties b/platform/marmotta-core/src/main/resources/config-descriptions.properties
index 0599619..b9ffa57 100644
--- a/platform/marmotta-core/src/main/resources/config-descriptions.properties
+++ b/platform/marmotta-core/src/main/resources/config-descriptions.properties
@@ -160,30 +160,13 @@ statistics.enabled.type = java.lang.Boolean
-clustering.enabled.description = Turn on cluster-specific configuration options (e.g. replicated and distributed caching, synchronization, ...)
-clustering.enabled.type = java.lang.Boolean
-
-clustering.name.description = Cluster name to use in cluster configuration (e.g. cache cluster name)
-clustering.name.type = java.lang.String
-
-clustering.mode.description = Set the cache mode for this KiWi triple store. The following cluster modes are available: \
- LOCAL: In local cache mode, the cache is not shared among the servers in a cluster. Each machine keeps a local cache. \
- This allows quick startups and eliminates network traffic in the cluster, but subsequent requests to different \
- cluster members cannot benefit from the cached data. \
- DISTRIBUTED: In distributed cache mode, the cluster forms a big hash table used as a cache. This allows to make efficient \
- use of the large amount of memory available, but requires cache rebalancing and a lot of network transfers, \
- especially in case cluster members are restarted often. \
- REPLICATED: In replicated cache mode, each node in the cluster has an identical copy of all cache data. This allows \
- very efficient cache lookups and reduces the rebalancing effort, but requires more memory.
-clustering.mode.type = java.lang.Enum("LOCAL"|"DISTRIBUTED"|"REPLICATED")
-
-clustering.address.description = Set the address used for sending UDP multicast packages in the cluster
-clustering.address.type = java.lang.String
-
-clustering.port.description = Set the port used for sending UDP multicast packages in the cluster
-clustering.port.type = java.lang.Integer(1|1024|65535)
-
contexts.default.description = Default context to use for triples in case no explicit context selected (may be empty)
contexts.default.type = java.lang.String
contexts.inferred.description = Context to use for storing triples inferred automatically be the reasoner (may not be empty)
contexts.inferred.type = java.lang.String
+
+
+caching.maximum_size.description = Maximum number of entries for in-memory caches used by the Marmotta Platform
+caching.maximum_size.type = java.lang.Integer(1|1000|10000000)
+caching.expiration.description = Maximum minutes of inactivity before a cache entry expires from the in-memory caches
+caching.expiration.type = java.lang.Integer(1|5|1440)
http://git-wip-us.apache.org/repos/asf/marmotta/blob/766bef0a/platform/marmotta-user/src/main/java/org/apache/marmotta/platform/user/services/AccountServiceImpl.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-user/src/main/java/org/apache/marmotta/platform/user/services/AccountServiceImpl.java b/platform/marmotta-user/src/main/java/org/apache/marmotta/platform/user/services/AccountServiceImpl.java
index 90b502e..1cd0128 100644
--- a/platform/marmotta-user/src/main/java/org/apache/marmotta/platform/user/services/AccountServiceImpl.java
+++ b/platform/marmotta-user/src/main/java/org/apache/marmotta/platform/user/services/AccountServiceImpl.java
@@ -30,7 +30,6 @@ import org.apache.marmotta.platform.core.qualifiers.cache.MarmottaCache;
import org.apache.marmotta.platform.user.api.AccountService;
import org.apache.marmotta.platform.user.model.UserAccount;
import org.apache.marmotta.platform.user.model.UserAccount.PasswordHash;
-import org.infinispan.Cache;
import org.openrdf.model.Resource;
import org.openrdf.model.URI;
import org.slf4j.Logger;
@@ -43,6 +42,7 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import java.util.concurrent.ConcurrentMap;
@ApplicationScoped
public class AccountServiceImpl implements AccountService {
@@ -58,7 +58,7 @@ public class AccountServiceImpl implements AccountService {
@Inject
@MarmottaCache("user-cache")
- private Cache userCache;
+ private ConcurrentMap userCache;
private PasswordHash hashAlgo;
[14/21] git commit: started working on remote cluster test
Posted by ss...@apache.org.
started working on remote cluster test
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/1497768a
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/1497768a
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/1497768a
Branch: refs/heads/MARMOTTA-450
Commit: 1497768a27506d6d5cd0aec0b0754b055a7f8e8d
Parents: 89763d1
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Tue Mar 4 19:13:17 2014 +0100
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Tue Mar 4 19:13:17 2014 +0100
----------------------------------------------------------------------
libraries/kiwi/kiwi-caching-infinispan/pom.xml | 5 +
.../remote/InfinispanRemoteCacheManager.java | 61 +++++--
.../marmotta/kiwi/test/RemoteClusterTest.java | 158 +++++++++++++++++++
.../kiwi/test/cluster/BaseClusterTest.java | 29 +++-
parent/pom.xml | 5 +
5 files changed, 239 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/1497768a/libraries/kiwi/kiwi-caching-infinispan/pom.xml
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/pom.xml b/libraries/kiwi/kiwi-caching-infinispan/pom.xml
index ddbbab0..5bd3416 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/pom.xml
+++ b/libraries/kiwi/kiwi-caching-infinispan/pom.xml
@@ -112,6 +112,11 @@
<artifactId>sesame-rio-rdfxml</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.infinispan</groupId>
+ <artifactId>infinispan-server-hotrod</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/marmotta/blob/1497768a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/InfinispanRemoteCacheManager.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/InfinispanRemoteCacheManager.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/InfinispanRemoteCacheManager.java
index 0090387..39a20b6 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/InfinispanRemoteCacheManager.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/remote/InfinispanRemoteCacheManager.java
@@ -19,10 +19,14 @@ package org.apache.marmotta.kiwi.infinispan.remote;
import org.apache.marmotta.kiwi.caching.CacheManager;
import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+import org.apache.marmotta.kiwi.infinispan.util.AsyncMap;
import org.apache.marmotta.kiwi.model.rdf.*;
import org.infinispan.client.hotrod.RemoteCacheManager;
import org.infinispan.client.hotrod.configuration.Configuration;
import org.infinispan.client.hotrod.configuration.ConfigurationBuilder;
+import org.infinispan.commons.CacheException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.util.Map;
@@ -33,6 +37,8 @@ import java.util.Map;
*/
public class InfinispanRemoteCacheManager implements CacheManager {
+ private static Logger log = LoggerFactory.getLogger(InfinispanRemoteCacheManager.class);
+
private KiWiConfiguration configuration;
private RemoteCacheManager cacheManager;
@@ -44,11 +50,15 @@ public class InfinispanRemoteCacheManager implements CacheManager {
this.configuration = configuration;
Configuration remoteCfg = new ConfigurationBuilder()
- .addServers(configuration.getClusterAddress())
+ .addServer()
+ .host(configuration.getClusterAddress())
+ .port(configuration.getClusterPort())
.marshaller(new CustomJBossMarshaller())
.build();
cacheManager = new RemoteCacheManager(remoteCfg);
+
+ log.info("initialised Infinispan remote cache manager (servers: {})", configuration.getClusterAddress());
}
@@ -60,7 +70,10 @@ public class InfinispanRemoteCacheManager implements CacheManager {
*/
@Override
public Map<Long, KiWiNode> getNodeCache() {
- return null;
+ if(nodeCache == null) {
+ nodeCache = new AsyncMap(cacheManager.getCache(NODE_CACHE));
+ }
+ return nodeCache;
}
/**
@@ -71,7 +84,10 @@ public class InfinispanRemoteCacheManager implements CacheManager {
*/
@Override
public Map<Long, KiWiTriple> getTripleCache() {
- return null;
+ if(tripleCache == null) {
+ tripleCache = new AsyncMap(cacheManager.getCache(TRIPLE_CACHE));
+ }
+ return tripleCache;
}
/**
@@ -82,7 +98,10 @@ public class InfinispanRemoteCacheManager implements CacheManager {
*/
@Override
public Map<String, KiWiUriResource> getUriCache() {
- return null;
+ if(uriCache == null) {
+ uriCache = new AsyncMap(cacheManager.getCache(URI_CACHE));
+ }
+ return uriCache;
}
/**
@@ -93,7 +112,10 @@ public class InfinispanRemoteCacheManager implements CacheManager {
*/
@Override
public Map<String, KiWiAnonResource> getBNodeCache() {
- return null;
+ if(bnodeCache == null) {
+ bnodeCache = new AsyncMap(cacheManager.getCache(BNODE_CACHE));
+ }
+ return bnodeCache;
}
/**
@@ -105,7 +127,10 @@ public class InfinispanRemoteCacheManager implements CacheManager {
*/
@Override
public Map<String, KiWiLiteral> getLiteralCache() {
- return null;
+ if(literalCache == null) {
+ literalCache = new AsyncMap(cacheManager.getCache(LITERAL_CACHE));
+ }
+ return literalCache;
}
/**
@@ -115,7 +140,10 @@ public class InfinispanRemoteCacheManager implements CacheManager {
*/
@Override
public Map<String, KiWiNamespace> getNamespaceUriCache() {
- return null;
+ if(nsUriCache == null) {
+ nsUriCache = new AsyncMap(cacheManager.getCache(NS_URI_CACHE));
+ }
+ return nsUriCache;
}
/**
@@ -125,7 +153,10 @@ public class InfinispanRemoteCacheManager implements CacheManager {
*/
@Override
public Map<String, KiWiNamespace> getNamespacePrefixCache() {
- return null;
+ if(nsPrefixCache == null) {
+ nsPrefixCache = new AsyncMap(cacheManager.getCache(NS_PREFIX_CACHE));
+ }
+ return nsPrefixCache;
}
/**
@@ -136,7 +167,10 @@ public class InfinispanRemoteCacheManager implements CacheManager {
*/
@Override
public Map<Long, Long> getRegistryCache() {
- return null;
+ if(registryCache == null) {
+ registryCache = cacheManager.getCache(REGISTRY_CACHE);
+ }
+ return registryCache;
}
/**
@@ -148,7 +182,7 @@ public class InfinispanRemoteCacheManager implements CacheManager {
*/
@Override
public Map getCacheByName(String name) {
- return null;
+ return cacheManager.getCache(name);
}
/**
@@ -164,6 +198,11 @@ public class InfinispanRemoteCacheManager implements CacheManager {
*/
@Override
public void shutdown() {
-
+ try {
+ log.info("shutting down cache manager ...");
+ cacheManager.stop();
+ } catch (CacheException ex) {
+ log.warn("error shutting down cache: {}", ex.getMessage());
+ }
}
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/1497768a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/RemoteClusterTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/RemoteClusterTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/RemoteClusterTest.java
new file mode 100644
index 0000000..630f64e
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/RemoteClusterTest.java
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.test;
+
+import org.apache.marmotta.commons.vocabulary.XSD;
+import org.apache.marmotta.kiwi.caching.CacheManager;
+import org.apache.marmotta.kiwi.config.CacheManagerType;
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+import org.apache.marmotta.kiwi.infinispan.embedded.InfinispanEmbeddedCacheManager;
+import org.apache.marmotta.kiwi.infinispan.remote.CustomJBossMarshaller;
+import org.apache.marmotta.kiwi.test.cluster.BaseClusterTest;
+import org.infinispan.client.hotrod.RemoteCache;
+import org.infinispan.client.hotrod.RemoteCacheManager;
+import org.infinispan.configuration.cache.CacheMode;
+import org.infinispan.configuration.cache.Configuration;
+import org.infinispan.configuration.cache.ConfigurationBuilder;
+import org.infinispan.configuration.global.GlobalConfiguration;
+import org.infinispan.configuration.global.GlobalConfigurationBuilder;
+import org.infinispan.eviction.EvictionStrategy;
+import org.infinispan.manager.DefaultCacheManager;
+import org.infinispan.manager.EmbeddedCacheManager;
+import org.infinispan.server.hotrod.HotRodServer;
+import org.infinispan.server.hotrod.configuration.HotRodServerConfiguration;
+import org.infinispan.server.hotrod.configuration.HotRodServerConfigurationBuilder;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class RemoteClusterTest extends BaseClusterTest {
+
+ private static Logger log = LoggerFactory.getLogger(RemoteClusterTest.class);
+
+ private static HotRodServer hotRodServer1, hotRodServer2, hotRodServer3;
+
+ @BeforeClass
+ public static void setup() {
+ hotRodServer1 = buildServer(61222);
+ hotRodServer2 = buildServer(61223);
+ hotRodServer3 = buildServer(61224);
+
+ ClusterTestSupport s = new ClusterTestSupport(CacheManagerType.INFINISPAN_HOTROD);
+
+ KiWiConfiguration base = s.buildBaseConfiguration();
+ base.setClusterAddress("127.0.0.1");
+ s.setup(base);
+ }
+
+
+
+ private static HotRodServer buildServer(int port) {
+ HotRodServer hotRodServer = new HotRodServer() {
+ @Override
+ public ConfigurationBuilder createTopologyCacheConfig(long distSyncTimeout) {
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ }
+
+ ConfigurationBuilder c = super.createTopologyCacheConfig(distSyncTimeout);
+ c.transaction().syncCommitPhase(false).syncRollbackPhase(false);
+ return c;
+ }
+ };
+
+ HotRodServerConfiguration hotrodConfig = new HotRodServerConfigurationBuilder()
+ .host("127.0.0.1")
+ .port(port)
+ .proxyHost("127.0.0.1")
+ .proxyPort(port)
+ .topologyStateTransfer(false)
+ .workerThreads(2)
+ .build(true);
+
+
+ GlobalConfiguration globalConfiguration = new GlobalConfigurationBuilder()
+ .classLoader(InfinispanEmbeddedCacheManager.class.getClassLoader())
+ .globalJmxStatistics()
+ .jmxDomain("org.apache.marmotta.kiwi")
+ .allowDuplicateDomains(true)
+ .build();
+
+ Configuration defaultConfiguration = new ConfigurationBuilder()
+ .clustering()
+ .cacheMode(CacheMode.LOCAL)
+ .eviction()
+ .strategy(EvictionStrategy.LIRS)
+ .maxEntries(100000)
+ .expiration()
+ .lifespan(5, TimeUnit.MINUTES)
+ .maxIdle(1, TimeUnit.MINUTES)
+ .build();
+
+ EmbeddedCacheManager cacheManager = new DefaultCacheManager(globalConfiguration, defaultConfiguration, true);
+ cacheManager.defineConfiguration(CacheManager.NODE_CACHE, defaultConfiguration);
+ cacheManager.defineConfiguration(CacheManager.TRIPLE_CACHE, defaultConfiguration);
+ cacheManager.defineConfiguration(CacheManager.URI_CACHE, defaultConfiguration);
+ cacheManager.defineConfiguration(CacheManager.BNODE_CACHE, defaultConfiguration);
+ cacheManager.defineConfiguration(CacheManager.LITERAL_CACHE, defaultConfiguration);
+ cacheManager.defineConfiguration(CacheManager.NS_PREFIX_CACHE, defaultConfiguration);
+ cacheManager.defineConfiguration(CacheManager.NS_URI_CACHE, defaultConfiguration);
+ cacheManager.defineConfiguration(CacheManager.REGISTRY_CACHE, defaultConfiguration);
+ cacheManager.getCache(CacheManager.NODE_CACHE, true);
+ cacheManager.getCache(CacheManager.TRIPLE_CACHE, true);
+ cacheManager.getCache(CacheManager.URI_CACHE, true);
+ cacheManager.getCache(CacheManager.BNODE_CACHE, true);
+ cacheManager.getCache(CacheManager.LITERAL_CACHE, true);
+ cacheManager.getCache(CacheManager.NS_PREFIX_CACHE, true);
+ cacheManager.getCache(CacheManager.NS_URI_CACHE, true);
+ cacheManager.getCache(CacheManager.REGISTRY_CACHE,true);
+
+ hotRodServer.start(hotrodConfig, cacheManager);
+
+ // test if cache is available
+ org.infinispan.client.hotrod.configuration.Configuration remoteCfg = new org.infinispan.client.hotrod.configuration.ConfigurationBuilder()
+ .addServer()
+ .host("127.0.0.1")
+ .port(port)
+ .marshaller(new CustomJBossMarshaller())
+ .pingOnStartup(true)
+ .build(true);
+
+
+ RemoteCacheManager remoteCacheManager = new RemoteCacheManager(remoteCfg);
+ Assert.assertTrue(remoteCacheManager.isStarted());
+
+ RemoteCache<String, String> m = remoteCacheManager.getCache();
+
+ m.put(XSD.AnyURI.stringValue(), XSD.AnyURI.stringValue());
+ String n = m.get(XSD.AnyURI.stringValue());
+
+ Assert.assertNotNull(n);
+
+ return hotRodServer;
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/1497768a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/cluster/BaseClusterTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/cluster/BaseClusterTest.java b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/cluster/BaseClusterTest.java
index 12a57b0..d2e12ef 100644
--- a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/cluster/BaseClusterTest.java
+++ b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/cluster/BaseClusterTest.java
@@ -44,7 +44,7 @@ public abstract class BaseClusterTest {
private static int datacenterIds = 1;
- private static Repository repositorySync1, repositorySync2, repositoryAsync1, repositoryAsync2;
+ protected static Repository repositorySync1, repositorySync2, repositoryAsync1, repositoryAsync2;
private static CacheManager cacheManagerSync1, cacheManagerSync2, cacheManagerAsync1, cacheManagerAsync2;
@@ -133,11 +133,15 @@ public abstract class BaseClusterTest {
}
public void setup() {
+ setup(null);
+ }
+
+ public void setup(KiWiConfiguration base) {
try {
- repositorySync1 = createConfiguration(61222);
- repositorySync2 = createConfiguration(61222);
- repositoryAsync1 = createConfiguration(61223);
- repositoryAsync2 = createConfiguration(61224);
+ repositorySync1 = createConfiguration(base,61222);
+ repositorySync2 = createConfiguration(base,61222);
+ repositoryAsync1 = createConfiguration(base,61223);
+ repositoryAsync2 = createConfiguration(base,61224);
cacheManagerSync1 = getCacheManager(repositorySync1);
cacheManagerSync2 = getCacheManager(repositorySync2);
@@ -150,13 +154,22 @@ public abstract class BaseClusterTest {
}
}
-
- private Repository createConfiguration(int port) throws RepositoryException {
- KiWiConfiguration config = new KiWiConfiguration(
+ public KiWiConfiguration buildBaseConfiguration() {
+ return new KiWiConfiguration(
"default-H2",
"jdbc:h2:mem:kiwitest;MVCC=true;DB_CLOSE_ON_EXIT=TRUE;DB_CLOSE_DELAY=-1",
"kiwi", "kiwi",
new H2Dialect());
+ }
+
+ private Repository createConfiguration(KiWiConfiguration base, int port) throws RepositoryException {
+ KiWiConfiguration config;
+
+ if(base != null) {
+ config = base;
+ } else {
+ config = buildBaseConfiguration();
+ }
config.setDatacenterId(datacenterIds++);
config.setClustered(true);
config.setCacheManager(type);
http://git-wip-us.apache.org/repos/asf/marmotta/blob/1497768a/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 2190cbe..8abc2b2 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -1045,6 +1045,11 @@
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
+ <artifactId>infinispan-server-hotrod</artifactId>
+ <version>6.0.1.Final</version>
+ </dependency>
+ <dependency>
+ <groupId>org.infinispan</groupId>
<artifactId>infinispan-cdi</artifactId>
<version>6.0.1.Final</version>
</dependency>
[18/21] git commit: added repository tests to other cache
implementations
Posted by ss...@apache.org.
added repository tests to other cache implementations
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/d04230ab
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/d04230ab
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/d04230ab
Branch: refs/heads/MARMOTTA-450
Commit: d04230ab9b7fac0027743f4d1b70521d244487b7
Parents: b25a254
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Tue Mar 4 22:03:09 2014 +0100
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Tue Mar 4 22:03:09 2014 +0100
----------------------------------------------------------------------
libraries/kiwi/kiwi-caching-hazelcast/pom.xml | 5 +
.../caching/HazelcastCacheManager.java | 22 +-
.../hazelcast/serializer/BNodeSerializer.java | 15 +-
.../HazelcastRepositoryConnectionTest.java | 66 +++++
.../test/cluster/HazelcastRepositoryTest.java | 64 +++++
libraries/kiwi/kiwi-caching-infinispan/pom.xml | 5 +
.../externalizer/BNodeExternalizer.java | 13 +-
.../marmotta/kiwi/test/EmbeddedClusterTest.java | 37 ---
.../marmotta/kiwi/test/ExternalizerTest.java | 241 ------------------
.../marmotta/kiwi/test/RemoteClusterTest.java | 156 ------------
.../kiwi/test/embedded/EmbeddedClusterTest.java | 37 +++
.../EmbeddedRepositoryConnectionTest.java | 66 +++++
.../test/embedded/EmbeddedRepositoryTest.java | 64 +++++
.../test/externalizer/ExternalizerTest.java | 254 +++++++++++++++++++
.../kiwi/test/remote/HotRodClusterTest.java | 57 +++++
.../kiwi/test/remote/HotRodPersistenceTest.java | 42 +++
.../remote/HotRodRepositoryConnectionTest.java | 72 ++++++
.../kiwi/test/remote/HotRodRepositoryTest.java | 70 +++++
.../kiwi/test/remote/HotRodServerRule.java | 178 +++++++++++++
.../marmotta/kiwi/test/PersistenceTest.java | 52 ++--
.../kiwi/test/cluster/BaseClusterTest.java | 43 +++-
21 files changed, 1068 insertions(+), 491 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/libraries/kiwi/kiwi-caching-hazelcast/pom.xml
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/pom.xml b/libraries/kiwi/kiwi-caching-hazelcast/pom.xml
index b1f406a..4d82fbd 100644
--- a/libraries/kiwi/kiwi-caching-hazelcast/pom.xml
+++ b/libraries/kiwi/kiwi-caching-hazelcast/pom.xml
@@ -107,6 +107,11 @@
<artifactId>sesame-rio-rdfxml</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.openrdf.sesame</groupId>
+ <artifactId>sesame-store-testsuite</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/caching/HazelcastCacheManager.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/caching/HazelcastCacheManager.java b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/caching/HazelcastCacheManager.java
index b2b03a8..db4ee50 100644
--- a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/caching/HazelcastCacheManager.java
+++ b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/caching/HazelcastCacheManager.java
@@ -63,9 +63,13 @@ public class HazelcastCacheManager implements CacheManager {
this.configuration = configuration;
hcConfiguration = new Config();
- hcConfiguration.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(true);
- hcConfiguration.getNetworkConfig().getJoin().getMulticastConfig().setMulticastPort(configuration.getClusterPort());
- hcConfiguration.getNetworkConfig().getJoin().getMulticastConfig().setMulticastGroup(configuration.getClusterAddress());
+ if(configuration.isClustered()) {
+ hcConfiguration.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(true);
+ hcConfiguration.getNetworkConfig().getJoin().getMulticastConfig().setMulticastPort(configuration.getClusterPort());
+ hcConfiguration.getNetworkConfig().getJoin().getMulticastConfig().setMulticastGroup(configuration.getClusterAddress());
+ } else {
+ hcConfiguration.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
+ }
hcConfiguration.getGroupConfig().setName(configuration.getClusterName());
@@ -76,12 +80,16 @@ public class HazelcastCacheManager implements CacheManager {
hazelcast = Hazelcast.newHazelcastInstance(hcConfiguration);
+ if(configuration.isClustered()) {
+ log.info("initialised Hazelcast local cache manager");
+ } else {
+ log.info("initialised Hazelcast distributed cache manager (cluster name: {})", configuration.getClusterName());
- log.info("initialised Hazelcast distributed cache manager (cluster name: {})", configuration.getClusterName());
-
- if(configuration.getCacheMode() != CacheMode.DISTRIBUTED) {
- log.warn("Hazelcast only supports distributed cache mode (mode configuration was {})", configuration.getCacheMode());
+ if(configuration.getCacheMode() != CacheMode.DISTRIBUTED) {
+ log.warn("Hazelcast only supports distributed cache mode (mode configuration was {})", configuration.getCacheMode());
+ }
}
+
}
private void setupSerializers() {
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/BNodeSerializer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/BNodeSerializer.java b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/BNodeSerializer.java
index 4462537..e105b39 100644
--- a/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/BNodeSerializer.java
+++ b/libraries/kiwi/kiwi-caching-hazelcast/src/main/java/org/apache/marmotta/kiwi/hazelcast/serializer/BNodeSerializer.java
@@ -20,6 +20,7 @@ package org.apache.marmotta.kiwi.hazelcast.serializer;
import com.hazelcast.nio.ObjectDataInput;
import com.hazelcast.nio.ObjectDataOutput;
import com.hazelcast.nio.serialization.StreamSerializer;
+import org.apache.marmotta.commons.io.DataIO;
import org.apache.marmotta.kiwi.model.rdf.KiWiAnonResource;
import java.io.IOException;
@@ -42,24 +43,18 @@ public class BNodeSerializer implements StreamSerializer<KiWiAnonResource> {
@Override
public void write(ObjectDataOutput output, KiWiAnonResource object) throws IOException {
output.writeLong(object.getId());
- output.writeInt(object.stringValue().length());
- output.writeChars(object.stringValue());
+ DataIO.writeString(output, object.stringValue());
output.writeLong(object.getCreated().getTime());
}
@Override
public KiWiAnonResource read(ObjectDataInput input) throws IOException {
- long id = input.readLong();
- int len = input.readInt();
-
- char[] anonId = new char[len];
- for(int i=0; i<len; i++) {
- anonId[i] = input.readChar();
- }
+ long id = input.readLong();
+ String anonId = DataIO.readString(input);
Date created = new Date(input.readLong());
- KiWiAnonResource r = new KiWiAnonResource(new String(anonId),created);
+ KiWiAnonResource r = new KiWiAnonResource(anonId,created);
r.setId(id);
return r;
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastRepositoryConnectionTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastRepositoryConnectionTest.java b/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastRepositoryConnectionTest.java
new file mode 100644
index 0000000..ef75821
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastRepositoryConnectionTest.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.test.cluster;
+
+import org.apache.marmotta.kiwi.config.CacheManagerType;
+import org.apache.marmotta.kiwi.config.CacheMode;
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+import org.apache.marmotta.kiwi.sail.KiWiStore;
+import org.apache.marmotta.kiwi.test.junit.KiWiDatabaseRunner;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.openrdf.repository.Repository;
+import org.openrdf.repository.RepositoryConnectionTest;
+import org.openrdf.repository.sail.SailRepository;
+
+/**
+ * Run the {@link org.openrdf.repository.RepositoryConnectionTest}s.
+ * @author Jakob Frank <ja...@apache.org>
+ *
+ */
+@RunWith(KiWiDatabaseRunner.class)
+public class HazelcastRepositoryConnectionTest extends RepositoryConnectionTest {
+
+ private final KiWiConfiguration config;
+
+ public HazelcastRepositoryConnectionTest(KiWiConfiguration config) {
+ this.config = config;
+ config.setClustered(false);
+ config.setClusterPort(61222);
+ config.setCacheMode(CacheMode.DISTRIBUTED);
+ config.setCacheManager(CacheManagerType.HAZELCAST);
+ }
+
+ /* (non-Javadoc)
+ * @see org.openrdf.repository.RepositoryConnectionTest#createRepository()
+ */
+ @Override
+ protected Repository createRepository() throws Exception {
+ config.setDefaultContext(null);
+ KiWiStore store = new KiWiStore(config);
+ store.setDropTablesOnShutdown(true);
+ return new SailRepository(store);
+ }
+
+ @Ignore
+ @Test
+ @Override
+ public void testOrderByQueriesAreInterruptable() throws Exception {
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastRepositoryTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastRepositoryTest.java b/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastRepositoryTest.java
new file mode 100644
index 0000000..3b080ef
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-hazelcast/src/test/java/org/apache/marmotta/kiwi/test/cluster/HazelcastRepositoryTest.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.test.cluster;
+
+import org.apache.marmotta.kiwi.config.CacheManagerType;
+import org.apache.marmotta.kiwi.config.CacheMode;
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+import org.apache.marmotta.kiwi.sail.KiWiStore;
+import org.apache.marmotta.kiwi.test.junit.KiWiDatabaseRunner;
+import org.junit.runner.RunWith;
+import org.openrdf.repository.Repository;
+import org.openrdf.repository.RepositoryTest;
+import org.openrdf.repository.sail.SailRepository;
+
+/**
+ * Run the {@link org.openrdf.repository.RepositoryTest}s.
+ * @author Jakob Frank <ja...@apache.org>
+ *
+ */
+@RunWith(KiWiDatabaseRunner.class)
+public class HazelcastRepositoryTest extends RepositoryTest {
+
+ private final KiWiConfiguration config;
+
+ private KiWiStore store;
+
+ public HazelcastRepositoryTest(KiWiConfiguration config) {
+ this.config = config;
+ config.setClustered(true);
+ config.setClusterPort(61222);
+ config.setCacheMode(CacheMode.DISTRIBUTED);
+ config.setCacheManager(CacheManagerType.HAZELCAST);
+ }
+
+ /* (non-Javadoc)
+ * @see org.openrdf.repository.RepositoryTest#createRepository()
+ */
+ @Override
+ protected Repository createRepository() throws Exception {
+ store = new KiWiStore(config);
+ return new SailRepository(store);
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ store.getPersistence().dropDatabase();
+ super.tearDown();
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/libraries/kiwi/kiwi-caching-infinispan/pom.xml
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/pom.xml b/libraries/kiwi/kiwi-caching-infinispan/pom.xml
index 5bd3416..0a919b6 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/pom.xml
+++ b/libraries/kiwi/kiwi-caching-infinispan/pom.xml
@@ -117,6 +117,11 @@
<artifactId>infinispan-server-hotrod</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.openrdf.sesame</groupId>
+ <artifactId>sesame-store-testsuite</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/BNodeExternalizer.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/BNodeExternalizer.java b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/BNodeExternalizer.java
index 4bcaf40..e9ad806 100644
--- a/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/BNodeExternalizer.java
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/main/java/org/apache/marmotta/kiwi/infinispan/externalizer/BNodeExternalizer.java
@@ -17,6 +17,7 @@
package org.apache.marmotta.kiwi.infinispan.externalizer;
+import org.apache.marmotta.commons.io.DataIO;
import org.apache.marmotta.kiwi.model.rdf.KiWiAnonResource;
import org.infinispan.commons.marshall.AdvancedExternalizer;
import org.infinispan.commons.util.Util;
@@ -48,24 +49,18 @@ public class BNodeExternalizer extends BaseExternalizer<KiWiAnonResource> implem
@Override
public void writeObject(ObjectOutput output, KiWiAnonResource object) throws IOException {
output.writeLong(object.getId());
- output.writeInt(object.stringValue().length());
- output.writeChars(object.stringValue());
+ DataIO.writeString(output, object.stringValue());
output.writeLong(object.getCreated().getTime());
}
@Override
public KiWiAnonResource readObject(ObjectInput input) throws IOException, ClassNotFoundException {
long id = input.readLong();
- int len = input.readInt();
-
- char[] anonId = new char[len];
- for(int i=0; i<len; i++) {
- anonId[i] = input.readChar();
- }
+ String anonId = DataIO.readString(input);
Date created = new Date(input.readLong());
- KiWiAnonResource r = new KiWiAnonResource(new String(anonId),created);
+ KiWiAnonResource r = new KiWiAnonResource(anonId,created);
r.setId(id);
return r;
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/EmbeddedClusterTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/EmbeddedClusterTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/EmbeddedClusterTest.java
deleted file mode 100644
index 17bc3cf..0000000
--- a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/EmbeddedClusterTest.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.kiwi.test;
-
-import org.apache.marmotta.kiwi.config.CacheManagerType;
-import org.apache.marmotta.kiwi.test.cluster.BaseClusterTest;
-import org.junit.BeforeClass;
-
-/**
- * Add file description here!
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class EmbeddedClusterTest extends BaseClusterTest {
-
-
- @BeforeClass
- public static void setup() {
- ClusterTestSupport s = new ClusterTestSupport(CacheManagerType.INFINISPAN_CLUSTERED);
- s.setup();
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/ExternalizerTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/ExternalizerTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/ExternalizerTest.java
deleted file mode 100644
index 94121f3..0000000
--- a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/ExternalizerTest.java
+++ /dev/null
@@ -1,241 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.kiwi.test;
-
-import org.apache.commons.lang3.RandomStringUtils;
-import org.apache.marmotta.commons.vocabulary.XSD;
-import org.apache.marmotta.kiwi.infinispan.externalizer.*;
-import org.apache.marmotta.kiwi.infinispan.remote.CustomJBossMarshaller;
-import org.apache.marmotta.kiwi.model.rdf.*;
-import org.infinispan.commons.marshall.AdvancedExternalizer;
-import org.infinispan.commons.marshall.StreamingMarshaller;
-import org.infinispan.configuration.cache.CacheMode;
-import org.infinispan.configuration.cache.Configuration;
-import org.infinispan.configuration.cache.ConfigurationBuilder;
-import org.infinispan.configuration.global.GlobalConfiguration;
-import org.infinispan.configuration.global.GlobalConfigurationBuilder;
-import org.infinispan.manager.DefaultCacheManager;
-import org.infinispan.manager.EmbeddedCacheManager;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.openrdf.model.Value;
-import org.openrdf.model.ValueFactory;
-import org.openrdf.model.vocabulary.OWL;
-import org.openrdf.model.vocabulary.RDFS;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.*;
-import java.util.Random;
-
-/**
- * Test the different externalizer implementations we provide for Infinispan
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class ExternalizerTest {
-
- private static ValueFactory valueFactory = new TestValueFactory();
-
- private static Random rnd = new Random();
-
- private static Logger log = LoggerFactory.getLogger(ExternalizerTest.class);
-
- private static StreamingMarshaller marshaller, hotrod;
-
-
- @BeforeClass
- public static void setup() {
- AdvancedExternalizer[] externalizers = new AdvancedExternalizer[] {
- new UriExternalizer(),
- new BNodeExternalizer(),
- new StringLiteralExternalizer(),
- new DateLiteralExternalizer(),
- new BooleanLiteralExternalizer(),
- new IntLiteralExternalizer(),
- new DoubleLiteralExternalizer(),
- new TripleExternalizer()
- };
-
-
- GlobalConfiguration globalConfiguration = new GlobalConfigurationBuilder()
- .transport()
- .defaultTransport()
- .serialization()
- .addAdvancedExternalizer(externalizers)
- .build();
-
- Configuration defaultConfiguration = new ConfigurationBuilder()
- .clustering()
- .cacheMode(CacheMode.DIST_ASYNC)
- .build();
-
- EmbeddedCacheManager cacheManager = new DefaultCacheManager(globalConfiguration, defaultConfiguration, true);
-
- marshaller = cacheManager.getCache().getAdvancedCache().getComponentRegistry().getCacheMarshaller();
-
- hotrod = new CustomJBossMarshaller();
- }
-
-
- @Test
- public void testUriResource() throws Exception {
- marshall((KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8)), new UriExternalizer());
- }
-
- @Test
- public void testCompressedUriResource() throws Exception {
- marshall((KiWiUriResource) valueFactory.createURI(XSD.Double.stringValue()), new UriExternalizer());
- marshall((KiWiUriResource) valueFactory.createURI(RDFS.LABEL.stringValue()), new UriExternalizer());
- marshall((KiWiUriResource) valueFactory.createURI(OWL.SAMEAS.stringValue()), new UriExternalizer());
- }
-
-
- @Test
- public void testBNode() throws Exception {
- marshall((KiWiAnonResource) valueFactory.createBNode(), new BNodeExternalizer());
- }
-
- @Test
- public void testStringLiteral() throws Exception {
- marshall((KiWiStringLiteral) valueFactory.createLiteral(RandomStringUtils.randomAscii(40)), new StringLiteralExternalizer());
- }
-
- @Test
- public void testLangLiteral() throws Exception {
- marshall((KiWiStringLiteral) valueFactory.createLiteral(RandomStringUtils.randomAscii(40),"en"), new StringLiteralExternalizer());
- }
-
- @Test
- public void testTypeLiteral() throws Exception {
- marshall((KiWiStringLiteral) valueFactory.createLiteral(RandomStringUtils.randomAscii(40),valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8))), new StringLiteralExternalizer());
- }
-
-
- @Test
- public void testIntLiteral() throws Exception {
- marshall((KiWiIntLiteral) valueFactory.createLiteral(rnd.nextInt()), new IntLiteralExternalizer());
- }
-
-
- @Test
- public void testTriple() throws Exception {
- KiWiUriResource s = (KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
- KiWiUriResource p = (KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
- KiWiNode o = (KiWiNode) randomNode();
- KiWiTriple t = (KiWiTriple) valueFactory.createStatement(s,p,o);
-
- marshall(t, new TripleExternalizer());
- }
-
- @Test
- public void testPrefixCompressedTriple() throws Exception {
- KiWiUriResource s = (KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
- KiWiUriResource p = (KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
- KiWiUriResource o = (KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
- KiWiTriple t = (KiWiTriple) valueFactory.createStatement(s,p,o);
-
- marshall(t, new TripleExternalizer());
- }
-
-
- /**
- * Run the given object through the marshaller using an in-memory stream.
- * @param origin
- * @param <T>
- * @return
- */
- private <T> void marshall(T origin, AdvancedExternalizer<T> externalizer) throws IOException, ClassNotFoundException, InterruptedException {
- log.info("- testing Java ObjectStream ...");
- ByteArrayOutputStream outBytesOS = new ByteArrayOutputStream();
- ObjectOutputStream outOS = new ObjectOutputStream(outBytesOS);
-
- outOS.writeObject(origin);
-
- outOS.close();
-
- log.info(" object {}: serialized with {} bytes", origin, outBytesOS.size());
-
-
- log.info("- testing externalizer directly ...");
- ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
- ObjectOutputStream out = new ObjectOutputStream(outBytes);
-
- externalizer.writeObject(out, origin);
- out.close();
-
- log.info(" object {}: serialized with {} bytes", origin, outBytes.size());
-
- ByteArrayInputStream inBytes = new ByteArrayInputStream(outBytes.toByteArray());
- ObjectInputStream in = new ObjectInputStream(inBytes);
-
- T destination1 = externalizer.readObject(in);
-
- Assert.assertEquals(origin,destination1);
-
- log.info("- testing externalizer with infinispan cluster marshaller ...");
-
- byte[] bytes = marshaller.objectToByteBuffer(origin);
- log.info(" object {}: serialized with {} bytes", origin, bytes.length);
-
- Object destination2 = marshaller.objectFromByteBuffer(bytes);
-
- Assert.assertEquals(origin, destination2);
-
-
-
- log.info("- testing externalizer with infinispan hotrod marshaller ...");
-
- byte[] bytesH = hotrod.objectToByteBuffer(origin);
- log.info(" object {}: serialized with {} bytes", origin, bytesH.length);
-
- Object destination3 = hotrod.objectFromByteBuffer(bytesH);
-
- Assert.assertEquals(origin, destination3);
-
- }
-
-
- /**
- * Return a random RDF value, either a reused object (10% chance) or of any other kind.
- * @return
- */
- protected Value randomNode() {
- Value object;
- switch(rnd.nextInt(6)) {
- case 0: object = valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
- break;
- case 1: object = valueFactory.createBNode();
- break;
- case 2: object = valueFactory.createLiteral(RandomStringUtils.randomAscii(40));
- break;
- case 3: object = valueFactory.createLiteral(rnd.nextInt());
- break;
- case 4: object = valueFactory.createLiteral(rnd.nextDouble());
- break;
- case 5: object = valueFactory.createLiteral(rnd.nextBoolean());
- break;
- default: object = valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
- break;
-
- }
- return object;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/RemoteClusterTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/RemoteClusterTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/RemoteClusterTest.java
deleted file mode 100644
index 4295c28..0000000
--- a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/RemoteClusterTest.java
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.kiwi.test;
-
-import org.apache.marmotta.kiwi.caching.CacheManager;
-import org.apache.marmotta.kiwi.config.CacheManagerType;
-import org.apache.marmotta.kiwi.config.KiWiConfiguration;
-import org.apache.marmotta.kiwi.infinispan.embedded.InfinispanEmbeddedCacheManager;
-import org.apache.marmotta.kiwi.infinispan.remote.CustomJBossMarshaller;
-import org.apache.marmotta.kiwi.test.cluster.BaseClusterTest;
-import org.infinispan.client.hotrod.RemoteCache;
-import org.infinispan.client.hotrod.RemoteCacheManager;
-import org.infinispan.commons.api.BasicCacheContainer;
-import org.infinispan.commons.equivalence.ByteArrayEquivalence;
-import org.infinispan.configuration.cache.CacheMode;
-import org.infinispan.configuration.cache.Configuration;
-import org.infinispan.configuration.cache.ConfigurationBuilder;
-import org.infinispan.configuration.global.GlobalConfiguration;
-import org.infinispan.configuration.global.GlobalConfigurationBuilder;
-import org.infinispan.manager.DefaultCacheManager;
-import org.infinispan.manager.EmbeddedCacheManager;
-import org.infinispan.server.hotrod.HotRodServer;
-import org.infinispan.server.hotrod.configuration.HotRodServerConfiguration;
-import org.infinispan.server.hotrod.configuration.HotRodServerConfigurationBuilder;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Add file description here!
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class RemoteClusterTest extends BaseClusterTest {
-
- private static Logger log = LoggerFactory.getLogger(RemoteClusterTest.class);
-
- private static HotRodServer hotRodServer1, hotRodServer2, hotRodServer3;
-
- @BeforeClass
- public static void setup() {
- hotRodServer1 = buildServer(61222);
- hotRodServer2 = buildServer(61223);
- hotRodServer3 = buildServer(61224);
-
- ClusterTestSupport s = new ClusterTestSupport(CacheManagerType.INFINISPAN_HOTROD);
-
- KiWiConfiguration base = s.buildBaseConfiguration();
- base.setClusterAddress("127.0.0.1");
- s.setup(base);
- }
-
-
-
- private static HotRodServer buildServer(int port) {
- HotRodServer hotRodServer = new HotRodServer() {
- @Override
- public ConfigurationBuilder createTopologyCacheConfig(long distSyncTimeout) {
- try {
- Thread.sleep(100);
- } catch (InterruptedException e) {
- }
-
- ConfigurationBuilder c = super.createTopologyCacheConfig(distSyncTimeout);
- c.transaction().syncCommitPhase(false).syncRollbackPhase(false);
- return c;
- }
- };
-
- HotRodServerConfiguration hotrodConfig = new HotRodServerConfigurationBuilder()
- .host("127.0.0.1")
- .port(port)
- .proxyHost("127.0.0.1")
- .proxyPort(port)
- .topologyStateTransfer(false)
- .defaultCacheName(BasicCacheContainer.DEFAULT_CACHE_NAME)
- .idleTimeout(0)
- .workerThreads(2)
- .build(true);
-
-
- GlobalConfiguration globalConfiguration = new GlobalConfigurationBuilder()
- .classLoader(InfinispanEmbeddedCacheManager.class.getClassLoader())
- .globalJmxStatistics()
- .jmxDomain("org.apache.marmotta.kiwi")
- .allowDuplicateDomains(true)
- .build();
-
- Configuration defaultConfiguration = new ConfigurationBuilder()
- .clustering()
- .cacheMode(CacheMode.LOCAL)
- .sync()
- .dataContainer()
- .keyEquivalence(ByteArrayEquivalence.INSTANCE)
- .valueEquivalence(ByteArrayEquivalence.INSTANCE)
- .build();
-
- EmbeddedCacheManager cacheManager = new DefaultCacheManager(globalConfiguration, defaultConfiguration, true);
- cacheManager.defineConfiguration(CacheManager.NODE_CACHE, defaultConfiguration);
- cacheManager.defineConfiguration(CacheManager.TRIPLE_CACHE, defaultConfiguration);
- cacheManager.defineConfiguration(CacheManager.URI_CACHE, defaultConfiguration);
- cacheManager.defineConfiguration(CacheManager.BNODE_CACHE, defaultConfiguration);
- cacheManager.defineConfiguration(CacheManager.LITERAL_CACHE, defaultConfiguration);
- cacheManager.defineConfiguration(CacheManager.NS_PREFIX_CACHE, defaultConfiguration);
- cacheManager.defineConfiguration(CacheManager.NS_URI_CACHE, defaultConfiguration);
- cacheManager.defineConfiguration(CacheManager.REGISTRY_CACHE, defaultConfiguration);
- cacheManager.getCache(CacheManager.NODE_CACHE, true);
- cacheManager.getCache(CacheManager.TRIPLE_CACHE, true);
- cacheManager.getCache(CacheManager.URI_CACHE, true);
- cacheManager.getCache(CacheManager.BNODE_CACHE, true);
- cacheManager.getCache(CacheManager.LITERAL_CACHE, true);
- cacheManager.getCache(CacheManager.NS_PREFIX_CACHE, true);
- cacheManager.getCache(CacheManager.NS_URI_CACHE, true);
- cacheManager.getCache(CacheManager.REGISTRY_CACHE, true);
-
- hotRodServer.start(hotrodConfig, cacheManager);
-
- // test if cache is available
- org.infinispan.client.hotrod.configuration.Configuration remoteCfg = new org.infinispan.client.hotrod.configuration.ConfigurationBuilder()
- .addServer()
- .host("127.0.0.1")
- .port(port)
- .marshaller(new CustomJBossMarshaller())
- .pingOnStartup(true)
- .build(true);
-
-
- RemoteCacheManager remoteCacheManager = new RemoteCacheManager(remoteCfg);
- Assert.assertTrue(remoteCacheManager.isStarted());
-
- RemoteCache<String, String> m = remoteCacheManager.getCache();
-
- m.put("xyz", "abc");
- String n = m.get("xyz");
-
- Assert.assertNotNull(n);
-
- return hotRodServer;
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedClusterTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedClusterTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedClusterTest.java
new file mode 100644
index 0000000..7405e0f
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedClusterTest.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.test.embedded;
+
+import org.apache.marmotta.kiwi.config.CacheManagerType;
+import org.apache.marmotta.kiwi.test.cluster.BaseClusterTest;
+import org.junit.BeforeClass;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class EmbeddedClusterTest extends BaseClusterTest {
+
+
+ @BeforeClass
+ public static void setup() {
+ ClusterTestSupport s = new ClusterTestSupport(CacheManagerType.INFINISPAN_CLUSTERED);
+ s.setup();
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedRepositoryConnectionTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedRepositoryConnectionTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedRepositoryConnectionTest.java
new file mode 100644
index 0000000..676e90b
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedRepositoryConnectionTest.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.test.embedded;
+
+import org.apache.marmotta.kiwi.config.CacheManagerType;
+import org.apache.marmotta.kiwi.config.CacheMode;
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+import org.apache.marmotta.kiwi.sail.KiWiStore;
+import org.apache.marmotta.kiwi.test.junit.KiWiDatabaseRunner;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.openrdf.repository.Repository;
+import org.openrdf.repository.RepositoryConnectionTest;
+import org.openrdf.repository.sail.SailRepository;
+
+/**
+ * Run the {@link RepositoryConnectionTest}s.
+ * @author Jakob Frank <ja...@apache.org>
+ *
+ */
+@RunWith(KiWiDatabaseRunner.class)
+public class EmbeddedRepositoryConnectionTest extends RepositoryConnectionTest {
+
+ private final KiWiConfiguration config;
+
+ public EmbeddedRepositoryConnectionTest(KiWiConfiguration config) {
+ this.config = config;
+ config.setClustered(true);
+ config.setClusterPort(61222);
+ config.setCacheMode(CacheMode.LOCAL);
+ config.setCacheManager(CacheManagerType.INFINISPAN_CLUSTERED);
+ }
+
+ /* (non-Javadoc)
+ * @see org.openrdf.repository.RepositoryConnectionTest#createRepository()
+ */
+ @Override
+ protected Repository createRepository() throws Exception {
+ config.setDefaultContext(null);
+ KiWiStore store = new KiWiStore(config);
+ store.setDropTablesOnShutdown(true);
+ return new SailRepository(store);
+ }
+
+ @Ignore
+ @Test
+ @Override
+ public void testOrderByQueriesAreInterruptable() throws Exception {
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedRepositoryTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedRepositoryTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedRepositoryTest.java
new file mode 100644
index 0000000..7094893
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/embedded/EmbeddedRepositoryTest.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.test.embedded;
+
+import org.apache.marmotta.kiwi.config.CacheManagerType;
+import org.apache.marmotta.kiwi.config.CacheMode;
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+import org.apache.marmotta.kiwi.sail.KiWiStore;
+import org.apache.marmotta.kiwi.test.junit.KiWiDatabaseRunner;
+import org.junit.runner.RunWith;
+import org.openrdf.repository.Repository;
+import org.openrdf.repository.RepositoryTest;
+import org.openrdf.repository.sail.SailRepository;
+
+/**
+ * Run the {@link RepositoryTest}s.
+ * @author Jakob Frank <ja...@apache.org>
+ *
+ */
+@RunWith(KiWiDatabaseRunner.class)
+public class EmbeddedRepositoryTest extends RepositoryTest {
+
+ private final KiWiConfiguration config;
+
+ private KiWiStore store;
+
+ public EmbeddedRepositoryTest(KiWiConfiguration config) {
+ this.config = config;
+ config.setClustered(true);
+ config.setClusterPort(61222);
+ config.setCacheMode(CacheMode.LOCAL);
+ config.setCacheManager(CacheManagerType.INFINISPAN_CLUSTERED);
+ }
+
+ /* (non-Javadoc)
+ * @see org.openrdf.repository.RepositoryTest#createRepository()
+ */
+ @Override
+ protected Repository createRepository() throws Exception {
+ store = new KiWiStore(config);
+ return new SailRepository(store);
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ store.getPersistence().dropDatabase();
+ super.tearDown();
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/externalizer/ExternalizerTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/externalizer/ExternalizerTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/externalizer/ExternalizerTest.java
new file mode 100644
index 0000000..7b6bb85
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/externalizer/ExternalizerTest.java
@@ -0,0 +1,254 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.test.externalizer;
+
+import org.apache.commons.lang3.RandomStringUtils;
+import org.apache.marmotta.commons.vocabulary.XSD;
+import org.apache.marmotta.kiwi.infinispan.externalizer.*;
+import org.apache.marmotta.kiwi.infinispan.remote.CustomJBossMarshaller;
+import org.apache.marmotta.kiwi.model.rdf.*;
+import org.apache.marmotta.kiwi.test.TestValueFactory;
+import org.infinispan.commons.marshall.AdvancedExternalizer;
+import org.infinispan.commons.marshall.StreamingMarshaller;
+import org.infinispan.configuration.cache.CacheMode;
+import org.infinispan.configuration.cache.Configuration;
+import org.infinispan.configuration.cache.ConfigurationBuilder;
+import org.infinispan.configuration.global.GlobalConfiguration;
+import org.infinispan.configuration.global.GlobalConfigurationBuilder;
+import org.infinispan.manager.DefaultCacheManager;
+import org.infinispan.manager.EmbeddedCacheManager;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.openrdf.model.Value;
+import org.openrdf.model.ValueFactory;
+import org.openrdf.model.vocabulary.OWL;
+import org.openrdf.model.vocabulary.RDFS;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.*;
+import java.util.Random;
+
+/**
+ * Test the different externalizer implementations we provide for Infinispan
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class ExternalizerTest {
+
+ private static ValueFactory valueFactory = new TestValueFactory();
+
+ private static Random rnd = new Random();
+
+ private static Logger log = LoggerFactory.getLogger(ExternalizerTest.class);
+
+ private static StreamingMarshaller marshaller, hotrod;
+
+
+ @BeforeClass
+ public static void setup() {
+ AdvancedExternalizer[] externalizers = new AdvancedExternalizer[] {
+ new UriExternalizer(),
+ new BNodeExternalizer(),
+ new StringLiteralExternalizer(),
+ new DateLiteralExternalizer(),
+ new BooleanLiteralExternalizer(),
+ new IntLiteralExternalizer(),
+ new DoubleLiteralExternalizer(),
+ new TripleExternalizer()
+ };
+
+
+ GlobalConfiguration globalConfiguration = new GlobalConfigurationBuilder()
+ .transport()
+ .defaultTransport()
+ .serialization()
+ .addAdvancedExternalizer(externalizers)
+ .build();
+
+ Configuration defaultConfiguration = new ConfigurationBuilder()
+ .clustering()
+ .cacheMode(CacheMode.DIST_ASYNC)
+ .build();
+
+ EmbeddedCacheManager cacheManager = new DefaultCacheManager(globalConfiguration, defaultConfiguration, true);
+
+ marshaller = cacheManager.getCache().getAdvancedCache().getComponentRegistry().getCacheMarshaller();
+
+ hotrod = new CustomJBossMarshaller();
+ }
+
+
+ @Test
+ public void testUriResource() throws Exception {
+ marshall((KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8)), new UriExternalizer());
+ }
+
+ @Test
+ public void testCompressedUriResource() throws Exception {
+ marshall((KiWiUriResource) valueFactory.createURI(XSD.Double.stringValue()), new UriExternalizer());
+ marshall((KiWiUriResource) valueFactory.createURI(RDFS.LABEL.stringValue()), new UriExternalizer());
+ marshall((KiWiUriResource) valueFactory.createURI(OWL.SAMEAS.stringValue()), new UriExternalizer());
+ }
+
+
+ @Test
+ public void testBNode() throws Exception {
+ marshall((KiWiAnonResource) valueFactory.createBNode(), new BNodeExternalizer());
+ }
+
+ @Test
+ public void testStringLiteral() throws Exception {
+ marshall((KiWiStringLiteral) valueFactory.createLiteral(RandomStringUtils.randomAscii(40)), new StringLiteralExternalizer());
+ }
+
+ @Test
+ public void testLangLiteral() throws Exception {
+ marshall((KiWiStringLiteral) valueFactory.createLiteral(RandomStringUtils.randomAscii(40),"en"), new StringLiteralExternalizer());
+ }
+
+ @Test
+ public void testTypeLiteral() throws Exception {
+ marshall((KiWiStringLiteral) valueFactory.createLiteral(RandomStringUtils.randomAscii(40),valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8))), new StringLiteralExternalizer());
+ }
+
+
+ @Test
+ public void testIntLiteral() throws Exception {
+ marshall((KiWiIntLiteral) valueFactory.createLiteral(rnd.nextInt()), new IntLiteralExternalizer());
+ }
+
+
+ @Test
+ public void testTriple() throws Exception {
+ KiWiUriResource s = (KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
+ KiWiUriResource p = (KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
+ KiWiNode o = (KiWiNode) randomNode();
+ KiWiTriple t = (KiWiTriple) valueFactory.createStatement(s,p,o);
+
+ marshall(t, new TripleExternalizer());
+ }
+
+ @Test
+ public void testPrefixCompressedTriple() throws Exception {
+ KiWiUriResource s = (KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
+ KiWiUriResource p = (KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
+ KiWiUriResource o = (KiWiUriResource) valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
+ KiWiTriple t = (KiWiTriple) valueFactory.createStatement(s,p,o);
+
+ marshall(t, new TripleExternalizer());
+ }
+
+
+ /**
+ * Run the given object through the marshaller using an in-memory stream.
+ * @param origin
+ * @param <T>
+ * @return
+ */
+ private <T> void marshall(T origin, AdvancedExternalizer<T> externalizer) throws IOException, ClassNotFoundException, InterruptedException {
+ log.info("- testing Java ObjectStream ...");
+ ByteArrayOutputStream outBytesOS = new ByteArrayOutputStream();
+ ObjectOutputStream outOS = new ObjectOutputStream(outBytesOS);
+
+ outOS.writeObject(origin);
+
+ outOS.close();
+
+ log.info(" object {}: serialized with {} bytes", origin, outBytesOS.size());
+
+
+ log.info("- testing externalizer directly ...");
+ ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream(outBytes);
+
+ externalizer.writeObject(out, origin);
+ out.close();
+
+ log.info(" object {}: serialized with {} bytes", origin, outBytes.size());
+
+ ByteArrayInputStream inBytes = new ByteArrayInputStream(outBytes.toByteArray());
+ ObjectInputStream in = new ObjectInputStream(inBytes);
+
+ T destination1 = externalizer.readObject(in);
+
+ Assert.assertEquals(origin,destination1);
+ assertEqualsId(origin,destination1);
+
+ log.info("- testing externalizer with infinispan cluster marshaller ...");
+
+ byte[] bytes = marshaller.objectToByteBuffer(origin);
+ log.info(" object {}: serialized with {} bytes", origin, bytes.length);
+
+ Object destination2 = marshaller.objectFromByteBuffer(bytes);
+
+ Assert.assertEquals(origin, destination2);
+ assertEqualsId(origin, destination2);
+
+
+
+ log.info("- testing externalizer with infinispan hotrod marshaller ...");
+
+ byte[] bytesH = hotrod.objectToByteBuffer(origin);
+ log.info(" object {}: serialized with {} bytes", origin, bytesH.length);
+
+ Object destination3 = hotrod.objectFromByteBuffer(bytesH);
+
+ Assert.assertEquals(origin, destination3);
+ assertEqualsId(origin, destination3);
+
+ }
+
+
+ /**
+ * Return a random RDF value, either a reused object (10% chance) or of any other kind.
+ * @return
+ */
+ protected Value randomNode() {
+ Value object;
+ switch(rnd.nextInt(6)) {
+ case 0: object = valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
+ break;
+ case 1: object = valueFactory.createBNode();
+ break;
+ case 2: object = valueFactory.createLiteral(RandomStringUtils.randomAscii(40));
+ break;
+ case 3: object = valueFactory.createLiteral(rnd.nextInt());
+ break;
+ case 4: object = valueFactory.createLiteral(rnd.nextDouble());
+ break;
+ case 5: object = valueFactory.createLiteral(rnd.nextBoolean());
+ break;
+ default: object = valueFactory.createURI("http://localhost/" + RandomStringUtils.randomAlphanumeric(8));
+ break;
+
+ }
+ return object;
+ }
+
+ private static <T> void assertEqualsId(T o1, T o2) {
+ if(o1 instanceof KiWiNode && o2 instanceof KiWiNode) {
+ Assert.assertEquals(((KiWiNode) o1).getId(), ((KiWiNode) o2).getId());
+ } else if(o1 instanceof KiWiTriple && o2 instanceof KiWiTriple) {
+ Assert.assertEquals(((KiWiTriple) o1).getId(), ((KiWiTriple) o2).getId());
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodClusterTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodClusterTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodClusterTest.java
new file mode 100644
index 0000000..3f4fa2a
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodClusterTest.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.test.remote;
+
+import org.apache.marmotta.kiwi.config.CacheManagerType;
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+import org.apache.marmotta.kiwi.test.cluster.BaseClusterTest;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class HotRodClusterTest extends BaseClusterTest {
+
+ private static Logger log = LoggerFactory.getLogger(HotRodClusterTest.class);
+
+
+ @ClassRule
+ public static HotRodServerRule hotrod1 = new HotRodServerRule(61222);
+
+ @ClassRule
+ public static HotRodServerRule hotrod2 = new HotRodServerRule(61223);
+
+ @ClassRule
+ public static HotRodServerRule hotrod3 = new HotRodServerRule(61224);
+
+ @BeforeClass
+ public static void setup() {
+ ClusterTestSupport s = new ClusterTestSupport(CacheManagerType.INFINISPAN_HOTROD);
+
+ KiWiConfiguration base = s.buildBaseConfiguration();
+ base.setClusterAddress("127.0.0.1");
+ s.setup(base);
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodPersistenceTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodPersistenceTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodPersistenceTest.java
new file mode 100644
index 0000000..406fa9c
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodPersistenceTest.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.test.remote;
+
+import org.apache.marmotta.kiwi.config.CacheManagerType;
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+import org.apache.marmotta.kiwi.test.PersistenceTest;
+import org.junit.ClassRule;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class HotRodPersistenceTest extends PersistenceTest {
+
+ @ClassRule
+ public static HotRodServerRule hotrod = new HotRodServerRule(61222);
+
+ public HotRodPersistenceTest(KiWiConfiguration kiwiConfig) {
+ super(kiwiConfig);
+
+ kiwiConfig.setClusterAddress("127.0.0.1");
+ kiwiConfig.setClusterPort(61222);
+ kiwiConfig.setCacheManager(CacheManagerType.INFINISPAN_HOTROD);
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryConnectionTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryConnectionTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryConnectionTest.java
new file mode 100644
index 0000000..198c44c
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryConnectionTest.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.test.remote;
+
+import org.apache.marmotta.kiwi.config.CacheManagerType;
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+import org.apache.marmotta.kiwi.sail.KiWiStore;
+import org.apache.marmotta.kiwi.test.junit.KiWiDatabaseRunner;
+import org.junit.ClassRule;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.openrdf.repository.Repository;
+import org.openrdf.repository.RepositoryConnectionTest;
+import org.openrdf.repository.sail.SailRepository;
+
+/**
+ * Run the {@link org.openrdf.repository.RepositoryConnectionTest}s.
+ * @author Jakob Frank <ja...@apache.org>
+ *
+ */
+@RunWith(KiWiDatabaseRunner.class)
+public class HotRodRepositoryConnectionTest extends RepositoryConnectionTest {
+
+ @ClassRule
+ public static HotRodServerRule hotrod = new HotRodServerRule(61222);
+
+ private final KiWiConfiguration config;
+
+ public HotRodRepositoryConnectionTest(KiWiConfiguration config) {
+ this.config = config;
+ config.setClusterAddress("127.0.0.1");
+ config.setClustered(true);
+ config.setClusterPort(61222);
+ config.setCacheManager(CacheManagerType.INFINISPAN_HOTROD);
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.openrdf.repository.RepositoryConnectionTest#createRepository()
+ */
+ @Override
+ protected Repository createRepository() throws Exception {
+ hotrod.clearAll();
+
+ config.setDefaultContext(null);
+ KiWiStore store = new KiWiStore(config);
+ store.setDropTablesOnShutdown(true);
+ return new SailRepository(store);
+ }
+
+ @Ignore
+ @Test
+ @Override
+ public void testOrderByQueriesAreInterruptable() throws Exception {
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryTest.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryTest.java
new file mode 100644
index 0000000..6d1cc2f
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodRepositoryTest.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.test.remote;
+
+import org.apache.marmotta.kiwi.config.CacheManagerType;
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+import org.apache.marmotta.kiwi.sail.KiWiStore;
+import org.apache.marmotta.kiwi.test.junit.KiWiDatabaseRunner;
+import org.junit.ClassRule;
+import org.junit.runner.RunWith;
+import org.openrdf.repository.Repository;
+import org.openrdf.repository.RepositoryTest;
+import org.openrdf.repository.sail.SailRepository;
+
+/**
+ * Run the {@link org.openrdf.repository.RepositoryTest}s.
+ * @author Jakob Frank <ja...@apache.org>
+ *
+ */
+@RunWith(KiWiDatabaseRunner.class)
+public class HotRodRepositoryTest extends RepositoryTest {
+
+ @ClassRule
+ public static HotRodServerRule hotrod = new HotRodServerRule(61222);
+
+ private final KiWiConfiguration config;
+
+ private KiWiStore store;
+
+ public HotRodRepositoryTest(KiWiConfiguration config) {
+ this.config = config;
+
+ config.setClusterAddress("127.0.0.1");
+ config.setClustered(true);
+ config.setClusterPort(61222);
+ config.setCacheManager(CacheManagerType.INFINISPAN_HOTROD);
+ }
+
+
+
+ /* (non-Javadoc)
+ * @see org.openrdf.repository.RepositoryTest#createRepository()
+ */
+ @Override
+ protected Repository createRepository() throws Exception {
+ store = new KiWiStore(config);
+ return new SailRepository(store);
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ store.getPersistence().dropDatabase();
+ super.tearDown();
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodServerRule.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodServerRule.java b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodServerRule.java
new file mode 100644
index 0000000..0bef0ee
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-infinispan/src/test/java/org/apache/marmotta/kiwi/test/remote/HotRodServerRule.java
@@ -0,0 +1,178 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.kiwi.test.remote;
+
+import org.apache.marmotta.kiwi.caching.CacheManager;
+import org.apache.marmotta.kiwi.infinispan.embedded.InfinispanEmbeddedCacheManager;
+import org.apache.marmotta.kiwi.infinispan.remote.CustomJBossMarshaller;
+import org.infinispan.Cache;
+import org.infinispan.client.hotrod.RemoteCache;
+import org.infinispan.client.hotrod.RemoteCacheManager;
+import org.infinispan.commons.api.BasicCacheContainer;
+import org.infinispan.commons.equivalence.ByteArrayEquivalence;
+import org.infinispan.configuration.cache.CacheMode;
+import org.infinispan.configuration.cache.Configuration;
+import org.infinispan.configuration.cache.ConfigurationBuilder;
+import org.infinispan.configuration.global.GlobalConfiguration;
+import org.infinispan.configuration.global.GlobalConfigurationBuilder;
+import org.infinispan.manager.DefaultCacheManager;
+import org.infinispan.manager.EmbeddedCacheManager;
+import org.infinispan.server.hotrod.HotRodServer;
+import org.infinispan.server.hotrod.configuration.HotRodServerConfiguration;
+import org.infinispan.server.hotrod.configuration.HotRodServerConfigurationBuilder;
+import org.junit.Assert;
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class HotRodServerRule implements TestRule {
+
+ HotRodServer server;
+
+ int port;
+
+ public HotRodServerRule(int port) {
+ this.port = port;
+ }
+
+
+ /**
+ * Modifies the method-running {@link org.junit.runners.model.Statement} to implement this
+ * test-running rule.
+ *
+ * @param base The {@link org.junit.runners.model.Statement} to be modified
+ * @param description A {@link org.junit.runner.Description} of the test implemented in {@code base}
+ * @return a new statement, which may be the same as {@code base},
+ * a wrapper around {@code base}, or a completely new Statement.
+ */
+ @Override
+ public Statement apply(final Statement base, Description description) {
+ return new Statement() {
+ @Override
+ public void evaluate() throws Throwable {
+ server = buildServer(port);
+
+ try {
+ base.evaluate();
+ } finally {
+ server.stop();
+ }
+ }
+ };
+ }
+
+
+ public void clearAll() {
+ for(String s : server.getCacheManager().getCacheNames()) {
+ Cache c = server.getCacheManager().getCache(s);
+ c.clear();
+ }
+ }
+
+ private static HotRodServer buildServer(int port) {
+ HotRodServer hotRodServer = new HotRodServer() {
+ @Override
+ public ConfigurationBuilder createTopologyCacheConfig(long distSyncTimeout) {
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ }
+
+ ConfigurationBuilder c = super.createTopologyCacheConfig(distSyncTimeout);
+ c.transaction().syncCommitPhase(false).syncRollbackPhase(false);
+ return c;
+ }
+ };
+
+ HotRodServerConfiguration hotrodConfig = new HotRodServerConfigurationBuilder()
+ .host("127.0.0.1")
+ .port(port)
+ .proxyHost("127.0.0.1")
+ .proxyPort(port)
+ .topologyStateTransfer(false)
+ .defaultCacheName(BasicCacheContainer.DEFAULT_CACHE_NAME)
+ .idleTimeout(0)
+ .workerThreads(2)
+ .build(true);
+
+
+ GlobalConfiguration globalConfiguration = new GlobalConfigurationBuilder()
+ .classLoader(InfinispanEmbeddedCacheManager.class.getClassLoader())
+ .globalJmxStatistics()
+ .jmxDomain("org.apache.marmotta.kiwi")
+ .allowDuplicateDomains(true)
+ .build();
+
+ Configuration defaultConfiguration = new ConfigurationBuilder()
+ .clustering()
+ .cacheMode(CacheMode.LOCAL)
+ .sync()
+ .dataContainer()
+ .keyEquivalence(ByteArrayEquivalence.INSTANCE)
+ .valueEquivalence(ByteArrayEquivalence.INSTANCE)
+ .build();
+
+ EmbeddedCacheManager cacheManager = new DefaultCacheManager(globalConfiguration, defaultConfiguration, true);
+ cacheManager.defineConfiguration(CacheManager.NODE_CACHE, defaultConfiguration);
+ cacheManager.defineConfiguration(CacheManager.TRIPLE_CACHE, defaultConfiguration);
+ cacheManager.defineConfiguration(CacheManager.URI_CACHE, defaultConfiguration);
+ cacheManager.defineConfiguration(CacheManager.BNODE_CACHE, defaultConfiguration);
+ cacheManager.defineConfiguration(CacheManager.LITERAL_CACHE, defaultConfiguration);
+ cacheManager.defineConfiguration(CacheManager.NS_PREFIX_CACHE, defaultConfiguration);
+ cacheManager.defineConfiguration(CacheManager.NS_URI_CACHE, defaultConfiguration);
+ cacheManager.defineConfiguration(CacheManager.REGISTRY_CACHE, defaultConfiguration);
+ cacheManager.getCache(CacheManager.NODE_CACHE, true);
+ cacheManager.getCache(CacheManager.TRIPLE_CACHE, true);
+ cacheManager.getCache(CacheManager.URI_CACHE, true);
+ cacheManager.getCache(CacheManager.BNODE_CACHE, true);
+ cacheManager.getCache(CacheManager.LITERAL_CACHE, true);
+ cacheManager.getCache(CacheManager.NS_PREFIX_CACHE, true);
+ cacheManager.getCache(CacheManager.NS_URI_CACHE, true);
+ cacheManager.getCache(CacheManager.REGISTRY_CACHE, true);
+
+ hotRodServer.start(hotrodConfig, cacheManager);
+
+ // test if cache is available
+ org.infinispan.client.hotrod.configuration.Configuration remoteCfg = new org.infinispan.client.hotrod.configuration.ConfigurationBuilder()
+ .addServer()
+ .host("127.0.0.1")
+ .port(port)
+ .marshaller(new CustomJBossMarshaller())
+ .pingOnStartup(true)
+ .build(true);
+
+
+ RemoteCacheManager remoteCacheManager = new RemoteCacheManager(remoteCfg);
+ Assert.assertTrue(remoteCacheManager.isStarted());
+
+ RemoteCache<String, String> m = remoteCacheManager.getCache();
+
+ m.put("xyz", "abc");
+ String n = m.get("xyz");
+
+ Assert.assertNotNull(n);
+
+ return hotRodServer;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04230ab/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/PersistenceTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/PersistenceTest.java b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/PersistenceTest.java
index 9eff945..a3aa52a 100644
--- a/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/PersistenceTest.java
+++ b/libraries/kiwi/kiwi-triplestore/src/test/java/org/apache/marmotta/kiwi/test/PersistenceTest.java
@@ -113,7 +113,7 @@ public class PersistenceTest {
// needs to be equal, and should also be the identical object!
Assert.assertEquals(uri,testUri1);
- //Assert.assertTrue(uri == testUri1);
+ Assert.assertEquals(uri.getId(), testUri1.getId());
connection.commit();
@@ -121,14 +121,14 @@ public class PersistenceTest {
// needs to be equal, and should also be the identical object!
Assert.assertEquals(uri,testUri2);
- //Assert.assertTrue(uri == testUri2);
+ Assert.assertEquals(uri.getId(), testUri2.getId());
KiWiNode testUri3 = connection.loadUriResource(uri.stringValue());
// needs to be equal, and should also be the identical object!
Assert.assertEquals(uri,testUri3);
- //Assert.assertTrue(uri == testUri3);
+ Assert.assertEquals(uri.getId(), testUri3.getId());
connection.commit();
@@ -142,13 +142,13 @@ public class PersistenceTest {
// needs to be equal, but now it should not be the same object!
Assert.assertEquals(uri,testUri4);
- //Assert.assertTrue(uri != testUri4);
+ Assert.assertEquals(uri.getId(), testUri4.getId());
KiWiNode testUri5 = connection.loadUriResource(uri.stringValue());
// needs to be equal, but now it should not be the same object!
Assert.assertEquals(uri,testUri5);
- //Assert.assertTrue(uri != testUri5);
+ Assert.assertEquals(uri.getId(), testUri5.getId());
connection.commit();
@@ -157,7 +157,7 @@ public class PersistenceTest {
ResultSet result = checkNodeStmt.executeQuery();
Assert.assertTrue(result.next());
- Assert.assertEquals((long) uri.getId(), result.getLong("id"));
+ Assert.assertEquals(uri.getId(), result.getLong("id"));
Assert.assertEquals(uri.stringValue(),result.getString("svalue"));
Assert.assertEquals("uri",result.getString("ntype"));
@@ -190,7 +190,7 @@ public class PersistenceTest {
// needs to be equal, and should also be the identical object!
Assert.assertEquals(bnode,testBNode1);
- //Assert.assertTrue(bnode == testBNode1);
+ Assert.assertEquals(bnode.getId(), testBNode1.getId());
connection.commit();
@@ -198,14 +198,14 @@ public class PersistenceTest {
// needs to be equal, and should also be the identical object!
Assert.assertEquals(bnode,testBNode2);
- //Assert.assertTrue(bnode == testBNode2);
+ Assert.assertEquals(bnode.getId(), testBNode2.getId());
KiWiNode testBNode3 = connection.loadAnonResource(bnode.stringValue());
// needs to be equal, and should also be the identical object!
Assert.assertEquals(bnode,testBNode3);
- //Assert.assertTrue(bnode == testBNode3);
+ Assert.assertEquals(bnode.getId(), testBNode3.getId());
connection.commit();
@@ -218,13 +218,13 @@ public class PersistenceTest {
// needs to be equal, but now it should not be the same object!
Assert.assertEquals(bnode,testBNode4);
- //Assert.assertTrue(bnode != testBNode4);
+ Assert.assertEquals(bnode.getId(), testBNode4.getId());
KiWiNode testBNode5 = connection.loadAnonResource(bnode.stringValue());
// needs to be equal, but now it should not be the same object!
Assert.assertEquals(bnode,testBNode5);
- //Assert.assertTrue(bnode != testBNode5);
+ Assert.assertEquals(bnode.getId(), testBNode5.getId());
connection.commit();
@@ -269,7 +269,7 @@ public class PersistenceTest {
// needs to be equal, and should also be the identical object!
Assert.assertEquals(literal,testLiteral1);
- //Assert.assertTrue(literal == testLiteral1);
+ Assert.assertEquals(literal.getId(), testLiteral1.getId());
connection.commit();
@@ -277,13 +277,13 @@ public class PersistenceTest {
// needs to be equal, and should also be the identical object!
Assert.assertEquals(literal,testLiteral2);
- //Assert.assertTrue(literal == testLiteral2);
+ Assert.assertEquals(literal.getId(), testLiteral2.getId());
KiWiNode testLiteral3 = connection.loadLiteral(literal.stringValue(), null, stype);
// needs to be equal, and should also be the identical object!
Assert.assertEquals(literal,testLiteral3);
- //Assert.assertTrue(literal == testLiteral3);
+ Assert.assertEquals(literal.getId(), testLiteral3.getId());
connection.commit();
@@ -294,13 +294,13 @@ public class PersistenceTest {
// needs to be equal, but now it should not be the same object!
Assert.assertEquals(literal,testLiteral4);
- //Assert.assertTrue(literal != testLiteral4);
+ Assert.assertEquals(literal.getId(), testLiteral4.getId());
KiWiNode testLiteral5 = connection.loadLiteral(literal.stringValue(),null,stype);
// needs to be equal, but now it should not be the same object!
Assert.assertEquals(literal,testLiteral5);
- //Assert.assertTrue(literal != testLiteral5);
+ Assert.assertEquals(literal.getId(), testLiteral5.getId());
connection.commit();
@@ -348,7 +348,7 @@ public class PersistenceTest {
// needs to be equal, and should also be the identical object!
Assert.assertEquals(literal,testLiteral1);
- //Assert.assertTrue(literal == testLiteral1);
+ Assert.assertEquals(literal.getId(), testLiteral1.getId());
connection.commit();
@@ -356,13 +356,13 @@ public class PersistenceTest {
// needs to be equal, and should also be the identical object!
Assert.assertEquals(literal,testLiteral2);
- //Assert.assertTrue(literal == testLiteral2);
+ Assert.assertEquals(literal.getId(), testLiteral2.getId());
KiWiNode testLiteral3 = connection.loadLiteral(literal.stringValue(),Locale.ENGLISH.getLanguage(),null);
// needs to be equal, and should also be the identical object!
Assert.assertEquals(literal,testLiteral3);
- //Assert.assertTrue(literal == testLiteral3);
+ Assert.assertEquals(literal.getId(), testLiteral3.getId());
connection.commit();
@@ -373,13 +373,13 @@ public class PersistenceTest {
// needs to be equal, but now it should not be the same object!
Assert.assertEquals(literal,testLiteral4);
- //Assert.assertTrue(literal != testLiteral4);
+ Assert.assertEquals(literal.getId(), testLiteral4.getId());
KiWiNode testLiteral5 = connection.loadLiteral(literal.stringValue(),Locale.ENGLISH.getLanguage(),null);
// needs to be equal, but now it should not be the same object!
Assert.assertEquals(literal,testLiteral5);
- //Assert.assertTrue(literal != testLiteral5);
+ Assert.assertEquals(literal.getId(), testLiteral5.getId());
connection.commit();
@@ -427,7 +427,7 @@ public class PersistenceTest {
// needs to be equal, and should also be the identical object!
Assert.assertEquals(literal,testLiteral1);
Assert.assertEquals(uri,((KiWiLiteral)testLiteral1).getType());
- //Assert.assertTrue(literal == testLiteral1);
+ Assert.assertEquals(literal.getId(), testLiteral1.getId());
connection.commit();
@@ -436,14 +436,14 @@ public class PersistenceTest {
// needs to be equal, and should also be the identical object!
Assert.assertEquals(literal,testLiteral2);
Assert.assertEquals(uri,((KiWiLiteral)testLiteral2).getType());
- //Assert.assertTrue(literal == testLiteral2);
+ Assert.assertEquals(literal.getId(), testLiteral2.getId());
KiWiNode testLiteral3 = connection.loadLiteral(literal.stringValue(),null,uri);
// needs to be equal, and should also be the identical object!
Assert.assertEquals(literal,testLiteral3);
Assert.assertEquals(uri,((KiWiLiteral)testLiteral3).getType());
- //Assert.assertTrue(literal == testLiteral3);
+ Assert.assertEquals(literal.getId(), testLiteral3.getId());
connection.commit();
@@ -455,14 +455,14 @@ public class PersistenceTest {
// needs to be equal, but now it should not be the same object!
Assert.assertEquals(literal,testLiteral4);
Assert.assertEquals(uri,((KiWiLiteral)testLiteral4).getType());
- //Assert.assertTrue(literal != testLiteral4);
+ Assert.assertEquals(literal.getId(), testLiteral4.getId());
KiWiNode testLiteral5 = connection.loadLiteral(literal.stringValue(),null,uri);
// needs to be equal, but now it should not be the same object!
Assert.assertEquals(literal,testLiteral5);
Assert.assertEquals(uri,((KiWiLiteral)testLiteral5).getType());
- //Assert.assertTrue(literal != testLiteral5);
+ Assert.assertEquals(literal.getId(), testLiteral5.getId());
connection.commit();