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:18 UTC
[03/21] git commit: started working on cleaner cache API for KiWi
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;
- }
-}