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/17 11:23:01 UTC

[10/32] git commit: started implementing Hazelcast cache manager

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/develop
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);
+    }
 }