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:22:52 UTC
[01/32] git commit: wrong version number - update to
3.1.0-incubating-SNAPSHOT
Repository: marmotta
Updated Branches:
refs/heads/develop d5b0c6d2f -> 374513a21
wrong version number - update to 3.1.0-incubating-SNAPSHOT
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/cdb3223d
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/cdb3223d
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/cdb3223d
Branch: refs/heads/develop
Commit: cdb3223db7439a9f8fd7fb5159ffd52f6da0ecb7
Parents: 8e87a83
Author: Dietmar Glachs <dg...@gmail.com>
Authored: Mon Sep 23 12:16:34 2013 +0200
Committer: Dietmar Glachs <dg...@gmail.com>
Committed: Mon Sep 23 12:16:34 2013 +0200
----------------------------------------------------------------------
client/marmotta-client-js-sample-webapp/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/cdb3223d/client/marmotta-client-js-sample-webapp/pom.xml
----------------------------------------------------------------------
diff --git a/client/marmotta-client-js-sample-webapp/pom.xml b/client/marmotta-client-js-sample-webapp/pom.xml
index 69bb541..afe52bf 100644
--- a/client/marmotta-client-js-sample-webapp/pom.xml
+++ b/client/marmotta-client-js-sample-webapp/pom.xml
@@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.marmotta</groupId>
<artifactId>marmotta-parent</artifactId>
- <version>3.0.0-incubating-SNAPSHOT</version>
+ <version>3.1.0-incubating-SNAPSHOT</version>
<relativePath>../../parent/pom.xml</relativePath>
</parent>
[09/32] 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/develop
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);
[24/32] git commit: simplified KiWiNode I/O by moving all redundant
methods to a separate class
Posted by ss...@apache.org.
simplified KiWiNode I/O by moving all redundant methods to a separate class
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/7c40b532
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/7c40b532
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/7c40b532
Branch: refs/heads/develop
Commit: 7c40b532b9a3dd1699418f3784c41a7a24101704
Parents: 766bef0
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Wed Mar 5 14:36:14 2014 +0100
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Wed Mar 5 14:36:14 2014 +0100
----------------------------------------------------------------------
.../hazelcast/serializer/BNodeSerializer.java | 17 +-
.../serializer/BooleanLiteralSerializer.java | 22 +-
.../serializer/DateLiteralSerializer.java | 22 +-
.../serializer/DoubleLiteralSerializer.java | 22 +-
.../serializer/IntLiteralSerializer.java | 22 +-
.../serializer/StringLiteralSerializer.java | 29 +-
.../hazelcast/serializer/TripleSerializer.java | 101 +--
.../hazelcast/serializer/UriSerializer.java | 86 +--
.../externalizer/BNodeExternalizer.java | 17 +-
.../BooleanLiteralExternalizer.java | 22 +-
.../externalizer/DateLiteralExternalizer.java | 22 +-
.../externalizer/DoubleLiteralExternalizer.java | 22 +-
.../externalizer/IntLiteralExternalizer.java | 22 +-
.../externalizer/StringLiteralExternalizer.java | 29 +-
.../externalizer/TripleExternalizer.java | 99 +--
.../externalizer/UriExternalizer.java | 85 +--
libraries/kiwi/kiwi-loader/pom.xml | 9 -
.../org/apache/marmotta/kiwi/io/KiWiIO.java | 636 +++++++++++++++++++
.../LDCachingKiWiPersistenceConnection.java | 6 +-
.../ldcache/services/test/LDCacheKiWiTest.java | 5 +
20 files changed, 692 insertions(+), 603 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/7c40b532/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 e105b39..4ec58b4 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,11 +20,10 @@ 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.io.KiWiIO;
import org.apache.marmotta.kiwi.model.rdf.KiWiAnonResource;
import java.io.IOException;
-import java.util.Date;
/**
* Add file description here!
@@ -42,22 +41,12 @@ public class BNodeSerializer implements StreamSerializer<KiWiAnonResource> {
@Override
public void write(ObjectDataOutput output, KiWiAnonResource object) throws IOException {
- output.writeLong(object.getId());
- DataIO.writeString(output, object.stringValue());
- output.writeLong(object.getCreated().getTime());
+ KiWiIO.writeBNode(output, object);
}
@Override
public KiWiAnonResource read(ObjectDataInput input) throws IOException {
- long id = input.readLong();
- String anonId = DataIO.readString(input);
-
- Date created = new Date(input.readLong());
-
- KiWiAnonResource r = new KiWiAnonResource(anonId,created);
- r.setId(id);
-
- return r;
+ return KiWiIO.readBNode(input);
}
@Override
http://git-wip-us.apache.org/repos/asf/marmotta/blob/7c40b532/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
index 0246e35..5792b84 100644
--- 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
@@ -20,11 +20,10 @@ 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.io.KiWiIO;
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!
@@ -41,27 +40,12 @@ public class BooleanLiteralSerializer implements StreamSerializer<KiWiBooleanLit
@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());
-
+ KiWiIO.writeBooleanLiteral(output,object);
}
@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;
+ return KiWiIO.readBooleanLiteral(input);
}
@Override
http://git-wip-us.apache.org/repos/asf/marmotta/blob/7c40b532/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
index 1ddd75d..209378c 100644
--- 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
@@ -20,11 +20,10 @@ 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.io.KiWiIO;
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!
@@ -41,27 +40,12 @@ public class DateLiteralSerializer implements StreamSerializer<KiWiDateLiteral>
@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());
-
+ KiWiIO.writeDateLiteral(output,object);
}
@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;
+ return KiWiIO.readDateLiteral(input);
}
@Override
http://git-wip-us.apache.org/repos/asf/marmotta/blob/7c40b532/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
index 61ba8e4..3a4719a 100644
--- 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
@@ -20,11 +20,10 @@ 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.io.KiWiIO;
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!
@@ -40,27 +39,12 @@ public class DoubleLiteralSerializer implements StreamSerializer<KiWiDoubleLiter
@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());
-
+ KiWiIO.writeDoubleLiteral(output,object);
}
@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;
+ return KiWiIO.readDoubleLiteral(input);
}
@Override
http://git-wip-us.apache.org/repos/asf/marmotta/blob/7c40b532/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
index 12d49b4..4d77667 100644
--- 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
@@ -20,11 +20,10 @@ 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.io.KiWiIO;
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!
@@ -41,27 +40,12 @@ public class IntLiteralSerializer implements StreamSerializer<KiWiIntLiteral> {
@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());
-
+ KiWiIO.writeIntLiteral(output,object);
}
@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;
+ return KiWiIO.readIntLiteral(input);
}
@Override
http://git-wip-us.apache.org/repos/asf/marmotta/blob/7c40b532/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
index 6531aa0..687c321 100644
--- 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
@@ -20,13 +20,10 @@ 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.io.KiWiIO;
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!
@@ -43,32 +40,12 @@ public class StringLiteralSerializer implements StreamSerializer<KiWiStringLiter
@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());
-
+ KiWiIO.writeStringLiteral(output,object);
}
@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;
+ return KiWiIO.readStringLiteral(input);
}
@Override
http://git-wip-us.apache.org/repos/asf/marmotta/blob/7c40b532/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
index cb2de2a..fa5b312 100644
--- 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
@@ -20,15 +20,10 @@ 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.io.KiWiIO;
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
@@ -36,12 +31,6 @@ import java.util.Date;
*/
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;
@@ -49,96 +38,12 @@ public class TripleSerializer implements StreamSerializer<KiWiTriple> {
@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);
- }
+ KiWiIO.writeTriple(output,object);
}
@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;
+ return KiWiIO.readTriple(input);
}
@Override
http://git-wip-us.apache.org/repos/asf/marmotta/blob/7c40b532/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
index 0f235d5..5418436 100644
--- 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
@@ -20,13 +20,10 @@ 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.io.KiWiIO;
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!
@@ -35,16 +32,6 @@ import java.util.Date;
*/
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;
@@ -52,79 +39,12 @@ public class UriSerializer implements StreamSerializer<KiWiUriResource> {
@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());
+ KiWiIO.writeURI(output, object);
}
@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;
+ return KiWiIO.readURI(input);
}
@Override
http://git-wip-us.apache.org/repos/asf/marmotta/blob/7c40b532/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 e9ad806..d94c9ce 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,7 +17,7 @@
package org.apache.marmotta.kiwi.infinispan.externalizer;
-import org.apache.marmotta.commons.io.DataIO;
+import org.apache.marmotta.kiwi.io.KiWiIO;
import org.apache.marmotta.kiwi.model.rdf.KiWiAnonResource;
import org.infinispan.commons.marshall.AdvancedExternalizer;
import org.infinispan.commons.util.Util;
@@ -25,7 +25,6 @@ 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;
/**
@@ -48,22 +47,12 @@ public class BNodeExternalizer extends BaseExternalizer<KiWiAnonResource> implem
@Override
public void writeObject(ObjectOutput output, KiWiAnonResource object) throws IOException {
- output.writeLong(object.getId());
- DataIO.writeString(output, object.stringValue());
- output.writeLong(object.getCreated().getTime());
+ KiWiIO.writeBNode(output, object);
}
@Override
public KiWiAnonResource readObject(ObjectInput input) throws IOException, ClassNotFoundException {
- long id = input.readLong();
- String anonId = DataIO.readString(input);
-
- Date created = new Date(input.readLong());
-
- KiWiAnonResource r = new KiWiAnonResource(anonId,created);
- r.setId(id);
-
- return r;
+ return KiWiIO.readBNode(input);
}
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/7c40b532/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
index 73793bf..a079eeb 100644
--- 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
@@ -17,15 +17,14 @@
package org.apache.marmotta.kiwi.infinispan.externalizer;
+import org.apache.marmotta.kiwi.io.KiWiIO;
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;
/**
@@ -47,26 +46,11 @@ public class BooleanLiteralExternalizer extends BaseExternalizer<KiWiBooleanLite
@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());
-
+ KiWiIO.writeBooleanLiteral(output,object);
}
@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;
+ return KiWiIO.readBooleanLiteral(input);
}
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/7c40b532/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
index 532d70e..b4f804c 100644
--- 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
@@ -17,15 +17,14 @@
package org.apache.marmotta.kiwi.infinispan.externalizer;
+import org.apache.marmotta.kiwi.io.KiWiIO;
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;
/**
@@ -47,26 +46,11 @@ public class DateLiteralExternalizer extends BaseExternalizer<KiWiDateLiteral> i
@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());
-
+ KiWiIO.writeDateLiteral(output,object);
}
@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;
+ return KiWiIO.readDateLiteral(input);
}
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/7c40b532/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
index 66b40f9..d5748b5 100644
--- 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
@@ -17,15 +17,14 @@
package org.apache.marmotta.kiwi.infinispan.externalizer;
+import org.apache.marmotta.kiwi.io.KiWiIO;
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;
/**
@@ -47,26 +46,11 @@ public class DoubleLiteralExternalizer extends BaseExternalizer<KiWiDoubleLitera
@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());
-
+ KiWiIO.writeDoubleLiteral(output,object);
}
@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;
+ return KiWiIO.readDoubleLiteral(input);
}
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/7c40b532/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
index 3f2052a..82eb719 100644
--- 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
@@ -17,15 +17,14 @@
package org.apache.marmotta.kiwi.infinispan.externalizer;
+import org.apache.marmotta.kiwi.io.KiWiIO;
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;
/**
@@ -47,26 +46,11 @@ public class IntLiteralExternalizer extends BaseExternalizer<KiWiIntLiteral> imp
@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());
-
+ KiWiIO.writeIntLiteral(output,object);
}
@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;
+ return KiWiIO.readIntLiteral(input);
}
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/7c40b532/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
index 015698c..62f9da2 100644
--- 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
@@ -17,17 +17,14 @@
package org.apache.marmotta.kiwi.infinispan.externalizer;
-import org.apache.marmotta.commons.io.DataIO;
+import org.apache.marmotta.kiwi.io.KiWiIO;
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;
/**
@@ -49,31 +46,11 @@ public class StringLiteralExternalizer extends BaseExternalizer<KiWiStringLitera
@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());
-
+ KiWiIO.writeStringLiteral(output,object);
}
@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;
+ return KiWiIO.readStringLiteral(input);
}
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/7c40b532/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
index 562475d..97c24ea 100644
--- 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
@@ -17,19 +17,14 @@
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.io.KiWiIO;
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;
/**
@@ -39,10 +34,6 @@ import java.util.Set;
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);
@@ -55,95 +46,11 @@ public class TripleExternalizer extends BaseExternalizer<KiWiTriple> implements
@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);
- }
+ KiWiIO.writeTriple(output,object);
}
@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;
+ return KiWiIO.readTriple(input);
}
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/7c40b532/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
index cfd9dc2..d29f87a 100644
--- 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
@@ -17,17 +17,14 @@
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.io.KiWiIO;
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;
/**
@@ -37,15 +34,6 @@ import java.util.Set;
*/
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);
@@ -58,79 +46,12 @@ public class UriExternalizer extends BaseExternalizer<KiWiUriResource> implement
@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());
+ KiWiIO.writeURI(output, object);
}
@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;
+ return KiWiIO.readURI(input);
}
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/7c40b532/libraries/kiwi/kiwi-loader/pom.xml
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-loader/pom.xml b/libraries/kiwi/kiwi-loader/pom.xml
index 9d13fb1..3913a72 100644
--- a/libraries/kiwi/kiwi-loader/pom.xml
+++ b/libraries/kiwi/kiwi-loader/pom.xml
@@ -81,15 +81,6 @@
<type>test-jar</type>
</dependency>
<dependency>
- <!-- License: CPL-1.0 http://www.opensource.org/licenses/cpl1.0
- As a MAVEN dependency it is not included in a source release. As a TEST dependency
- it is not included in a BINARY release, so no need to mention in N&L. -->
- <groupId>com.github.stefanbirkner</groupId>
- <artifactId>system-rules</artifactId>
- <version>1.4.0</version>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.openrdf.sesame</groupId>
<artifactId>sesame-rio-rdfxml</artifactId>
<scope>test</scope>
http://git-wip-us.apache.org/repos/asf/marmotta/blob/7c40b532/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/io/KiWiIO.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/io/KiWiIO.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/io/KiWiIO.java
new file mode 100644
index 0000000..584b22a
--- /dev/null
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/io/KiWiIO.java
@@ -0,0 +1,636 @@
+/*
+ * 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.io;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.marmotta.commons.io.DataIO;
+import org.apache.marmotta.commons.vocabulary.XSD;
+import org.apache.marmotta.kiwi.model.rdf.*;
+import org.openrdf.model.vocabulary.*;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class KiWiIO {
+
+ 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;
+
+
+ private static final int TYPE_URI = 1;
+ private static final int TYPE_BNODE = 2;
+ private static final int TYPE_BOOLEAN = 3;
+ private static final int TYPE_DATE = 4;
+ private static final int TYPE_DOUBLE = 5;
+ private static final int TYPE_INT = 6;
+ private static final int TYPE_STRING = 7;
+
+
+ public static final int MODE_DEFAULT = 1;
+ public static final int MODE_PREFIX = 2;
+
+
+ private static Map<Class<? extends KiWiNode>, Integer> classTable = new HashMap<>();
+ static {
+ classTable.put(KiWiUriResource.class, TYPE_URI);
+ classTable.put(KiWiAnonResource.class, TYPE_BNODE);
+ classTable.put(KiWiBooleanLiteral.class, TYPE_BOOLEAN);
+ classTable.put(KiWiDateLiteral.class, TYPE_DATE);
+ classTable.put(KiWiDoubleLiteral.class, TYPE_DOUBLE);
+ classTable.put(KiWiIntLiteral.class, TYPE_INT);
+ classTable.put(KiWiStringLiteral.class, TYPE_STRING);
+ }
+
+ /**
+ * Efficiently serialize a KiWiNode to a DataOutput destination. The type of node will be encoded with a single
+ * byte usinbg the TYPE_* constants defined in this class
+ *
+ * @param output DataOutput destination
+ * @param node KiWiNode to serialize
+ * @throws IOException
+ */
+ public static void writeNode(DataOutput output, KiWiNode node) throws IOException {
+ if(node == null) {
+ output.writeByte(0);
+ } else {
+ int type = classTable.get(node.getClass());
+ output.writeByte(type);
+ switch (type) {
+ case TYPE_URI:
+ writeURI(output, (KiWiUriResource) node);
+ break;
+ case TYPE_BNODE:
+ writeBNode(output, (KiWiAnonResource) node);
+ break;
+ case TYPE_BOOLEAN:
+ writeBooleanLiteral(output, (KiWiBooleanLiteral) node);
+ break;
+ case TYPE_DATE:
+ writeDateLiteral(output, (KiWiDateLiteral) node);
+ break;
+ case TYPE_DOUBLE:
+ writeDoubleLiteral(output, (KiWiDoubleLiteral) node);
+ break;
+ case TYPE_INT:
+ writeIntLiteral(output, (KiWiIntLiteral) node);
+ break;
+ case TYPE_STRING:
+ writeStringLiteral(output, (KiWiStringLiteral) node);
+ break;
+ default:
+ throw new IllegalArgumentException("unknown KiWiNode type: "+node.getClass());
+ }
+ }
+ }
+
+
+ /**
+ * Read a KiWiNode serialized with writeNode and return it. The type indicator is used to determine which type
+ * of resource to instantiate.
+ *
+ * @param input DataInput source
+ * @return an instance of a subclass of KiWiNode, depending on the type indicator read from the source
+ * @throws IOException
+ */
+ public static KiWiNode readNode(DataInput input) throws IOException {
+ int type = input.readByte();
+ switch (type) {
+ case 0:
+ return null;
+ case TYPE_URI:
+ return readURI(input);
+ case TYPE_BNODE:
+ return readBNode(input);
+ case TYPE_BOOLEAN:
+ return readBooleanLiteral(input);
+ case TYPE_DATE:
+ return readDateLiteral(input);
+ case TYPE_DOUBLE:
+ return readDoubleLiteral(input);
+ case TYPE_INT:
+ return readIntLiteral(input);
+ case TYPE_STRING:
+ return readStringLiteral(input);
+ default:
+ throw new IllegalArgumentException("unknown KiWiNode type: "+type);
+ }
+
+ }
+
+ /**
+ * Efficiently serialize a KiWiUriResource to a DataOutput destination, using prefix compression for commonly used
+ * prefixes.
+ *
+ * @param out DataOutput destination
+ * @param uri KiWiUriResource to serialize
+ * @throws IOException
+ */
+ public static void writeURI(DataOutput out, KiWiUriResource uri) throws IOException {
+ if(uri == null) {
+ out.writeLong(-1L);
+ } else {
+ out.writeLong(uri.getId());
+
+ // compression for commonly used constant prefixes
+ if(uri.stringValue().startsWith(XSD.NAMESPACE)) {
+ out.writeByte(PREFIX_XSD);
+ DataIO.writeString(out, uri.stringValue().substring(XSD.NAMESPACE.length()));
+ } else if(uri.stringValue().startsWith(RDF.NAMESPACE)) {
+ out.writeByte(PREFIX_RDF);
+ DataIO.writeString(out, uri.stringValue().substring(RDF.NAMESPACE.length()));
+ } else if(uri.stringValue().startsWith(RDFS.NAMESPACE)) {
+ out.writeByte(PREFIX_RDFS);
+ DataIO.writeString(out, uri.stringValue().substring(RDFS.NAMESPACE.length()));
+ } else if(uri.stringValue().startsWith(SKOS.NAMESPACE)) {
+ out.writeByte(PREFIX_SKOS);
+ DataIO.writeString(out, uri.stringValue().substring(SKOS.NAMESPACE.length()));
+ } else if(uri.stringValue().startsWith(DC.NAMESPACE)) {
+ out.writeByte(PREFIX_DC);
+ DataIO.writeString(out, uri.stringValue().substring(DC.NAMESPACE.length()));
+ } else if(uri.stringValue().startsWith(DCTERMS.NAMESPACE)) {
+ out.writeByte(PREFIX_DCT);
+ DataIO.writeString(out, uri.stringValue().substring(DCTERMS.NAMESPACE.length()));
+ } else if(uri.stringValue().startsWith(OWL.NAMESPACE)) {
+ out.writeByte(PREFIX_OWL);
+ DataIO.writeString(out, uri.stringValue().substring(OWL.NAMESPACE.length()));
+ } else {
+ out.writeByte(PREFIX_UNKNOWN);
+ DataIO.writeString(out, uri.stringValue());
+ }
+
+ out.writeLong(uri.getCreated().getTime());
+ }
+ }
+
+
+ /**
+ * Read a KiWiUriResource serialized with writeURI and return it.
+ *
+ * @param input DataInput source
+ * @return a KiWiUriResource
+ * @throws IOException
+ */
+ public static KiWiUriResource readURI(DataInput input) throws IOException {
+ long id = input.readLong();
+
+ if(id == -1) {
+ return null;
+ } else {
+
+
+ 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;
+ }
+ }
+
+
+ /**
+ * Efficiently serialize a KiWiAnonResource to a DataOutput destination.
+ *
+ * @param out the destination
+ * @param bnode the KiWiAnonResource to serialize
+ * @throws IOException
+ */
+ public static void writeBNode(DataOutput out, KiWiAnonResource bnode) throws IOException {
+ if(bnode == null) {
+ out.writeLong(-1L);
+ } else {
+ out.writeLong(bnode.getId());
+ DataIO.writeString(out, bnode.stringValue());
+ out.writeLong(bnode.getCreated().getTime());
+ }
+ }
+
+ /**
+ * Read a KiWiAnonResource serialized with writeBNode from a DataInput source
+ *
+ * @param input the source
+ * @return the de-serialized KiWiAnonResource
+ * @throws IOException
+ */
+ public static KiWiAnonResource readBNode(DataInput input) throws IOException {
+ long id = input.readLong();
+
+ if(id == -1) {
+ return null;
+ } else {
+ String anonId = DataIO.readString(input);
+
+ Date created = new Date(input.readLong());
+
+ KiWiAnonResource r = new KiWiAnonResource(anonId,created);
+ r.setId(id);
+
+ return r;
+ }
+ }
+
+
+ /**
+ * Efficiently serialize a KiWiBooleanLiteral to a DataOutput destination.
+ *
+ * @param out the destination
+ * @param literal the KiWiBooleanLiteral to serialize
+ * @throws IOException
+ */
+ public static void writeBooleanLiteral(DataOutput out, KiWiBooleanLiteral literal) throws IOException {
+ if(literal == null) {
+ out.writeLong(-1L);
+ } else {
+ out.writeLong(literal.getId());
+ out.writeBoolean(literal.booleanValue());
+ writeURI(out, literal.getType());
+ out.writeLong(literal.getCreated().getTime());
+ }
+ }
+
+
+ /**
+ * Read a KiWiBooleanLiteral serialized with writeBooleanLiteral from a DataInput source
+ *
+ * @param input the source
+ * @return the de-serialized KiWiBooleanLiteral
+ * @throws IOException
+ */
+ public static KiWiBooleanLiteral readBooleanLiteral(DataInput input) throws IOException {
+ long id = input.readLong();
+
+ if(id == -1) {
+ return null;
+ } else {
+ boolean content = input.readBoolean();
+
+ KiWiUriResource dtype = readURI(input);
+
+ Date created = new Date(input.readLong());
+
+ KiWiBooleanLiteral r = new KiWiBooleanLiteral(content, dtype, created);
+ r.setId(id);
+
+ return r;
+ }
+ }
+
+
+ /**
+ * Efficiently serialize a KiWiDateLiteral to a DataOutput destination.
+ *
+ * @param out the destination
+ * @param literal the KiWiDateLiteral to serialize
+ * @throws IOException
+ */
+ public static void writeDateLiteral(DataOutput out, KiWiDateLiteral literal) throws IOException {
+ if(literal == null) {
+ out.writeLong(-1L);
+ } else {
+ out.writeLong(literal.getId());
+ out.writeLong(literal.getDateContent().getTime());
+ writeURI(out, literal.getType());
+ out.writeLong(literal.getCreated().getTime());
+ }
+ }
+
+
+ /**
+ * Read a KiWiDateLiteral serialized with writeDateLiteral from a DataInput source
+ *
+ * @param input the source
+ * @return the de-serialized KiWiDateLiteral
+ * @throws IOException
+ */
+ public static KiWiDateLiteral readDateLiteral(DataInput input) throws IOException {
+ long id = input.readLong();
+
+ if(id == -1) {
+ return null;
+ } else {
+ Date content = new Date(input.readLong());
+
+ KiWiUriResource dtype = readURI(input);
+
+ Date created = new Date(input.readLong());
+
+ KiWiDateLiteral r = new KiWiDateLiteral(content, dtype, created);
+ r.setId(id);
+
+ return r;
+ }
+ }
+
+
+ /**
+ * Efficiently serialize a KiWiDoubleLiteral to a DataOutput destination.
+ *
+ * @param out the destination
+ * @param literal the KiWiDoubleLiteral to serialize
+ * @throws IOException
+ */
+ public static void writeDoubleLiteral(DataOutput out, KiWiDoubleLiteral literal) throws IOException {
+ if(literal == null) {
+ out.writeLong(-1L);
+ } else {
+ out.writeLong(literal.getId());
+ out.writeDouble(literal.getDoubleContent());
+ writeURI(out, literal.getType());
+ out.writeLong(literal.getCreated().getTime());
+ }
+ }
+
+
+ /**
+ * Read a KiWiDoubleLiteral serialized with writeDoubleLiteral from a DataInput source
+ *
+ * @param input the source
+ * @return the de-serialized KiWiDoubleLiteral
+ * @throws IOException
+ */
+ public static KiWiDoubleLiteral readDoubleLiteral(DataInput input) throws IOException {
+ long id = input.readLong();
+
+ if(id == -1) {
+ return null;
+ } else {
+ double content = input.readDouble();
+
+ KiWiUriResource dtype = readURI(input);
+
+ Date created = new Date(input.readLong());
+
+ KiWiDoubleLiteral r = new KiWiDoubleLiteral(content, dtype, created);
+ r.setId(id);
+
+ return r;
+ }
+ }
+
+
+ /**
+ * Efficiently serialize a KiWiIntLiteral to a DataOutput destination.
+ *
+ * @param out the destination
+ * @param literal the KiWiIntLiteral to serialize
+ * @throws IOException
+ */
+ public static void writeIntLiteral(DataOutput out, KiWiIntLiteral literal) throws IOException {
+ if(literal == null) {
+ out.writeLong(-1L);
+ } else {
+ out.writeLong(literal.getId());
+ out.writeLong(literal.getIntContent());
+ writeURI(out, literal.getType());
+ out.writeLong(literal.getCreated().getTime());
+ }
+ }
+
+
+ /**
+ * Read a KiWiIntLiteral serialized with writeIntLiteral from a DataInput source
+ *
+ * @param input the source
+ * @return the de-serialized KiWiIntLiteral
+ * @throws IOException
+ */
+ public static KiWiIntLiteral readIntLiteral(DataInput input) throws IOException {
+ long id = input.readLong();
+
+ if(id == -1) {
+ return null;
+ } else {
+ long content = input.readLong();
+
+ KiWiUriResource dtype = readURI(input);
+
+ Date created = new Date(input.readLong());
+
+ KiWiIntLiteral r = new KiWiIntLiteral(content, dtype, created);
+ r.setId(id);
+
+ return r;
+ }
+ }
+
+
+
+ /**
+ * Efficiently serialize a KiWiStringLiteral to a DataOutput destination.
+ *
+ * @param out the destination
+ * @param literal the KiWiStringLiteral to serialize
+ * @throws IOException
+ */
+ public static void writeStringLiteral(DataOutput out, KiWiStringLiteral literal) throws IOException {
+ if(literal == null) {
+ out.writeLong(-1L);
+ } else {
+ out.writeLong(literal.getId());
+ DataIO.writeString(out, literal.getContent());
+ DataIO.writeString(out, literal.getLanguage());
+ writeURI(out, literal.getType());
+ out.writeLong(literal.getCreated().getTime());
+ }
+ }
+
+
+
+ /**
+ * Read a KiWiStringLiteral serialized with writeStringLiteral from a DataInput source
+ *
+ * @param input the source
+ * @return the de-serialized KiWiStringLiteral
+ * @throws IOException
+ */
+ public static KiWiStringLiteral readStringLiteral(DataInput input) throws IOException {
+ long id = input.readLong();
+
+ if(id == -1) {
+ return null;
+ } else {
+ String content = DataIO.readString(input);
+ String lang = DataIO.readString(input);
+
+ KiWiUriResource dtype = readURI(input);
+
+ Date created = new Date(input.readLong());
+
+ KiWiStringLiteral r = new KiWiStringLiteral(content, lang != null ? Locale.forLanguageTag(lang) : null, dtype, created);
+ r.setId(id);
+
+ return r;
+ }
+ }
+
+
+ /**
+ * Efficiently serialize a KiWiTriple to a DataOutput destination.
+ *
+ * @param output the destination
+ * @param triple the KiWiTriple to serialize
+ * @throws IOException
+ */
+ public static void writeTriple(DataOutput output, KiWiTriple triple) throws IOException {
+ output.writeLong(triple.getId());
+
+ // in case subject and object are both uris we use a special prefix-compressed mode
+ if(triple.getSubject().isUriResource() && triple.getObject().isUriResource()) {
+ String sUri = triple.getSubject().stringValue();
+ String oUri = triple.getObject().stringValue();
+
+ String prefix = StringUtils.getCommonPrefix(sUri, oUri);
+
+ output.writeByte(MODE_PREFIX);
+ DataIO.writeString(output,prefix);
+
+ output.writeLong(triple.getSubject().getId());
+ DataIO.writeString(output, sUri.substring(prefix.length()));
+ output.writeLong(triple.getSubject().getCreated().getTime());
+
+ writeURI(output,triple.getPredicate());
+
+ output.writeLong(triple.getObject().getId());
+ DataIO.writeString(output, oUri.substring(prefix.length()));
+ output.writeLong(triple.getObject().getCreated().getTime());
+ } else {
+ output.writeByte(MODE_DEFAULT);
+
+ writeNode(output,triple.getSubject());
+ writeURI(output,triple.getPredicate());
+ writeNode(output,triple.getObject());
+
+ }
+
+ writeNode(output,triple.getContext());
+ writeNode(output,triple.getCreator());
+ output.writeBoolean(triple.isDeleted());
+ output.writeBoolean(triple.isInferred());
+ output.writeBoolean(triple.isNewTriple());
+ output.writeLong(triple.getCreated().getTime());
+ if(triple.getDeletedAt() != null) {
+ output.writeLong(triple.getDeletedAt().getTime());
+ } else {
+ output.writeLong(0);
+ }
+ }
+
+
+ /**
+ * Read a KiWiTriple serialized with writeTriple from a DataInput source
+ *
+ * @param input the source
+ * @return the de-serialized KiWiTriple
+ * @throws IOException
+ */
+ public static KiWiTriple readTriple(DataInput 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(readURI(input));
+
+ 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) readNode(input));
+ result.setPredicate(readURI(input));
+ result.setObject(readNode(input));
+ }
+ result.setContext((KiWiResource) readNode(input));
+ result.setCreator((KiWiResource) readNode(input));
+ 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/7c40b532/libraries/ldcache/ldcache-backend-kiwi/src/main/java/org/apache/marmotta/ldcache/backend/kiwi/persistence/LDCachingKiWiPersistenceConnection.java
----------------------------------------------------------------------
diff --git a/libraries/ldcache/ldcache-backend-kiwi/src/main/java/org/apache/marmotta/ldcache/backend/kiwi/persistence/LDCachingKiWiPersistenceConnection.java b/libraries/ldcache/ldcache-backend-kiwi/src/main/java/org/apache/marmotta/ldcache/backend/kiwi/persistence/LDCachingKiWiPersistenceConnection.java
index 17bfa9b..f2d9b47 100644
--- a/libraries/ldcache/ldcache-backend-kiwi/src/main/java/org/apache/marmotta/ldcache/backend/kiwi/persistence/LDCachingKiWiPersistenceConnection.java
+++ b/libraries/ldcache/ldcache-backend-kiwi/src/main/java/org/apache/marmotta/ldcache/backend/kiwi/persistence/LDCachingKiWiPersistenceConnection.java
@@ -25,7 +25,6 @@ import org.apache.marmotta.kiwi.persistence.util.ResultSetIteration;
import org.apache.marmotta.kiwi.persistence.util.ResultTransformerFunction;
import org.apache.marmotta.ldcache.backend.kiwi.model.KiWiCacheEntry;
import org.apache.marmotta.ldcache.model.CacheEntry;
-import org.infinispan.Cache;
import org.openrdf.model.URI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -36,6 +35,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Date;
+import java.util.Map;
import java.util.Set;
/**
@@ -53,13 +53,13 @@ public class LDCachingKiWiPersistenceConnection implements Closeable {
/**
* Cache entries by resource
*/
- private Cache<String,KiWiCacheEntry> entryResourceCache;
+ private Map<String,KiWiCacheEntry> entryResourceCache;
/**
* Cache entries by ID
*/
- private Cache<Long,KiWiCacheEntry> entryIdCache;
+ private Map<Long,KiWiCacheEntry> entryIdCache;
public LDCachingKiWiPersistenceConnection(KiWiConnection connection) throws SQLException {
http://git-wip-us.apache.org/repos/asf/marmotta/blob/7c40b532/libraries/ldcache/ldcache-backend-kiwi/src/test/java/org/apache/marmotta/ldcache/services/test/LDCacheKiWiTest.java
----------------------------------------------------------------------
diff --git a/libraries/ldcache/ldcache-backend-kiwi/src/test/java/org/apache/marmotta/ldcache/services/test/LDCacheKiWiTest.java b/libraries/ldcache/ldcache-backend-kiwi/src/test/java/org/apache/marmotta/ldcache/services/test/LDCacheKiWiTest.java
index 7d3a297..1320198 100644
--- a/libraries/ldcache/ldcache-backend-kiwi/src/test/java/org/apache/marmotta/ldcache/services/test/LDCacheKiWiTest.java
+++ b/libraries/ldcache/ldcache-backend-kiwi/src/test/java/org/apache/marmotta/ldcache/services/test/LDCacheKiWiTest.java
@@ -16,6 +16,7 @@
*/
package org.apache.marmotta.ldcache.services.test;
+import org.apache.commons.lang3.StringUtils;
import org.apache.marmotta.kiwi.persistence.KiWiDialect;
import org.apache.marmotta.kiwi.persistence.h2.H2Dialect;
import org.apache.marmotta.kiwi.persistence.mysql.MySQLDialect;
@@ -24,6 +25,7 @@ import org.apache.marmotta.kiwi.sail.KiWiStore;
import org.apache.marmotta.ldcache.api.LDCachingBackend;
import org.apache.marmotta.ldcache.backend.kiwi.LDCachingKiWiBackend;
import org.apache.marmotta.ldcache.services.test.ng.BaseLDCacheTest;
+import org.junit.Assume;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -127,6 +129,9 @@ public class LDCacheKiWiTest extends BaseLDCacheTest {
*/
@Override
protected LDCachingBackend createBackend() {
+ Assume.assumeNotNull(jdbcUrl);
+ Assume.assumeTrue(!StringUtils.isBlank(jdbcUrl));
+
try {
KiWiStore store = new KiWiStore("test",jdbcUrl,jdbcUser,jdbcPass,dialect, "http://localhost/context/default", "http://localhost/context/inferred");
final Repository repository = new SailRepository(store);
[11/32] 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/develop
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();
+ }
+
+ }
+}
[12/32] 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/develop
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;
}
[22/32] 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/develop
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;
+ }
}
[08/32] 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/develop
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;
- }
-
-}
[17/32] 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/develop
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);
[10/32] 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/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);
+ }
}
[18/32] 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/develop
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>
[23/32] 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/develop
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;
[03/32] 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/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>
[19/32] 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 {
[27/32] git commit: Merge branch 'develop' into MARMOTTA-450
Posted by ss...@apache.org.
Merge branch 'develop' into MARMOTTA-450
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/cebdd640
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/cebdd640
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/cebdd640
Branch: refs/heads/develop
Commit: cebdd640424d6f50b3f2552d17d668b8ec037381
Parents: b07ed13 d5b0c6d
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Mon Mar 17 09:53:25 2014 +0100
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Mon Mar 17 09:53:25 2014 +0100
----------------------------------------------------------------------
launchers/marmotta-webapp/pom.xml | 3 +-
platform/backends/marmotta-backend-http/pom.xml | 2 +-
platform/marmotta-core/pom.xml | 4 -
.../core/exception/HttpErrorException.java | 107 +++++
.../core/jaxrs/HttpErrorExceptionMapper.java | 91 ++++
.../jaxrs/MarmottaImportExceptionMapper.java | 1 -
.../servlet/MarmottaPreStartupListener.java | 10 +-
.../webservices/resource/ContentWebService.java | 83 ++--
.../webservices/resource/MetaWebService.java | 194 ++++-----
.../resource/ResourceWebService.java | 282 ++++++------
.../resource/ResourceWebServiceHelper.java | 65 +--
.../main/resources/config-defaults.properties | 28 +-
.../src/main/resources/templates/error.ftl | 83 ++++
.../src/main/resources/web/admin/dataview.html | 430 ++++++++++---------
.../web/public/img/logo/marmotta-sad.png | Bin 0 -> 37916 bytes
.../resources/web/public/style/blue/error.css | 31 ++
.../resources/web/public/style/white/error.css | 31 ++
17 files changed, 867 insertions(+), 578 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/cebdd640/launchers/marmotta-webapp/pom.xml
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/cebdd640/platform/marmotta-core/pom.xml
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/cebdd640/platform/marmotta-core/src/main/resources/config-defaults.properties
----------------------------------------------------------------------
[30/32] git commit: - re-added support for EHCache as KiWi caching
backend (MARMOTTA-450) - cleanup old use of EHCache (MARMOTTA-443)
Posted by ss...@apache.org.
- re-added support for EHCache as KiWi caching backend (MARMOTTA-450)
- cleanup old use of EHCache (MARMOTTA-443)
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/2c5e8529
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/2c5e8529
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/2c5e8529
Branch: refs/heads/develop
Commit: 2c5e8529cc51fbbec6c54cc43fd0c65b39352b11
Parents: 18db945
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Mon Mar 17 11:15:47 2014 +0100
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Mon Mar 17 11:15:47 2014 +0100
----------------------------------------------------------------------
.../src/main/resources/ehcache-lmf.xml | 422 ----------
.../resources/META-INF/test-persistence.xml | 86 ---
.../src/test/resources/arquillian.xml | 31 -
.../src/test/resources/ehcache.xml | 380 ---------
libraries/kiwi/kiwi-caching-ehcache/pom.xml | 117 +++
.../kiwi/ehcache/caching/EHCacheManager.java | 201 +++++
.../ehcache/caching/EHCacheManagerFactory.java | 41 +
.../marmotta/kiwi/ehcache/util/CacheMap.java | 144 ++++
...he.marmotta.kiwi.caching.CacheManagerFactory | 1 +
.../src/main/resources/ehcache-kiwi.xml | 767 +++++++++++++++++++
.../EHCacheRepositoryConnectionTest.java | 63 ++
.../test/caching/EHCacheRepositoryTest.java | 61 ++
...he.marmotta.kiwi.caching.CacheManagerFactory | 1 +
.../marmotta/kiwi/config/CachingBackends.java | 8 +-
libraries/kiwi/pom.xml | 1 +
parent/pom.xml | 9 +
.../src/main/resources/META-INF/ehcache.xml | 500 ------------
17 files changed, 1413 insertions(+), 1420 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2c5e8529/build/archetypes/marmotta-archetype-webapp/src/main/resources/archetype-resources/src/main/resources/ehcache-lmf.xml
----------------------------------------------------------------------
diff --git a/build/archetypes/marmotta-archetype-webapp/src/main/resources/archetype-resources/src/main/resources/ehcache-lmf.xml b/build/archetypes/marmotta-archetype-webapp/src/main/resources/archetype-resources/src/main/resources/ehcache-lmf.xml
deleted file mode 100644
index 9923971..0000000
--- a/build/archetypes/marmotta-archetype-webapp/src/main/resources/archetype-resources/src/main/resources/ehcache-lmf.xml
+++ /dev/null
@@ -1,422 +0,0 @@
-#set( $symbol_pound = '#' )
-#set( $symbol_dollar = '$' )
-#set( $symbol_escape = '\' )
-<?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.
-
--->
-<!--
-CacheManager Configuration
-==========================
-An ehcache-lmf.xml corresponds to a single CacheManager.
-
-See instructions below or the ehcache schema (ehcache.xsd) on how to configure.
-
-System property tokens can be specified in this file which are replaced when the configuration
-is loaded. For example multicastGroupPort=${symbol_dollar}{multicastGroupPort} can be replaced with the
-System property either from an environment variable or a system property specified with a
-command line switch such as -DmulticastGroupPort=4446.
-
-The attributes of <ehcache> are:
-* name - an optional name for the CacheManager. The name is optional and primarily used
-for documentation or to distinguish Terracotta clustered cache state. With Terracotta
-clustered caches, a combination of CacheManager name and cache name uniquely identify a
-particular cache store in the Terracotta clustered memory.
-* updateCheck - an optional boolean flag specifying whether this CacheManager should check
-for new versions of Ehcache over the Internet. If not specified, updateCheck="true".
-* monitoring - an optional setting that determines whether the CacheManager should
-automatically register the SampledCacheMBean with the system MBean server. Currently,
-this monitoring is only useful when using Terracotta and thus the "autodetect" value
-will detect the presence of Terracotta and register the MBean. Other allowed values
-are "on" and "off". The default is "autodetect".
--->
-<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd" name="lmf">
-
- <!--
- DiskStore configuration
- =======================
-
- The diskStore element is optional. To turn off disk store path creation, comment out the diskStore
- element below.
-
- Configure it if you have overflowToDisk or diskPersistent enabled for any cache.
-
- If it is not configured, and a cache is created which requires a disk store, a warning will be
- issued and java.io.tmpdir will automatically be used.
-
- diskStore has only one attribute - "path". It is the path to the directory where
- .data and .index files will be created.
-
- If the path is one of the following Java System Property it is replaced by its value in the
- running VM. For backward compatibility these are not specified without being enclosed in the ${symbol_dollar}{token}
- replacement syntax.
-
- The following properties are translated:
- * user.home - KiWiUser's home directory
- * user.dir - KiWiUser's current working directory
- * java.io.tmpdir - Default temp file path
- * ehcache.disk.store.dir - A system property you would normally specify on the command line
- e.g. java -Dehcache.disk.store.dir=/u01/myapp/diskdir ...
-
- Subdirectories can be specified below the property e.g. java.io.tmpdir/one
-
- -->
- <diskStore path="java.io.tmpdir/lmf-cache/lmf"/>
-
- <!--
- Cachemanagereventlistener
- =========================
- Specifies a CacheManagerEventListenerFactory which is notified when Caches are added
- or removed from the CacheManager.
-
- The attributes of CacheManagerEventListenerFactory are:
- * class - a fully qualified factory class name
- * properties - comma separated properties having meaning only to the factory.
-
- Sets the fully qualified class name to be registered as the CacheManager event listener.
-
- The events include:
- * adding a Cache
- * removing a Cache
-
- Callbacks to listener methods are synchronous and unsynchronized. It is the responsibility
- of the implementer to safely handle the potential performance and thread safety issues
- depending on what their listener is doing.
-
- If no class is specified, no listener is created. There is no default.
- -->
- <cacheManagerEventListenerFactory class="" properties=""/>
-
-
- <!--
- CacheManagerPeerProvider
- ========================
- (For distributed operation)
-
- Specifies a CacheManagerPeerProviderFactory which will be used to create a
- CacheManagerPeerProvider, which discovers other CacheManagers in the cluster.
-
- One or more providers can be configured. The first one in the ehcache-lmf.xml is the default, which is used
- for replication and bootstrapping.
-
- The attributes of cacheManagerPeerProviderFactory are:
- * class - a fully qualified factory class name
- * properties - comma separated properties having meaning only to the factory.
-
- Providers are available for RMI, JGroups and JMS as shown following.
-
- RMICacheManagerPeerProvider
- +++++++++++++++++++++++++++
-
- Ehcache comes with a built-in RMI-based distribution system with two means of discovery of
- CacheManager peers participating in the cluster:
- * automatic, using a multicast group. This one automatically discovers peers and detects
- changes such as peers entering and leaving the group
- * manual, using manual rmiURL configuration. A hardcoded list of peers is provided at
- configuration time.
-
- Configuring Automatic Discovery:
- Automatic discovery is configured as per the following example:
- <cacheManagerPeerProviderFactory
- class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
- properties="hostName=fully_qualified_hostname_or_ip,
- peerDiscovery=automatic, multicastGroupAddress=230.0.0.1,
- multicastGroupPort=4446, timeToLive=32"/>
-
- Valid properties are:
- * peerDiscovery (mandatory) - specify "automatic"
- * multicastGroupAddress (mandatory) - specify a valid multicast group address
- * multicastGroupPort (mandatory) - specify a dedicated port for the multicast heartbeat
- traffic
- * timeToLive - specify a value between 0 and 255 which determines how far the packets will
- propagate.
-
- By convention, the restrictions are:
- 0 - the same host
- 1 - the same subnet
- 32 - the same site
- 64 - the same region
- 128 - the same continent
- 255 - unrestricted
-
- * hostName - the hostname or IP of the interface to be used for sending and receiving multicast packets
- (relevant to mulithomed hosts only)
-
- Configuring Manual Discovery:
- Manual discovery requires a unique configuration per host. It is contains a list of rmiURLs for the peers, other
- than itself. So, if we have server1, server2 and server3 the configuration will be:
-
- In server1's configuration:
- <cacheManagerPeerProviderFactory class=
- "net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
- properties="peerDiscovery=manual,
- rmiUrls=//server2:40000/sampleCache1|//server3:40000/sampleCache1
- | //server2:40000/sampleCache2|//server3:40000/sampleCache2"
- propertySeparator="," />
-
- In server2's configuration:
- <cacheManagerPeerProviderFactory class=
- "net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
- properties="peerDiscovery=manual,
- rmiUrls=//server1:40000/sampleCache1|//server3:40000/sampleCache1
- | //server1:40000/sampleCache2|//server3:40000/sampleCache2"
- propertySeparator="," />
-
- In server3's configuration:
- <cacheManagerPeerProviderFactory class=
- "net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
- properties="peerDiscovery=manual,
- rmiUrls=//server1:40000/sampleCache1|//server2:40000/sampleCache1
- | //server1:40000/sampleCache2|//server2:40000/sampleCache2"
- propertySeparator="," />
-
-
- Valid properties are:
- * peerDiscovery (mandatory) - specify "manual"
- * rmiUrls (mandatory) - specify a pipe separated list of rmiUrls, in the form
- //hostname:port
- * hostname (optional) - the hostname is the hostname of the remote CacheManager peer. The port is the listening
- port of the RMICacheManagerPeerListener of the remote CacheManager peer.
-
- JGroupsCacheManagerPeerProvider
- +++++++++++++++++++++++++++++++
- <cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheManagerPeerProviderFactory"
- properties="connect=UDP(mcast_addr=231.12.21.132;mcast_port=45566;ip_ttl=32;
- mcast_send_buf_size=150000;mcast_recv_buf_size=80000):
- PING(timeout=2000;num_initial_members=6):
- MERGE2(min_interval=5000;max_interval=10000):
- FD_SOCK:VERIFY_SUSPECT(timeout=1500):
- pbcast.NAKACK(gc_lag=10;retransmit_timeout=3000):
- UNICAST(timeout=5000):
- pbcast.STABLE(desired_avg_gossip=20000):
- FRAG:
- pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;shun=false;print_local_addr=false)"
- propertySeparator="::"
- />
- The only property necessary is the connect String used by jgroups to configure itself. Refer to the Jgroups documentation for explanation
- of all the protocols. The example above uses UDP multicast. If the connect property is not specified the default JGroups connection will be
- used.
-
-
- JMSCacheManagerPeerProviderFactory
- ++++++++++++++++++++++++++++++++++
- <cacheManagerPeerProviderFactory
- class="net.sf.ehcache.distribution.jms.JMSCacheManagerPeerProviderFactory"
- properties="..."
- propertySeparator=","
- />
-
- The JMS PeerProviderFactory uses JNDI to maintain message queue independence. Refer to the manual for full configuration
- examples using ActiveMQ and Open Message Queue.
-
- Valid properties are:
- * initialContextFactoryName (mandatory) - the name of the factory used to create the message queue initial context.
- * providerURL (mandatory) - the JNDI configuration information for the service provider to use.
- * topicConnectionFactoryBindingName (mandatory) - the JNDI binding name for the TopicConnectionFactory
- * topicBindingName (mandatory) - the JNDI binding name for the topic name
- * getQueueBindingName (mandatory only if using jmsCacheLoader) - the JNDI binding name for the queue name
- * securityPrincipalName - the JNDI java.naming.security.principal
- * securityCredentials - the JNDI java.naming.security.credentials
- * urlPkgPrefixes - the JNDI java.naming.factory.url.pkgs
- * userName - the user name to use when creating the TopicConnection to the Message Queue
- * password - the password to use when creating the TopicConnection to the Message Queue
- * acknowledgementMode - the JMS Acknowledgement mode for both publisher and subscriber. The available choices are
- AUTO_ACKNOWLEDGE, DUPS_OK_ACKNOWLEDGE and SESSION_TRANSACTED. The default is AUTO_ACKNOWLEDGE.
- -->
-<!-- <cacheManagerPeerProviderFactory-->
-<!-- class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"-->
-<!-- properties="peerDiscovery=automatic,-->
-<!-- multicastGroupAddress=230.0.0.1,-->
-<!-- multicastGroupPort=4446, timeToLive=1"-->
-<!-- propertySeparator=","-->
-<!-- />-->
-
-
- <!--
- CacheManagerPeerListener
- ========================
- (Enable for distributed operation)
-
- Specifies a CacheManagerPeerListenerFactory which will be used to create a
- CacheManagerPeerListener, which listens for messages from cache replicators participating in the cluster.
-
- The attributes of cacheManagerPeerListenerFactory are:
- class - a fully qualified factory class name
- properties - comma separated properties having meaning only to the factory.
-
- Ehcache comes with a built-in RMI-based distribution system. The listener component is
- RMICacheManagerPeerListener which is configured using
- RMICacheManagerPeerListenerFactory. It is configured as per the following example:
-
- <cacheManagerPeerListenerFactory
- class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
- properties="hostName=fully_qualified_hostname_or_ip,
- port=40001,
- remoteObjectPort=40002,
- socketTimeoutMillis=120000"
- propertySeparator="," />
-
- All properties are optional. They are:
- * hostName - the hostName of the host the listener is running on. Specify
- where the host is multihomed and you want to control the interface over which cluster
- messages are received. Defaults to the host name of the default interface if not
- specified.
- * port - the port the RMI Registry listener listens on. This defaults to a free port if not specified.
- * remoteObjectPort - the port number on which the remote objects bound in the registry receive calls.
- This defaults to a free port if not specified.
- * socketTimeoutMillis - the number of ms client sockets will stay open when sending
- messages to the listener. This should be long enough for the slowest message.
- If not specified it defaults to 120000ms.
-
- -->
-<!-- <cacheManagerPeerListenerFactory-->
-<!-- class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"/>-->
-
- <!-- Cache configuration.
-
- The following attributes are required.
-
- name:
- Sets the name of the cache. This is used to identify the cache. It must be unique.
-
- maxElementsInMemory:
- Sets the maximum number of objects that will be created in memory
-
- maxElementsOnDisk:
- Sets the maximum number of objects that will be maintained in the DiskStore
- The default value is zero, meaning unlimited.
-
- eternal:
- Sets whether elements are eternal. If eternal, timeouts are ignored and the
- element is never expired.
-
- overflowToDisk:
- Sets whether elements can overflow to disk when the memory store
- has reached the maxInMemory limit.
-
- The following attributes are optional.
-
- timeToIdleSeconds:
- Sets the time to idle for an element before it expires.
- i.e. The maximum amount of time between accesses before an element expires
- Is only used if the element is not eternal.
- Optional attribute. A value of 0 means that an Element can idle for infinity.
- The default value is 0.
-
- timeToLiveSeconds:
- Sets the time to live for an element before it expires.
- i.e. The maximum time between creation time and when an element expires.
- Is only used if the element is not eternal.
- Optional attribute. A value of 0 means that and Element can live for infinity.
- The default value is 0.
-
- diskPersistent:
- Whether the disk store persists between restarts of the Virtual Machine.
- The default value is false.
-
- diskExpiryThreadIntervalSeconds:
- The number of seconds between runs of the disk expiry thread. The default value
- is 120 seconds.
-
- memoryStoreEvictionPolicy:
- Policy would be enforced upon reaching the maxElementsInMemory limit. Default
- policy is Least Recently Used (specified as LRU). Other policies available -
- First In First Out (specified as FIFO) and Less Frequently Used
- (specified as LFU)
-
- -->
-
- <!--
- Mandatory Default Cache configuration. These settings will be applied to caches
- created programmtically using CacheManager.add(String cacheName)
- -->
- <defaultCache
- maxElementsInMemory="20000"
- overflowToDisk="false"
- memoryStoreEvictionPolicy="LRU"
- />
-
-
- <!-- the cache used for triple queries by KiWi -->
- <cache name="uri-node-cache"
- statistics="true"
- maxElementsInMemory="100000"
- timeToIdleSeconds="3600"
- overflowToDisk="false"/>
- <cache name="anon-node-cache"
- statistics="true"
- maxElementsInMemory="10000"
- timeToIdleSeconds="3600"
- overflowToDisk="false"/>
- <cache name="literal-cache"
- statistics="true"
- maxElementsInMemory="10000"
- timeToIdleSeconds="3600"
- overflowToDisk="false"/>
-
- <cache name="namespace-prefix-cache"
- statistics="true"
- maxElementsInMemory="100"
- overflowToDisk="true"/>
-
- <cache name="namespace-uri-cache"
- statistics="true"
- maxElementsInMemory="100"
- overflowToDisk="true"/>
-
- <!-- the cache used for triple queries by KiWi -->
- <cache name="query-cache"
- statistics="true"
- maxElementsInMemory="200000"
- timeToIdleSeconds="3600"
- overflowToDisk="false"/>
-
- <!-- the cache used for resource lookups from module jar files -->
- <cache name="resource-cache"
- statistics="true"
- maxElementsInMemory="10000"
- timeToIdleSeconds="3600"
- timeToLiveSeconds="3600"
- overflowToDisk="false"
- memoryStoreEvictionPolicy="LRU"/>
-
- <!-- the cache used for triple queries by KiWi -->
- <cache name="page-cache"
- statistics="true"
- maxElementsInMemory="500"
- timeToIdleSeconds="3600"
- memoryStoreEvictionPolicy="LRU"
- overflowToDisk="true"/>
-
- <cache name="http-content-cache"
- statistics="true"
- maxElementsInMemory="500"
- timeToIdleSeconds="3600"
- memoryStoreEvictionPolicy="LRU"
- overflowToDisk="true"/>
-
-
- <!-- uncomment to enable cache debugging -->
-<!--
- <cacheManagerPeerListenerFactory
- class="org.terracotta.ehcachedx.monitor.probe.ProbePeerListenerFactory"
- properties="monitorAddress=localhost, monitorPort=9889" />
--->
-
-</ehcache>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2c5e8529/build/archetypes/marmotta-archetype-webapp/src/main/resources/archetype-resources/src/test/resources/META-INF/test-persistence.xml
----------------------------------------------------------------------
diff --git a/build/archetypes/marmotta-archetype-webapp/src/main/resources/archetype-resources/src/test/resources/META-INF/test-persistence.xml b/build/archetypes/marmotta-archetype-webapp/src/main/resources/archetype-resources/src/test/resources/META-INF/test-persistence.xml
deleted file mode 100644
index 852b672..0000000
--- a/build/archetypes/marmotta-archetype-webapp/src/main/resources/archetype-resources/src/test/resources/META-INF/test-persistence.xml
+++ /dev/null
@@ -1,86 +0,0 @@
-#set( $symbol_pound = '#' )
-#set( $symbol_dollar = '$' )
-#set( $symbol_escape = '\' )
-<?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.
--->
-
-<persistence xmlns="http://java.sun.com/xml/ns/persistence"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
- version="2.0">
-
- <!--
-
- resources/META-INF/persistence.xml.tmpl should be the only place you change anything
- any of persistence.*.xml. After changing it, "ant configure"
- copies it to all places it is needed.
-
- -->
-
- <persistence-unit name="KiWi" transaction-type="RESOURCE_LOCAL">
-
- <class>org.apache.marmotta.platform.core.model.rdf.KiWiNode</class>
- <class>org.apache.marmotta.platform.core.model.rdf.KiWiResource</class>
- <class>org.apache.marmotta.platform.core.model.rdf.KiWiUriResource</class>
- <class>org.apache.marmotta.platform.core.model.rdf.KiWiAnonResource</class>
- <class>org.apache.marmotta.platform.core.model.rdf.KiWiLiteral</class>
- <class>org.apache.marmotta.platform.core.model.rdf.KiWiStringLiteral</class>
- <class>org.apache.marmotta.platform.core.model.rdf.KiWiIntLiteral</class>
- <class>org.apache.marmotta.platform.core.model.rdf.KiWiDoubleLiteral</class>
- <class>org.apache.marmotta.platform.core.model.rdf.KiWiTextContentLiteral</class>
- <class>org.apache.marmotta.platform.core.model.rdf.KiWiMediaContentLiteral</class>
-
- <class>org.apache.marmotta.platform.core.model.rdf.KiWiNamespace</class>
- <class>org.apache.marmotta.platform.core.model.rdf.KiWiTriple</class>
-
- <class>${package}.user.model.UserAccount</class>
- <!--<class>kiwi.core.model.user.KiWiUser</class>-->
- <!--<class>kiwi.core.model.user.KiWiGroup</class>-->
- <!--<class>kiwi.core.model.user.Role</class>-->
-
- <class>${package}.versioning.model.Version</class>
-
- <properties>
- <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
- <property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
- <property name="javax.persistence.jdbc.user" value="sa"/>
- <property name="javax.persistence.jdbc.password" value="sa"/>
- <property name="javax.persistence.jdbc.url" value="jdbc:h2:/tmp/kiwi-test/db/kiwi2;MVCC=true;DB_CLOSE_ON_EXIT=FALSE"/>
-
-
- <!-- valid values are validate, update, create, create-drop -->
- <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
- <property name="hibernate.show_sql" value="false"/>
- <property name="hibernate.format_sql" value="true"/>
- <property name="hibernate.jdbc.fetch_size" value="30"/>
- <property name="hibernate.jdbc.batch_size" value="30"/>
- <property name="hibernate.default_batch_fetch_size" value="16" />
- <property name="hibernate.max_fetch_depth" value="3" />
-
- <!-- Without this statement seem Hibernate to come to "Cannot open connection" state at peak times (e.g. test) -->
- <property name="hibernate.connection.release_mode" value="after_statement" />
-
- <!-- caching -->
- <property name="hibernate.cache.region.factory_class"
- value="net.sf.ehcache.hibernate.EhCacheRegionFactory"/>
- <property name="hibernate.cache.use_query_cache" value="true" />
- <property name="hibernate.cache.use_second_level_cache" value="true"/>
- <property name="hibernate.cache.region_prefix" value=""/>
- </properties>
- </persistence-unit>
-</persistence>
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2c5e8529/build/archetypes/marmotta-archetype-webapp/src/main/resources/archetype-resources/src/test/resources/arquillian.xml
----------------------------------------------------------------------
diff --git a/build/archetypes/marmotta-archetype-webapp/src/main/resources/archetype-resources/src/test/resources/arquillian.xml b/build/archetypes/marmotta-archetype-webapp/src/main/resources/archetype-resources/src/test/resources/arquillian.xml
deleted file mode 100644
index ab814c4..0000000
--- a/build/archetypes/marmotta-archetype-webapp/src/main/resources/archetype-resources/src/test/resources/arquillian.xml
+++ /dev/null
@@ -1,31 +0,0 @@
-#set( $symbol_pound = '#' )
-#set( $symbol_dollar = '$' )
-#set( $symbol_escape = '\' )
-<?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.
--->
-
-<arquillian xmlns="http://jboss.com/arquillian"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:tomcat6="urn:arq:org.jboss.arquillian.container.tomcat.embedded_6"
- xsi:schemaLocation="http://jboss.com/arquillian ">
-
- <tomcat6:container>
- <tomcat6:unpackArchive>true</tomcat6:unpackArchive>
- </tomcat6:container>
-
-</arquillian>
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2c5e8529/build/archetypes/marmotta-archetype-webapp/src/main/resources/archetype-resources/src/test/resources/ehcache.xml
----------------------------------------------------------------------
diff --git a/build/archetypes/marmotta-archetype-webapp/src/main/resources/archetype-resources/src/test/resources/ehcache.xml b/build/archetypes/marmotta-archetype-webapp/src/main/resources/archetype-resources/src/test/resources/ehcache.xml
deleted file mode 100644
index 9174f6c..0000000
--- a/build/archetypes/marmotta-archetype-webapp/src/main/resources/archetype-resources/src/test/resources/ehcache.xml
+++ /dev/null
@@ -1,380 +0,0 @@
-#set( $symbol_pound = '#' )
-#set( $symbol_dollar = '$' )
-#set( $symbol_escape = '\' )
-<?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.
--->
-
-<!--
-CacheManager Configuration
-==========================
-An ehcache-lmf.xml corresponds to a single CacheManager.
-
-See instructions below or the ehcache schema (ehcache.xsd) on how to configure.
-
-System property tokens can be specified in this file which are replaced when the configuration
-is loaded. For example multicastGroupPort=${symbol_dollar}{multicastGroupPort} can be replaced with the
-System property either from an environment variable or a system property specified with a
-command line switch such as -DmulticastGroupPort=4446.
-
-The attributes of <ehcache> are:
-* name - an optional name for the CacheManager. The name is optional and primarily used
-for documentation or to distinguish Terracotta clustered cache state. With Terracotta
-clustered caches, a combination of CacheManager name and cache name uniquely identify a
-particular cache store in the Terracotta clustered memory.
-* updateCheck - an optional boolean flag specifying whether this CacheManager should check
-for new versions of Ehcache over the Internet. If not specified, updateCheck="true".
-* monitoring - an optional setting that determines whether the CacheManager should
-automatically register the SampledCacheMBean with the system MBean server. Currently,
-this monitoring is only useful when using Terracotta and thus the "autodetect" value
-will detect the presence of Terracotta and register the MBean. Other allowed values
-are "on" and "off". The default is "autodetect".
--->
-<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd">
-
- <!--
- DiskStore configuration
- =======================
-
- The diskStore element is optional. To turn off disk store path creation, comment out the diskStore
- element below.
-
- Configure it if you have overflowToDisk or diskPersistent enabled for any cache.
-
- If it is not configured, and a cache is created which requires a disk store, a warning will be
- issued and java.io.tmpdir will automatically be used.
-
- diskStore has only one attribute - "path". It is the path to the directory where
- .data and .index files will be created.
-
- If the path is one of the following Java System Property it is replaced by its value in the
- running VM. For backward compatibility these are not specified without being enclosed in the ${symbol_dollar}{token}
- replacement syntax.
-
- The following properties are translated:
- * user.home - KiWiUser's home directory
- * user.dir - KiWiUser's current working directory
- * java.io.tmpdir - Default temp file path
- * ehcache.disk.store.dir - A system property you would normally specify on the command line
- e.g. java -Dehcache.disk.store.dir=/u01/myapp/diskdir ...
-
- Subdirectories can be specified below the property e.g. java.io.tmpdir/one
-
- -->
- <diskStore path="java.io.tmpdir"/>
-
- <!--
- Cachemanagereventlistener
- =========================
- Specifies a CacheManagerEventListenerFactory which is notified when Caches are added
- or removed from the CacheManager.
-
- The attributes of CacheManagerEventListenerFactory are:
- * class - a fully qualified factory class name
- * properties - comma separated properties having meaning only to the factory.
-
- Sets the fully qualified class name to be registered as the CacheManager event listener.
-
- The events include:
- * adding a Cache
- * removing a Cache
-
- Callbacks to listener methods are synchronous and unsynchronized. It is the responsibility
- of the implementer to safely handle the potential performance and thread safety issues
- depending on what their listener is doing.
-
- If no class is specified, no listener is created. There is no default.
- -->
- <cacheManagerEventListenerFactory class="" properties=""/>
-
-
- <!--
- CacheManagerPeerProvider
- ========================
- (For distributed operation)
-
- Specifies a CacheManagerPeerProviderFactory which will be used to create a
- CacheManagerPeerProvider, which discovers other CacheManagers in the cluster.
-
- One or more providers can be configured. The first one in the ehcache-lmf.xml is the default, which is used
- for replication and bootstrapping.
-
- The attributes of cacheManagerPeerProviderFactory are:
- * class - a fully qualified factory class name
- * properties - comma separated properties having meaning only to the factory.
-
- Providers are available for RMI, JGroups and JMS as shown following.
-
- RMICacheManagerPeerProvider
- +++++++++++++++++++++++++++
-
- Ehcache comes with a built-in RMI-based distribution system with two means of discovery of
- CacheManager peers participating in the cluster:
- * automatic, using a multicast group. This one automatically discovers peers and detects
- changes such as peers entering and leaving the group
- * manual, using manual rmiURL configuration. A hardcoded list of peers is provided at
- configuration time.
-
- Configuring Automatic Discovery:
- Automatic discovery is configured as per the following example:
- <cacheManagerPeerProviderFactory
- class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
- properties="hostName=fully_qualified_hostname_or_ip,
- peerDiscovery=automatic, multicastGroupAddress=230.0.0.1,
- multicastGroupPort=4446, timeToLive=32"/>
-
- Valid properties are:
- * peerDiscovery (mandatory) - specify "automatic"
- * multicastGroupAddress (mandatory) - specify a valid multicast group address
- * multicastGroupPort (mandatory) - specify a dedicated port for the multicast heartbeat
- traffic
- * timeToLive - specify a value between 0 and 255 which determines how far the packets will
- propagate.
-
- By convention, the restrictions are:
- 0 - the same host
- 1 - the same subnet
- 32 - the same site
- 64 - the same region
- 128 - the same continent
- 255 - unrestricted
-
- * hostName - the hostname or IP of the interface to be used for sending and receiving multicast packets
- (relevant to mulithomed hosts only)
-
- Configuring Manual Discovery:
- Manual discovery requires a unique configuration per host. It is contains a list of rmiURLs for the peers, other
- than itself. So, if we have server1, server2 and server3 the configuration will be:
-
- In server1's configuration:
- <cacheManagerPeerProviderFactory class=
- "net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
- properties="peerDiscovery=manual,
- rmiUrls=//server2:40000/sampleCache1|//server3:40000/sampleCache1
- | //server2:40000/sampleCache2|//server3:40000/sampleCache2"
- propertySeparator="," />
-
- In server2's configuration:
- <cacheManagerPeerProviderFactory class=
- "net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
- properties="peerDiscovery=manual,
- rmiUrls=//server1:40000/sampleCache1|//server3:40000/sampleCache1
- | //server1:40000/sampleCache2|//server3:40000/sampleCache2"
- propertySeparator="," />
-
- In server3's configuration:
- <cacheManagerPeerProviderFactory class=
- "net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
- properties="peerDiscovery=manual,
- rmiUrls=//server1:40000/sampleCache1|//server2:40000/sampleCache1
- | //server1:40000/sampleCache2|//server2:40000/sampleCache2"
- propertySeparator="," />
-
-
- Valid properties are:
- * peerDiscovery (mandatory) - specify "manual"
- * rmiUrls (mandatory) - specify a pipe separated list of rmiUrls, in the form
- //hostname:port
- * hostname (optional) - the hostname is the hostname of the remote CacheManager peer. The port is the listening
- port of the RMICacheManagerPeerListener of the remote CacheManager peer.
-
- JGroupsCacheManagerPeerProvider
- +++++++++++++++++++++++++++++++
- <cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheManagerPeerProviderFactory"
- properties="connect=UDP(mcast_addr=231.12.21.132;mcast_port=45566;ip_ttl=32;
- mcast_send_buf_size=150000;mcast_recv_buf_size=80000):
- PING(timeout=2000;num_initial_members=6):
- MERGE2(min_interval=5000;max_interval=10000):
- FD_SOCK:VERIFY_SUSPECT(timeout=1500):
- pbcast.NAKACK(gc_lag=10;retransmit_timeout=3000):
- UNICAST(timeout=5000):
- pbcast.STABLE(desired_avg_gossip=20000):
- FRAG:
- pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;shun=false;print_local_addr=false)"
- propertySeparator="::"
- />
- The only property necessary is the connect String used by jgroups to configure itself. Refer to the Jgroups documentation for explanation
- of all the protocols. The example above uses UDP multicast. If the connect property is not specified the default JGroups connection will be
- used.
-
-
- JMSCacheManagerPeerProviderFactory
- ++++++++++++++++++++++++++++++++++
- <cacheManagerPeerProviderFactory
- class="net.sf.ehcache.distribution.jms.JMSCacheManagerPeerProviderFactory"
- properties="..."
- propertySeparator=","
- />
-
- The JMS PeerProviderFactory uses JNDI to maintain message queue independence. Refer to the manual for full configuration
- examples using ActiveMQ and Open Message Queue.
-
- Valid properties are:
- * initialContextFactoryName (mandatory) - the name of the factory used to create the message queue initial context.
- * providerURL (mandatory) - the JNDI configuration information for the service provider to use.
- * topicConnectionFactoryBindingName (mandatory) - the JNDI binding name for the TopicConnectionFactory
- * topicBindingName (mandatory) - the JNDI binding name for the topic name
- * getQueueBindingName (mandatory only if using jmsCacheLoader) - the JNDI binding name for the queue name
- * securityPrincipalName - the JNDI java.naming.security.principal
- * securityCredentials - the JNDI java.naming.security.credentials
- * urlPkgPrefixes - the JNDI java.naming.factory.url.pkgs
- * userName - the user name to use when creating the TopicConnection to the Message Queue
- * password - the password to use when creating the TopicConnection to the Message Queue
- * acknowledgementMode - the JMS Acknowledgement mode for both publisher and subscriber. The available choices are
- AUTO_ACKNOWLEDGE, DUPS_OK_ACKNOWLEDGE and SESSION_TRANSACTED. The default is AUTO_ACKNOWLEDGE.
- -->
-<!-- <cacheManagerPeerProviderFactory-->
-<!-- class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"-->
-<!-- properties="peerDiscovery=automatic,-->
-<!-- multicastGroupAddress=230.0.0.1,-->
-<!-- multicastGroupPort=4446, timeToLive=1"-->
-<!-- propertySeparator=","-->
-<!-- />-->
-
-
- <!--
- CacheManagerPeerListener
- ========================
- (Enable for distributed operation)
-
- Specifies a CacheManagerPeerListenerFactory which will be used to create a
- CacheManagerPeerListener, which listens for messages from cache replicators participating in the cluster.
-
- The attributes of cacheManagerPeerListenerFactory are:
- class - a fully qualified factory class name
- properties - comma separated properties having meaning only to the factory.
-
- Ehcache comes with a built-in RMI-based distribution system. The listener component is
- RMICacheManagerPeerListener which is configured using
- RMICacheManagerPeerListenerFactory. It is configured as per the following example:
-
- <cacheManagerPeerListenerFactory
- class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
- properties="hostName=fully_qualified_hostname_or_ip,
- port=40001,
- remoteObjectPort=40002,
- socketTimeoutMillis=120000"
- propertySeparator="," />
-
- All properties are optional. They are:
- * hostName - the hostName of the host the listener is running on. Specify
- where the host is multihomed and you want to control the interface over which cluster
- messages are received. Defaults to the host name of the default interface if not
- specified.
- * port - the port the RMI Registry listener listens on. This defaults to a free port if not specified.
- * remoteObjectPort - the port number on which the remote objects bound in the registry receive calls.
- This defaults to a free port if not specified.
- * socketTimeoutMillis - the number of ms client sockets will stay open when sending
- messages to the listener. This should be long enough for the slowest message.
- If not specified it defaults to 120000ms.
-
- -->
-<!-- <cacheManagerPeerListenerFactory-->
-<!-- class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"/>-->
-
- <!-- Cache configuration.
-
- The following attributes are required.
-
- name:
- Sets the name of the cache. This is used to identify the cache. It must be unique.
-
- maxElementsInMemory:
- Sets the maximum number of objects that will be created in memory
-
- maxElementsOnDisk:
- Sets the maximum number of objects that will be maintained in the DiskStore
- The default value is zero, meaning unlimited.
-
- eternal:
- Sets whether elements are eternal. If eternal, timeouts are ignored and the
- element is never expired.
-
- overflowToDisk:
- Sets whether elements can overflow to disk when the memory store
- has reached the maxInMemory limit.
-
- The following attributes are optional.
-
- timeToIdleSeconds:
- Sets the time to idle for an element before it expires.
- i.e. The maximum amount of time between accesses before an element expires
- Is only used if the element is not eternal.
- Optional attribute. A value of 0 means that an Element can idle for infinity.
- The default value is 0.
-
- timeToLiveSeconds:
- Sets the time to live for an element before it expires.
- i.e. The maximum time between creation time and when an element expires.
- Is only used if the element is not eternal.
- Optional attribute. A value of 0 means that and Element can live for infinity.
- The default value is 0.
-
- diskPersistent:
- Whether the disk store persists between restarts of the Virtual Machine.
- The default value is false.
-
- diskExpiryThreadIntervalSeconds:
- The number of seconds between runs of the disk expiry thread. The default value
- is 120 seconds.
-
- memoryStoreEvictionPolicy:
- Policy would be enforced upon reaching the maxElementsInMemory limit. Default
- policy is Least Recently Used (specified as LRU). Other policies available -
- First In First Out (specified as FIFO) and Less Frequently Used
- (specified as LFU)
-
- -->
-
- <!--
- Mandatory Default Cache configuration. These settings will be applied to caches
- created programmtically using CacheManager.add(String cacheName)
- -->
- <defaultCache
- maxElementsInMemory="20000"
- eternal="true"
- overflowToDisk="false"
- memoryStoreEvictionPolicy="LRU"
- />
-
- <cache name="org.hibernate.cache.StandardQueryCache"
- maxElementsInMemory="10000"
- eternal="true"
- overflowToDisk="false"
- memoryStoreEvictionPolicy="LRU"/>
-
- <cache name="org.hibernate.cache.UpdateTimestampsCache"
- maxElementsInMemory="10000"
- eternal="true"
- overflowToDisk="false"/>
-
- <cache name="PageCache"
- maxElementsInMemory="1000"
- eternal="false"
- overflowToDisk="true"
- timeToIdleSeconds="1000"
- timeToLiveSeconds="1000"
- memoryStoreEvictionPolicy="LRU"/>
-
-<!-- uncomment to enable cache debugging -->
-<!--
- <cacheManagerPeerListenerFactory
- class="org.terracotta.ehcachedx.monitor.probe.ProbePeerListenerFactory"
- properties="monitorAddress=localhost, monitorPort=9889" />
--->
-
-</ehcache>
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2c5e8529/libraries/kiwi/kiwi-caching-ehcache/pom.xml
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-ehcache/pom.xml b/libraries/kiwi/kiwi-caching-ehcache/pom.xml
new file mode 100644
index 0000000..48a727d
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-ehcache/pom.xml
@@ -0,0 +1,117 @@
+<?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-ehcache</artifactId>
+ <packaging>jar</packaging>
+
+ <name>KiWi Triplestore: EHCache Cache Backend</name>
+ <description>
+ EHCache cache implementation for the KiWi triplestore. Useful for single-machine production environments.
+ </description>
+
+
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.marmotta</groupId>
+ <artifactId>kiwi-triplestore</artifactId>
+ </dependency>
+
+ <!-- Caching -->
+ <dependency>
+ <groupId>net.sf.ehcache</groupId>
+ <artifactId>ehcache</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-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/2c5e8529/libraries/kiwi/kiwi-caching-ehcache/src/main/java/org/apache/marmotta/kiwi/ehcache/caching/EHCacheManager.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-ehcache/src/main/java/org/apache/marmotta/kiwi/ehcache/caching/EHCacheManager.java b/libraries/kiwi/kiwi-caching-ehcache/src/main/java/org/apache/marmotta/kiwi/ehcache/caching/EHCacheManager.java
new file mode 100644
index 0000000..65d7502
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-ehcache/src/main/java/org/apache/marmotta/kiwi/ehcache/caching/EHCacheManager.java
@@ -0,0 +1,201 @@
+/*
+ * 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.ehcache.caching;
+
+import org.apache.marmotta.kiwi.caching.CacheManager;
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+import org.apache.marmotta.kiwi.ehcache.util.CacheMap;
+import org.apache.marmotta.kiwi.model.rdf.*;
+
+import java.util.Map;
+
+/**
+ * KiWi Cache Manager implementation based on EHCache. Best used for single machine production environments.
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class EHCacheManager implements CacheManager {
+
+
+ private net.sf.ehcache.CacheManager cacheManager;
+
+ private CacheMap<Long,KiWiNode> nodeCache;
+ private CacheMap<Long,KiWiTriple> tripleCache;
+ private CacheMap<String,KiWiUriResource> uriCache;
+ private CacheMap<String,KiWiAnonResource> bnodeCache;
+ private CacheMap<String,KiWiLiteral> literalCache;
+ private CacheMap<String,KiWiNamespace> nsPrefixCache;
+ private CacheMap<String,KiWiNamespace> nsUriCache;
+
+ private CacheMap<Long,Long> registryCache;
+
+ public EHCacheManager(KiWiConfiguration configuration) {
+ cacheManager = net.sf.ehcache.CacheManager.newInstance(EHCacheManager.class.getResource("/ehcache-kiwi.xml"));
+ if(configuration.getClusterName() != null) {
+ cacheManager.setName(configuration.getClusterName());
+ }
+ }
+
+
+ /**
+ * 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() {
+ if(nodeCache == null) {
+ nodeCache = new CacheMap<>(cacheManager.getCache((NODE_CACHE)));
+ }
+
+ 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
+ */
+ @Override
+ public Map<Long, KiWiTriple> getTripleCache() {
+ if(tripleCache == null) {
+ tripleCache = new CacheMap<>(cacheManager.getCache((TRIPLE_CACHE)));
+ }
+
+ 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
+ */
+ @Override
+ public Map<String, KiWiUriResource> getUriCache() {
+ if(uriCache == null) {
+ uriCache = new CacheMap<>(cacheManager.getCache((URI_CACHE)));
+ }
+
+ 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
+ */
+ @Override
+ public Map<String, KiWiAnonResource> getBNodeCache() {
+ if(bnodeCache == null) {
+ bnodeCache = new CacheMap<>(cacheManager.getCache((BNODE_CACHE)));
+ }
+
+ 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.
+ *
+ * @return
+ * @see org.apache.marmotta.commons.sesame.model.LiteralCommons#createCacheKey(String, java.util.Locale, String)
+ */
+ @Override
+ public Map<String, KiWiLiteral> getLiteralCache() {
+ if(literalCache == null) {
+ literalCache = new CacheMap<>(cacheManager.getCache((LITERAL_CACHE)));
+ }
+
+ return literalCache;
+ }
+
+ /**
+ * Return the URI -> namespace cache from the cache manager. Used for looking up namespaces
+ *
+ * @return
+ */
+ @Override
+ public Map<String, KiWiNamespace> getNamespaceUriCache() {
+ if(nsUriCache == null) {
+ nsUriCache = new CacheMap<>(cacheManager.getCache((NS_URI_CACHE)));
+ }
+
+ return nsUriCache;
+ }
+
+ /**
+ * Return the prefix -> namespace cache from the cache manager. Used for looking up namespaces
+ *
+ * @return
+ */
+ @Override
+ public Map<String, KiWiNamespace> getNamespacePrefixCache() {
+ if(nsPrefixCache == null) {
+ nsPrefixCache = new CacheMap<>(cacheManager.getCache((NS_PREFIX_CACHE)));
+ }
+
+ 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
+ */
+ @Override
+ public Map<Long, Long> getRegistryCache() {
+ if(registryCache == null) {
+ registryCache = new CacheMap<>(cacheManager.getCache((REGISTRY_CACHE)));
+ }
+
+ 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) {
+ return new CacheMap(cacheManager.getCache((name)));
+ }
+
+ /**
+ * Clear all caches managed by this cache manager.
+ */
+ @Override
+ public void clear() {
+ cacheManager.clearAll();
+ }
+
+ /**
+ * Shutdown this cache manager instance. Will shutdown the underlying EHCache cache manager.
+ */
+ @Override
+ public void shutdown() {
+ cacheManager.shutdown();
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2c5e8529/libraries/kiwi/kiwi-caching-ehcache/src/main/java/org/apache/marmotta/kiwi/ehcache/caching/EHCacheManagerFactory.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-ehcache/src/main/java/org/apache/marmotta/kiwi/ehcache/caching/EHCacheManagerFactory.java b/libraries/kiwi/kiwi-caching-ehcache/src/main/java/org/apache/marmotta/kiwi/ehcache/caching/EHCacheManagerFactory.java
new file mode 100644
index 0000000..f315e1b
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-ehcache/src/main/java/org/apache/marmotta/kiwi/ehcache/caching/EHCacheManagerFactory.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.ehcache.caching;
+
+import org.apache.marmotta.kiwi.caching.CacheManager;
+import org.apache.marmotta.kiwi.caching.CacheManagerFactory;
+import org.apache.marmotta.kiwi.config.KiWiConfiguration;
+
+/**
+ * Create EHCacheManager instances.
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class EHCacheManagerFactory implements 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
+ */
+ @Override
+ public CacheManager createCacheManager(KiWiConfiguration configuration) {
+ return new EHCacheManager(configuration);
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2c5e8529/libraries/kiwi/kiwi-caching-ehcache/src/main/java/org/apache/marmotta/kiwi/ehcache/util/CacheMap.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-ehcache/src/main/java/org/apache/marmotta/kiwi/ehcache/util/CacheMap.java b/libraries/kiwi/kiwi-caching-ehcache/src/main/java/org/apache/marmotta/kiwi/ehcache/util/CacheMap.java
new file mode 100644
index 0000000..7bfefb6
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-ehcache/src/main/java/org/apache/marmotta/kiwi/ehcache/util/CacheMap.java
@@ -0,0 +1,144 @@
+/*
+ * 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.ehcache.util;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.ImmutableSet;
+import net.sf.ehcache.Cache;
+import net.sf.ehcache.Element;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A map API wrapper around EHCache caches so it is compatible with the KiWi caching API.
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class CacheMap<K,V> implements Map<K,V> {
+
+ private Cache delegate;
+
+ public CacheMap(Cache delegate) {
+ this.delegate = delegate;
+ }
+
+ @Override
+ public int size() {
+ return delegate.getSize();
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return delegate.getSize() == 0;
+ }
+
+ @Override
+ public boolean containsKey(Object o) {
+ return delegate.isKeyInCache(o);
+ }
+
+ @Override
+ public boolean containsValue(Object o) {
+ return delegate.isValueInCache(o);
+ }
+
+ @Override
+ public V get(Object o) {
+ Element e = delegate.get(o);
+
+ if(e != null) {
+ return (V) e.getObjectValue();
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public V put(K k, V v) {
+ Element e = delegate.get(k);
+ delegate.put(new Element(k, v));
+
+ if(e != null) {
+ return (V) e.getObjectValue();
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public V remove(Object o) {
+ Element e = delegate.removeAndReturnElement(o);
+ if(e != null) {
+ return (V) e.getObjectValue();
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public void putAll(Map<? extends K, ? extends V> map) {
+ for(Map.Entry entry : map.entrySet()) {
+ put((K)entry.getKey(), (V)entry.getValue());
+ }
+ }
+
+ @Override
+ public void clear() {
+ delegate.removeAll();
+ }
+
+ @Override
+ public Set<K> keySet() {
+ return ImmutableSet.copyOf(delegate.getKeys());
+ }
+
+ @Override
+ public Collection<V> values() {
+ throw new UnsupportedOperationException("listing values not supported by cache");
+ }
+
+ @Override
+ public Set<Entry<K, V>> entrySet() {
+ return ImmutableSet.copyOf(Collections2.transform(delegate.getKeys(), new Function<K,Entry<K,V>> () {
+ @Override
+ public Entry<K, V> apply(final K input) {
+ final Element e = delegate.get(input);
+ return new Entry<K,V>() {
+ @Override
+ public K getKey() {
+ return input;
+ }
+
+ @Override
+ public V getValue() {
+ return (V) e.getObjectValue();
+ }
+
+ @Override
+ public V setValue(V v) {
+ delegate.put(new Element(input,v));
+ return (V) e.getObjectValue();
+ }
+ };
+ }
+ }));
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2c5e8529/libraries/kiwi/kiwi-caching-ehcache/src/main/resources/META-INF/services/org.apache.marmotta.kiwi.caching.CacheManagerFactory
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-ehcache/src/main/resources/META-INF/services/org.apache.marmotta.kiwi.caching.CacheManagerFactory b/libraries/kiwi/kiwi-caching-ehcache/src/main/resources/META-INF/services/org.apache.marmotta.kiwi.caching.CacheManagerFactory
new file mode 100644
index 0000000..6fd37b2
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-ehcache/src/main/resources/META-INF/services/org.apache.marmotta.kiwi.caching.CacheManagerFactory
@@ -0,0 +1 @@
+org.apache.marmotta.kiwi.ehcache.caching.EHCacheManagerFactory
[02/32] git commit: Merge branch 'master' of
https://git-wip-us.apache.org/repos/asf/incubator-marmotta
Posted by ss...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-marmotta
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/a9bf7e4f
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/a9bf7e4f
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/a9bf7e4f
Branch: refs/heads/develop
Commit: a9bf7e4fa56f00e26e09a5fae002686eb65631df
Parents: be31f8a cdb3223
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Mon Sep 30 18:41:26 2013 +0200
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Mon Sep 30 18:41:26 2013 +0200
----------------------------------------------------------------------
----------------------------------------------------------------------
[21/32] 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/develop
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;
}
[32/32] git commit: cleanup old EHCache files (MARMOTTA-443)
Posted by ss...@apache.org.
cleanup old EHCache files (MARMOTTA-443)
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/374513a2
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/374513a2
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/374513a2
Branch: refs/heads/develop
Commit: 374513a21e8da1da51b8ab2386031309f2ed11af
Parents: d04e10b
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Mon Mar 17 11:19:31 2014 +0100
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Mon Mar 17 11:19:31 2014 +0100
----------------------------------------------------------------------
.../src/test/resources/arquillian.xml | 27 --
.../src/test/resources/ehcache.xml | 377 -------------------
2 files changed, 404 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/374513a2/launchers/marmotta-webapp/src/test/resources/arquillian.xml
----------------------------------------------------------------------
diff --git a/launchers/marmotta-webapp/src/test/resources/arquillian.xml b/launchers/marmotta-webapp/src/test/resources/arquillian.xml
deleted file mode 100644
index 379bb29..0000000
--- a/launchers/marmotta-webapp/src/test/resources/arquillian.xml
+++ /dev/null
@@ -1,27 +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.
--->
-
-<arquillian xmlns="http://jboss.com/arquillian"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:tomcat6="urn:arq:org.jboss.arquillian.container.tomcat.embedded_6"
- xsi:schemaLocation="http://jboss.com/arquillian ">
-
- <tomcat6:container>
- <tomcat6:unpackArchive>true</tomcat6:unpackArchive>
- </tomcat6:container>
-
-</arquillian>
http://git-wip-us.apache.org/repos/asf/marmotta/blob/374513a2/launchers/marmotta-webapp/src/test/resources/ehcache.xml
----------------------------------------------------------------------
diff --git a/launchers/marmotta-webapp/src/test/resources/ehcache.xml b/launchers/marmotta-webapp/src/test/resources/ehcache.xml
deleted file mode 100644
index 7cd8120..0000000
--- a/launchers/marmotta-webapp/src/test/resources/ehcache.xml
+++ /dev/null
@@ -1,377 +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.
--->
-
-<!--
-CacheManager Configuration
-==========================
-An ehcache-marmotta.xml corresponds to a single CacheManager.
-
-See instructions below or the ehcache schema (ehcache.xsd) on how to configure.
-
-System property tokens can be specified in this file which are replaced when the configuration
-is loaded. For example multicastGroupPort=${multicastGroupPort} can be replaced with the
-System property either from an environment variable or a system property specified with a
-command line switch such as -DmulticastGroupPort=4446.
-
-The attributes of <ehcache> are:
-* name - an optional name for the CacheManager. The name is optional and primarily used
-for documentation or to distinguish Terracotta clustered cache state. With Terracotta
-clustered caches, a combination of CacheManager name and cache name uniquely identify a
-particular cache store in the Terracotta clustered memory.
-* updateCheck - an optional boolean flag specifying whether this CacheManager should check
-for new versions of Ehcache over the Internet. If not specified, updateCheck="true".
-* monitoring - an optional setting that determines whether the CacheManager should
-automatically register the SampledCacheMBean with the system MBean server. Currently,
-this monitoring is only useful when using Terracotta and thus the "autodetect" value
-will detect the presence of Terracotta and register the MBean. Other allowed values
-are "on" and "off". The default is "autodetect".
--->
-<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd">
-
- <!--
- DiskStore configuration
- =======================
-
- The diskStore element is optional. To turn off disk store path creation, comment out the diskStore
- element below.
-
- Configure it if you have overflowToDisk or diskPersistent enabled for any cache.
-
- If it is not configured, and a cache is created which requires a disk store, a warning will be
- issued and java.io.tmpdir will automatically be used.
-
- diskStore has only one attribute - "path". It is the path to the directory where
- .data and .index files will be created.
-
- If the path is one of the following Java System Property it is replaced by its value in the
- running VM. For backward compatibility these are not specified without being enclosed in the ${token}
- replacement syntax.
-
- The following properties are translated:
- * user.home - KiWiUser's home directory
- * user.dir - KiWiUser's current working directory
- * java.io.tmpdir - Default temp file path
- * ehcache.disk.store.dir - A system property you would normally specify on the command line
- e.g. java -Dehcache.disk.store.dir=/u01/myapp/diskdir ...
-
- Subdirectories can be specified below the property e.g. java.io.tmpdir/one
-
- -->
- <diskStore path="java.io.tmpdir"/>
-
- <!--
- Cachemanagereventlistener
- =========================
- Specifies a CacheManagerEventListenerFactory which is notified when Caches are added
- or removed from the CacheManager.
-
- The attributes of CacheManagerEventListenerFactory are:
- * class - a fully qualified factory class name
- * properties - comma separated properties having meaning only to the factory.
-
- Sets the fully qualified class name to be registered as the CacheManager event listener.
-
- The events include:
- * adding a Cache
- * removing a Cache
-
- Callbacks to listener methods are synchronous and unsynchronized. It is the responsibility
- of the implementer to safely handle the potential performance and thread safety issues
- depending on what their listener is doing.
-
- If no class is specified, no listener is created. There is no default.
- -->
- <cacheManagerEventListenerFactory class="" properties=""/>
-
-
- <!--
- CacheManagerPeerProvider
- ========================
- (For distributed operation)
-
- Specifies a CacheManagerPeerProviderFactory which will be used to create a
- CacheManagerPeerProvider, which discovers other CacheManagers in the cluster.
-
- One or more providers can be configured. The first one in the ehcache-marmotta.xml is the default, which is used
- for replication and bootstrapping.
-
- The attributes of cacheManagerPeerProviderFactory are:
- * class - a fully qualified factory class name
- * properties - comma separated properties having meaning only to the factory.
-
- Providers are available for RMI, JGroups and JMS as shown following.
-
- RMICacheManagerPeerProvider
- +++++++++++++++++++++++++++
-
- Ehcache comes with a built-in RMI-based distribution system with two means of discovery of
- CacheManager peers participating in the cluster:
- * automatic, using a multicast group. This one automatically discovers peers and detects
- changes such as peers entering and leaving the group
- * manual, using manual rmiURL configuration. A hardcoded list of peers is provided at
- configuration time.
-
- Configuring Automatic Discovery:
- Automatic discovery is configured as per the following example:
- <cacheManagerPeerProviderFactory
- class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
- properties="hostName=fully_qualified_hostname_or_ip,
- peerDiscovery=automatic, multicastGroupAddress=230.0.0.1,
- multicastGroupPort=4446, timeToLive=32"/>
-
- Valid properties are:
- * peerDiscovery (mandatory) - specify "automatic"
- * multicastGroupAddress (mandatory) - specify a valid multicast group address
- * multicastGroupPort (mandatory) - specify a dedicated port for the multicast heartbeat
- traffic
- * timeToLive - specify a value between 0 and 255 which determines how far the packets will
- propagate.
-
- By convention, the restrictions are:
- 0 - the same host
- 1 - the same subnet
- 32 - the same site
- 64 - the same region
- 128 - the same continent
- 255 - unrestricted
-
- * hostName - the hostname or IP of the interface to be used for sending and receiving multicast packets
- (relevant to mulithomed hosts only)
-
- Configuring Manual Discovery:
- Manual discovery requires a unique configuration per host. It is contains a list of rmiURLs for the peers, other
- than itself. So, if we have server1, server2 and server3 the configuration will be:
-
- In server1's configuration:
- <cacheManagerPeerProviderFactory class=
- "net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
- properties="peerDiscovery=manual,
- rmiUrls=//server2:40000/sampleCache1|//server3:40000/sampleCache1
- | //server2:40000/sampleCache2|//server3:40000/sampleCache2"
- propertySeparator="," />
-
- In server2's configuration:
- <cacheManagerPeerProviderFactory class=
- "net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
- properties="peerDiscovery=manual,
- rmiUrls=//server1:40000/sampleCache1|//server3:40000/sampleCache1
- | //server1:40000/sampleCache2|//server3:40000/sampleCache2"
- propertySeparator="," />
-
- In server3's configuration:
- <cacheManagerPeerProviderFactory class=
- "net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
- properties="peerDiscovery=manual,
- rmiUrls=//server1:40000/sampleCache1|//server2:40000/sampleCache1
- | //server1:40000/sampleCache2|//server2:40000/sampleCache2"
- propertySeparator="," />
-
-
- Valid properties are:
- * peerDiscovery (mandatory) - specify "manual"
- * rmiUrls (mandatory) - specify a pipe separated list of rmiUrls, in the form
- //hostname:port
- * hostname (optional) - the hostname is the hostname of the remote CacheManager peer. The port is the listening
- port of the RMICacheManagerPeerListener of the remote CacheManager peer.
-
- JGroupsCacheManagerPeerProvider
- +++++++++++++++++++++++++++++++
- <cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheManagerPeerProviderFactory"
- properties="connect=UDP(mcast_addr=231.12.21.132;mcast_port=45566;ip_ttl=32;
- mcast_send_buf_size=150000;mcast_recv_buf_size=80000):
- PING(timeout=2000;num_initial_members=6):
- MERGE2(min_interval=5000;max_interval=10000):
- FD_SOCK:VERIFY_SUSPECT(timeout=1500):
- pbcast.NAKACK(gc_lag=10;retransmit_timeout=3000):
- UNICAST(timeout=5000):
- pbcast.STABLE(desired_avg_gossip=20000):
- FRAG:
- pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;shun=false;print_local_addr=false)"
- propertySeparator="::"
- />
- The only property necessary is the connect String used by jgroups to configure itself. Refer to the Jgroups documentation for explanation
- of all the protocols. The example above uses UDP multicast. If the connect property is not specified the default JGroups connection will be
- used.
-
-
- JMSCacheManagerPeerProviderFactory
- ++++++++++++++++++++++++++++++++++
- <cacheManagerPeerProviderFactory
- class="net.sf.ehcache.distribution.jms.JMSCacheManagerPeerProviderFactory"
- properties="..."
- propertySeparator=","
- />
-
- The JMS PeerProviderFactory uses JNDI to maintain message queue independence. Refer to the manual for full configuration
- examples using ActiveMQ and Open Message Queue.
-
- Valid properties are:
- * initialContextFactoryName (mandatory) - the name of the factory used to create the message queue initial context.
- * providerURL (mandatory) - the JNDI configuration information for the service provider to use.
- * topicConnectionFactoryBindingName (mandatory) - the JNDI binding name for the TopicConnectionFactory
- * topicBindingName (mandatory) - the JNDI binding name for the topic name
- * getQueueBindingName (mandatory only if using jmsCacheLoader) - the JNDI binding name for the queue name
- * securityPrincipalName - the JNDI java.naming.security.principal
- * securityCredentials - the JNDI java.naming.security.credentials
- * urlPkgPrefixes - the JNDI java.naming.factory.url.pkgs
- * userName - the user name to use when creating the TopicConnection to the Message Queue
- * password - the password to use when creating the TopicConnection to the Message Queue
- * acknowledgementMode - the JMS Acknowledgement mode for both publisher and subscriber. The available choices are
- AUTO_ACKNOWLEDGE, DUPS_OK_ACKNOWLEDGE and SESSION_TRANSACTED. The default is AUTO_ACKNOWLEDGE.
- -->
-<!-- <cacheManagerPeerProviderFactory-->
-<!-- class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"-->
-<!-- properties="peerDiscovery=automatic,-->
-<!-- multicastGroupAddress=230.0.0.1,-->
-<!-- multicastGroupPort=4446, timeToLive=1"-->
-<!-- propertySeparator=","-->
-<!-- />-->
-
-
- <!--
- CacheManagerPeerListener
- ========================
- (Enable for distributed operation)
-
- Specifies a CacheManagerPeerListenerFactory which will be used to create a
- CacheManagerPeerListener, which listens for messages from cache replicators participating in the cluster.
-
- The attributes of cacheManagerPeerListenerFactory are:
- class - a fully qualified factory class name
- properties - comma separated properties having meaning only to the factory.
-
- Ehcache comes with a built-in RMI-based distribution system. The listener component is
- RMICacheManagerPeerListener which is configured using
- RMICacheManagerPeerListenerFactory. It is configured as per the following example:
-
- <cacheManagerPeerListenerFactory
- class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
- properties="hostName=fully_qualified_hostname_or_ip,
- port=40001,
- remoteObjectPort=40002,
- socketTimeoutMillis=120000"
- propertySeparator="," />
-
- All properties are optional. They are:
- * hostName - the hostName of the host the listener is running on. Specify
- where the host is multihomed and you want to control the interface over which cluster
- messages are received. Defaults to the host name of the default interface if not
- specified.
- * port - the port the RMI Registry listener listens on. This defaults to a free port if not specified.
- * remoteObjectPort - the port number on which the remote objects bound in the registry receive calls.
- This defaults to a free port if not specified.
- * socketTimeoutMillis - the number of ms client sockets will stay open when sending
- messages to the listener. This should be long enough for the slowest message.
- If not specified it defaults to 120000ms.
-
- -->
-<!-- <cacheManagerPeerListenerFactory-->
-<!-- class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"/>-->
-
- <!-- Cache configuration.
-
- The following attributes are required.
-
- name:
- Sets the name of the cache. This is used to identify the cache. It must be unique.
-
- maxElementsInMemory:
- Sets the maximum number of objects that will be created in memory
-
- maxElementsOnDisk:
- Sets the maximum number of objects that will be maintained in the DiskStore
- The default value is zero, meaning unlimited.
-
- eternal:
- Sets whether elements are eternal. If eternal, timeouts are ignored and the
- element is never expired.
-
- overflowToDisk:
- Sets whether elements can overflow to disk when the memory store
- has reached the maxInMemory limit.
-
- The following attributes are optional.
-
- timeToIdleSeconds:
- Sets the time to idle for an element before it expires.
- i.e. The maximum amount of time between accesses before an element expires
- Is only used if the element is not eternal.
- Optional attribute. A value of 0 means that an Element can idle for infinity.
- The default value is 0.
-
- timeToLiveSeconds:
- Sets the time to live for an element before it expires.
- i.e. The maximum time between creation time and when an element expires.
- Is only used if the element is not eternal.
- Optional attribute. A value of 0 means that and Element can live for infinity.
- The default value is 0.
-
- diskPersistent:
- Whether the disk store persists between restarts of the Virtual Machine.
- The default value is false.
-
- diskExpiryThreadIntervalSeconds:
- The number of seconds between runs of the disk expiry thread. The default value
- is 120 seconds.
-
- memoryStoreEvictionPolicy:
- Policy would be enforced upon reaching the maxElementsInMemory limit. Default
- policy is Least Recently Used (specified as LRU). Other policies available -
- First In First Out (specified as FIFO) and Less Frequently Used
- (specified as LFU)
-
- -->
-
- <!--
- Mandatory Default Cache configuration. These settings will be applied to caches
- created programmtically using CacheManager.add(String cacheName)
- -->
- <defaultCache
- maxElementsInMemory="20000"
- eternal="true"
- overflowToDisk="false"
- memoryStoreEvictionPolicy="LRU"
- />
-
- <cache name="org.hibernate.cache.StandardQueryCache"
- maxElementsInMemory="10000"
- eternal="true"
- overflowToDisk="false"
- memoryStoreEvictionPolicy="LRU"/>
-
- <cache name="org.hibernate.cache.UpdateTimestampsCache"
- maxElementsInMemory="10000"
- eternal="true"
- overflowToDisk="false"/>
-
- <cache name="PageCache"
- maxElementsInMemory="1000"
- eternal="false"
- overflowToDisk="true"
- timeToIdleSeconds="1000"
- timeToLiveSeconds="1000"
- memoryStoreEvictionPolicy="LRU"/>
-
-<!-- uncomment to enable cache debugging -->
-<!--
- <cacheManagerPeerListenerFactory
- class="org.terracotta.ehcachedx.monitor.probe.ProbePeerListenerFactory"
- properties="monitorAddress=localhost, monitorPort=9889" />
--->
-
-</ehcache>
[29/32] - re-added support for EHCache as KiWi caching backend
(MARMOTTA-450) - cleanup old use of EHCache (MARMOTTA-443)
Posted by ss...@apache.org.
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2c5e8529/libraries/kiwi/kiwi-caching-ehcache/src/main/resources/ehcache-kiwi.xml
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-ehcache/src/main/resources/ehcache-kiwi.xml b/libraries/kiwi/kiwi-caching-ehcache/src/main/resources/ehcache-kiwi.xml
new file mode 100644
index 0000000..79af086
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-ehcache/src/main/resources/ehcache-kiwi.xml
@@ -0,0 +1,767 @@
+<?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.
+
+-->
+<!--
+CacheManager Configuration
+==========================
+An ehcache.xml corresponds to a single CacheManager.
+
+See instructions below or the ehcache schema (ehcache.xsd) on how to configure.
+
+System property tokens can be specified in this file which are replaced when the configuration
+is loaded. For example multicastGroupPort=${multicastGroupPort} can be replaced with the
+System property either from an environment variable or a system property specified with a
+command line switch such as -DmulticastGroupPort=4446. Another example, useful for Terracotta
+server based deployments is <terracottaConfig url="${serverAndPort}"/ and specify a command line
+switch of -Dserver36:9510
+
+The attributes of <ehcache> are:
+* name - an optional name for the CacheManager. The name is optional and primarily used
+for documentation or to distinguish Terracotta clustered cache state. With Terracotta
+clustered caches, a combination of CacheManager name and cache name uniquely identify a
+particular cache store in the Terracotta clustered memory.
+* updateCheck - an optional boolean flag specifying whether this CacheManager should check
+for new versions of Ehcache over the Internet. If not specified, updateCheck="true".
+* dynamicConfig - an optional setting that can be used to disable dynamic configuration of caches
+associated with this CacheManager. By default this is set to true - i.e. dynamic configuration
+is enabled. Dynamically configurable caches can have their TTI, TTL and maximum disk and
+in-memory capacity changed at runtime through the cache's configuration object.
+* monitoring - an optional setting that determines whether the CacheManager should
+automatically register the SampledCacheMBean with the system MBean server.
+
+Currently, this monitoring is only useful when using Terracotta clustering and using the
+Terracotta Developer Console. With the "autodetect" value, the presence of Terracotta clustering
+will be detected and monitoring, via the Developer Console, will be enabled. Other allowed values
+are "on" and "off". The default is "autodetect". This setting does not perform any function when
+used with JMX monitors.
+
+* maxBytesLocalHeap - optional setting that constraints the memory usage of the Caches managed by the CacheManager
+to use at most the specified number of bytes of the local VM's heap.
+* maxBytesLocalOffHeap - optional setting that constraints the offHeap usage of the Caches managed by the CacheManager
+to use at most the specified number of bytes of the local VM's offHeap memory.
+* maxBytesLocalDisk - optional setting that constraints the disk usage of the Caches managed by the CacheManager
+to use at most the specified number of bytes of the local disk.
+
+These settings let you define "resource pools", caches will share. For instance setting maxBytesLocalHeap to 100M, will result in
+all caches sharing 100 MegaBytes of ram. The CacheManager will balance these 100 MB across all caches based on their respective usage
+patterns. You can allocate a precise amount of bytes to a particular cache by setting the appropriate maxBytes* attribute for that cache.
+That amount will be subtracted from the CacheManager pools, so that if a cache a specified 30M requirement, the other caches will share
+the remaining 70M.
+
+Also, specifying a maxBytesLocalOffHeap at the CacheManager level will result in overflowToOffHeap to be true by default. If you don't want
+a specific cache to overflow to off heap, you'll have to set overflowToOffHeap="false" explicitly
+
+Here is an example of CacheManager level resource tuning, which will use up to 400M of heap and 2G of offHeap:
+
+<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="ehcache.xsd"
+ updateCheck="true" monitoring="autodetect"
+ dynamicConfig="true" maxBytesLocalHeap="400M" maxBytesLocalOffHeap="2G">
+
+-->
+<ehcache name="kiwi"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ updateCheck="false"
+ maxBytesLocalHeap="60%"
+ dynamicConfig="false"
+ xsi:noNamespaceSchemaLocation="http://ehcache.sf.net/ehcache.xsd">
+
+ <!--
+ DiskStore configuration
+ =======================
+
+ The diskStore element is optional. To turn off disk store path creation, comment out the diskStore
+ element below.
+
+ Configure it if you have overflowToDisk or diskPersistent enabled for any cache.
+
+ If it is not configured, and a cache is created which requires a disk store, a warning will be
+ issued and java.io.tmpdir will automatically be used.
+
+ diskStore has only one attribute - "path". It is the path to the directory where
+ .data and .index files will be created.
+
+ If the path is one of the following Java System Property it is replaced by its value in the
+ running VM. For backward compatibility these are not specified without being enclosed in the ${token}
+ replacement syntax.
+
+ The following properties are translated:
+ * user.home - KiWiUser's home directory
+ * user.dir - KiWiUser's current working directory
+ * java.io.tmpdir - Default temp file path
+ * ehcache.disk.store.dir - A system property you would normally specify on the command line
+ e.g. java -Dehcache.disk.store.dir=/u01/myapp/diskdir ...
+
+ Subdirectories can be specified below the property e.g. java.io.tmpdir/one
+
+ -->
+ <diskStore path="java.io.tmpdir/kiwi-cache"/>
+
+
+ <!--
+ Cache configuration
+ ===================
+
+ The following attributes are required.
+
+ name:
+ Sets the name of the cache. This is used to identify the cache. It must be unique.
+
+ maxEntriesLocalHeap:
+ Sets the maximum number of objects that will be held on heap memory. 0 = no limit.
+
+ maxEntriesLocalDisk:
+ Sets the maximum number of objects that will be maintained in the DiskStore
+ The default value is zero, meaning unlimited.
+
+ eternal:
+ Sets whether elements are eternal. If eternal, timeouts are ignored and the
+ element is never expired.
+
+ The following attributes and elements are optional.
+
+ maxEntriesInCache:
+ This feature is applicable only to Terracotta distributed caches.
+ Sets the maximum number of entries that can be stored in the cluster. 0 = no limit.
+ Note that clustered cache will still perform eviction if resource usage requires it.
+ This property can be modified dynamically while the cache is operating.
+
+ overflowToOffHeap:
+ (boolean) This feature is available only in enterprise versions of Ehcache.
+ When set to true, enables the cache to utilize off-heap memory
+ storage to improve performance. Off-heap memory is not subject to Java
+ GC. The default value is false.
+
+ maxBytesLocalHeap:
+ Defines how many bytes the cache may use from the VM's heap. If a CacheManager
+ maxBytesLocalHeap has been defined, this Cache's specified amount will be
+ subtracted from the CacheManager. Other caches will share the remainder.
+ This attribute's values are given as <number>k|K|m|M|g|G for
+ kilobytes (k|K), megabytes (m|M), or gigabytes (g|G).
+ For example, maxBytesLocalHeap="2g" allots 2 gigabytes of heap memory.
+ If you specify a maxBytesLocalHeap, you can't use the maxEntriesLocalHeap attribute.
+ maxEntriesLocalHeap can't be used if a CacheManager maxBytesLocalHeap is set.
+
+ Elements put into the cache will be measured in size using net.sf.ehcache.pool.sizeof.SizeOf
+ If you wish to ignore some part of the object graph, see net.sf.ehcache.pool.sizeof.annotations.IgnoreSizeOf
+
+ maxBytesLocalOffHeap:
+ This feature is available only in enterprise versions of Ehcache.
+ Sets the amount of off-heap memory this cache can use, and will reserve.
+
+ This setting will set overflowToOffHeap to true. Set explicitly to false to disable overflow behavior.
+
+ Note that it is recommended to set maxEntriesLocalHeap to at least 100 elements
+ when using an off-heap store, otherwise performance will be seriously degraded,
+ and a warning will be logged.
+
+ The minimum amount that can be allocated is 128MB. There is no maximum.
+
+ maxBytesLocalDisk:
+ As for maxBytesLocalHeap, but specifies the limit of disk storage this cache will ever use.
+
+ timeToIdleSeconds:
+ Sets the time to idle for an element before it expires.
+ i.e. The maximum amount of time between accesses before an element expires
+ Is only used if the element is not eternal.
+ Optional attribute. A value of 0 means that an Element can idle for infinity.
+ The default value is 0.
+
+ timeToLiveSeconds:
+ Sets the time to live for an element before it expires.
+ i.e. The maximum time between creation time and when an element expires.
+ Is only used if the element is not eternal.
+ Optional attribute. A value of 0 means that and Element can live for infinity.
+ The default value is 0.
+
+ diskExpiryThreadIntervalSeconds:
+ The number of seconds between runs of the disk expiry thread. The default value
+ is 120 seconds.
+
+ diskSpoolBufferSizeMB:
+ This is the size to allocate the DiskStore for a spool buffer. Writes are made
+ to this area and then asynchronously written to disk. The default size is 30MB.
+ Each spool buffer is used only by its cache. If you get OutOfMemory errors consider
+ lowering this value. To improve DiskStore performance consider increasing it. Trace level
+ logging in the DiskStore will show if put back ups are occurring.
+
+ clearOnFlush:
+ whether the MemoryStore should be cleared when flush() is called on the cache.
+ By default, this is true i.e. the MemoryStore is cleared.
+
+ memoryStoreEvictionPolicy:
+ Policy would be enforced upon reaching the maxEntriesLocalHeap limit. Default
+ policy is Least Recently Used (specified as LRU). Other policies available -
+ First In First Out (specified as FIFO) and Less Frequently Used
+ (specified as LFU)
+
+ copyOnRead:
+ Whether an Element is copied when being read from a cache.
+ By default this is false.
+
+ copyOnWrite:
+ Whether an Element is copied when being added to the cache.
+ By default this is false.
+
+ Cache persistence is configured through the persistence sub-element. The attributes of the
+ persistence element are:
+
+ strategy:
+ Configures the type of persistence provided by the configured cache. This must be one of the
+ following values:
+
+ * localRestartable - Enables the RestartStore and copies all cache entries (on-heap and/or off-heap)
+ to disk. This option provides fast restartability with fault tolerant cache persistence on disk.
+ It is available for Enterprise Ehcache users only.
+
+ * localTempSwap - Swaps cache entries (on-heap and/or off-heap) to disk when the cache is full.
+ "localTempSwap" is not persistent.
+
+ * none - Does not persist cache entries.
+
+ * distributed - Defers to the <terracotta> configuration for persistence settings. This option
+ is not applicable for standalone.
+
+ synchronousWrites:
+ When set to true write operations on the cache do not return until after the operations data has been
+ successfully flushed to the disk storage. This option is only valid when used with the "localRestartable"
+ strategy, and defaults to false.
+
+ The following example configuration shows a cache configured for localTempSwap restartability.
+
+ <cache name="persistentCache" maxEntriesLocalHeap="1000">
+ <persistence strategy="localTempSwap"/>
+ </cache>
+
+ Cache elements can also contain sub elements which take the same format of a factory class
+ and properties. Defined sub-elements are:
+
+ * cacheEventListenerFactory - Enables registration of listeners for cache events, such as
+ put, remove, update, and expire.
+
+ * bootstrapCacheLoaderFactory - Specifies a BootstrapCacheLoader, which is called by a
+ cache on initialisation to prepopulate itself.
+
+ * cacheExtensionFactory - Specifies a CacheExtension, a generic mechanism to tie a class
+ which holds a reference to a cache to the cache lifecycle.
+
+ * cacheExceptionHandlerFactory - Specifies a CacheExceptionHandler, which is called when
+ cache exceptions occur.
+
+ * cacheLoaderFactory - Specifies a CacheLoader, which can be used both asynchronously and
+ synchronously to load objects into a cache. More than one cacheLoaderFactory element
+ can be added, in which case the loaders form a chain which are executed in order. If a
+ loader returns null, the next in chain is called.
+
+ * copyStrategy - Specifies a fully qualified class which implements
+ net.sf.ehcache.store.compound.CopyStrategy. This strategy will be used for copyOnRead
+ and copyOnWrite in place of the default which is serialization.
+
+ Example of cache level resource tuning:
+ <cache name="memBound" maxBytesLocalHeap="100m" maxBytesLocalOffHeap="4g" maxBytesLocalDisk="200g" />
+
+
+ Cache Event Listeners
+ +++++++++++++++++++++
+
+ All cacheEventListenerFactory elements can take an optional property listenFor that describes
+ which events will be delivered in a clustered environment. The listenFor attribute has the
+ following allowed values:
+
+ * all - the default is to deliver all local and remote events
+ * local - deliver only events originating in the current node
+ * remote - deliver only events originating in other nodes
+
+ Example of setting up a logging listener for local cache events:
+
+ <cacheEventListenerFactory class="my.company.log.CacheLogger"
+ listenFor="local" />
+
+
+ Search
+ ++++++
+
+ A <cache> can be made searchable by adding a <searchable/> sub-element. By default the keys
+ and value objects of elements put into the cache will be attributes against which
+ queries can be expressed.
+
+ <cache>
+ <searchable/>
+ </cache>
+
+
+ An "attribute" of the cache elements can also be defined to be searchable. In the example below
+ an attribute with the name "age" will be available for use in queries. The value for the "age"
+ attribute will be computed by calling the method "getAge()" on the value object of each element
+ in the cache. See net.sf.ehcache.search.attribute.ReflectionAttributeExtractor for the format of
+ attribute expressions. Attribute values must also conform to the set of types documented in the
+ net.sf.ehcache.search.attribute.AttributeExtractor interface
+
+ <cache>
+ <searchable>
+ <searchAttribute name="age" expression="value.getAge()"/>
+ </searchable>
+ </cache>
+
+
+ Attributes may also be defined using a JavaBean style. With the following attribute declaration
+ a public method getAge() will be expected to be found on either the key or value for cache elements
+
+ <cache>
+ <searchable>
+ <searchAttribute name="age"/>
+ </searchable>
+ </cache>
+
+ In more complex situations you can create your own attribute extractor by implementing the
+ AttributeExtractor interface. Providing your extractor class is shown in the following example:
+
+ <cache>
+ <searchable>
+ <searchAttribute name="age" class="com.example.MyAttributeExtractor"/>
+ </searchable>
+ </cache>
+
+ Use properties to pass state to your attribute extractor if needed. Your implementation must provide
+ a public constructor that takes a single java.util.Properties instance
+
+ <cache>
+ <searchable>
+ <searchAttribute name="age" class="com.example.MyAttributeExtractor" properties="foo=1,bar=2"/>
+ </searchable>
+ </cache>
+
+
+ RMI Cache Replication
+ +++++++++++++++++++++
+
+ Each cache that will be distributed needs to set a cache event listener which replicates
+ messages to the other CacheManager peers. For the built-in RMI implementation this is done
+ by adding a cacheEventListenerFactory element of type RMICacheReplicatorFactory to each
+ distributed cache's configuration as per the following example:
+
+ <cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
+ properties="replicateAsynchronously=true,
+ replicatePuts=true,
+ replicatePutsViaCopy=false,
+ replicateUpdates=true,
+ replicateUpdatesViaCopy=true,
+ replicateRemovals=true,
+ asynchronousReplicationIntervalMillis=<number of milliseconds>,
+ asynchronousReplicationMaximumBatchSize=<number of operations>"
+ propertySeparator="," />
+
+ The RMICacheReplicatorFactory recognises the following properties:
+
+ * replicatePuts=true|false - whether new elements placed in a cache are
+ replicated to others. Defaults to true.
+
+ * replicatePutsViaCopy=true|false - whether the new elements are
+ copied to other caches (true), or whether a remove message is sent. Defaults to true.
+
+ * replicateUpdates=true|false - whether new elements which override an
+ element already existing with the same key are replicated. Defaults to true.
+
+ * replicateRemovals=true - whether element removals are replicated. Defaults to true.
+
+ * replicateAsynchronously=true | false - whether replications are
+ asynchronous (true) or synchronous (false). Defaults to true.
+
+ * replicateUpdatesViaCopy=true | false - whether the new elements are
+ copied to other caches (true), or whether a remove message is sent. Defaults to true.
+
+ * asynchronousReplicationIntervalMillis=<number of milliseconds> - The asynchronous
+ replicator runs at a set interval of milliseconds. The default is 1000. The minimum
+ is 10. This property is only applicable if replicateAsynchronously=true
+
+ * asynchronousReplicationMaximumBatchSize=<number of operations> - The maximum
+ number of operations that will be batch within a single RMI message. The default
+ is 1000. This property is only applicable if replicateAsynchronously=true
+
+ JGroups Replication
+ +++++++++++++++++++
+
+ For the Jgroups replication this is done with:
+ <cacheEventListenerFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"
+ properties="replicateAsynchronously=true, replicatePuts=true,
+ replicateUpdates=true, replicateUpdatesViaCopy=false,
+ replicateRemovals=true,asynchronousReplicationIntervalMillis=1000"/>
+ This listener supports the same properties as the RMICacheReplicationFactory.
+
+
+ JMS Replication
+ +++++++++++++++
+
+ For JMS-based replication this is done with:
+ <cacheEventListenerFactory
+ class="net.sf.ehcache.distribution.jms.JMSCacheReplicatorFactory"
+ properties="replicateAsynchronously=true,
+ replicatePuts=true,
+ replicateUpdates=true,
+ replicateUpdatesViaCopy=true,
+ replicateRemovals=true,
+ asynchronousReplicationIntervalMillis=1000"
+ propertySeparator=","/>
+
+ This listener supports the same properties as the RMICacheReplicationFactory.
+
+ Cluster Bootstrapping
+ +++++++++++++++++++++
+
+ Bootstrapping a cluster may use a different mechanism to replication. e.g you can mix
+ JMS replication with bootstrap via RMI - just make sure you have the cacheManagerPeerProviderFactory
+ and cacheManagerPeerListenerFactory configured.
+
+ There are two bootstrapping mechanisms: RMI and JGroups.
+
+ RMI Bootstrap
+
+ The RMIBootstrapCacheLoader bootstraps caches in clusters where RMICacheReplicators are
+ used. It is configured as per the following example:
+
+ <bootstrapCacheLoaderFactory
+ class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory"
+ properties="bootstrapAsynchronously=true, maximumChunkSizeBytes=5000000"
+ propertySeparator="," />
+
+ The RMIBootstrapCacheLoaderFactory recognises the following optional properties:
+
+ * bootstrapAsynchronously=true|false - whether the bootstrap happens in the background
+ after the cache has started. If false, bootstrapping must complete before the cache is
+ made available. The default value is true.
+
+ * maximumChunkSizeBytes=<integer> - Caches can potentially be very large, larger than the
+ memory limits of the VM. This property allows the bootstraper to fetched elements in
+ chunks. The default chunk size is 5000000 (5MB).
+
+ JGroups Bootstrap
+
+ Here is an example of bootstrap configuration using JGroups boostrap:
+
+ <bootstrapCacheLoaderFactory class="net.sf.ehcache.distribution.jgroups.JGroupsBootstrapCacheLoaderFactory"
+ properties="bootstrapAsynchronously=true"/>
+
+ The configuration properties are the same as for RMI above. Note that JGroups bootstrap only supports
+ asynchronous bootstrap mode.
+
+
+ Cache Exception Handling
+ ++++++++++++++++++++++++
+
+ By default, most cache operations will propagate a runtime CacheException on failure. An
+ interceptor, using a dynamic proxy, may be configured so that a CacheExceptionHandler can
+ be configured to intercept Exceptions. Errors are not intercepted.
+
+ It is configured as per the following example:
+
+ <cacheExceptionHandlerFactory class="com.example.ExampleExceptionHandlerFactory"
+ properties="logLevel=FINE"/>
+
+ Caches with ExceptionHandling configured are not of type Cache, but are of type Ehcache only,
+ and are not available using CacheManager.getCache(), but using CacheManager.getEhcache().
+
+
+ Cache Loader
+ ++++++++++++
+
+ A default CacheLoader may be set which loads objects into the cache through asynchronous and
+ synchronous methods on Cache. This is different to the bootstrap cache loader, which is used
+ only in distributed caching.
+
+ It is configured as per the following example:
+
+ <cacheLoaderFactory class="com.example.ExampleCacheLoaderFactory"
+ properties="type=int,startCounter=10"/>
+
+ Element value comparator
+ ++++++++++++++++++++++++
+
+ These two cache atomic methods:
+ removeElement(Element e)
+ replace(Element old, Element element)
+
+ rely on comparison of cached elements value. The default implementation relies on Object.equals()
+ but that can be changed in case you want to use a different way to compute equality of two elements.
+
+ This is configured as per the following example:
+
+ <elementValueComparator class="com.company.xyz.MyElementComparator"/>
+
+ The MyElementComparator class must implement the is net.sf.ehcache.store.ElementValueComparator
+ interface. The default implementation is net.sf.ehcache.store.DefaultElementValueComparator.
+
+
+ SizeOf Policy
+ +++++++++++++
+
+ Control how deep the SizeOf engine can go when sizing on-heap elements.
+
+ This is configured as per the following example:
+
+ <sizeOfPolicy maxDepth="100" maxDepthExceededBehavior="abort"/>
+
+ maxDepth controls how many linked objects can be visited before the SizeOf engine takes any action.
+ maxDepthExceededBehavior specifies what happens when the max depth is exceeded while sizing an object graph.
+ "continue" makes the SizeOf engine log a warning and continue the sizing. This is the default.
+ "abort" makes the SizeOf engine abort the sizing, log a warning and mark the cache as not correctly tracking
+ memory usage. This makes Ehcache.hasAbortedSizeOf() return true when this happens.
+
+ The SizeOf policy can be configured at the cache manager level (directly under <ehcache>) and at
+ the cache level (under <cache> or <defaultCache>). The cache policy always overrides the cache manager
+ one if both are set. This element has no effect on distributed caches.
+
+ Transactions
+ ++++++++++++
+
+ To enable an ehcache as transactions, set the transactionalMode
+
+ transactionalMode="xa" - high performance JTA/XA implementation
+ transactionalMode="xa_strict" - canonically correct JTA/XA implementation
+ transactionMode="local" - high performance local transactions involving caches only
+ transactionalMode="off" - the default, no transactions
+
+ If set, all cache operations will need to be done through transactions.
+
+ To prevent users keeping references on stored elements and modifying them outside of any transaction's control,
+ transactions also require the cache to be configured copyOnRead and copyOnWrite.
+
+ CacheWriter
+ ++++++++++++
+
+ A CacheWriter can be set to write to an underlying resource. Only one CacheWriter can be
+ configured per cache.
+
+ The following is an example of how to configure CacheWriter for write-through:
+
+ <cacheWriter writeMode="write-through" notifyListenersOnException="true">
+ <cacheWriterFactory class="net.sf.ehcache.writer.TestCacheWriterFactory"
+ properties="type=int,startCounter=10"/>
+ </cacheWriter>
+
+ The following is an example of how to configure CacheWriter for write-behind:
+
+ <cacheWriter writeMode="write-behind" minWriteDelay="1" maxWriteDelay="5"
+ rateLimitPerSecond="5" writeCoalescing="true" writeBatching="true" writeBatchSize="1"
+ retryAttempts="2" retryAttemptDelaySeconds="1">
+ <cacheWriterFactory class="net.sf.ehcache.writer.TestCacheWriterFactory"
+ properties="type=int,startCounter=10"/>
+ </cacheWriter>
+
+ The cacheWriter element has the following attributes:
+ * writeMode: the write mode, write-through or write-behind
+
+ These attributes only apply to write-through mode:
+ * notifyListenersOnException: Sets whether to notify listeners when an exception occurs on a writer operation.
+
+ These attributes only apply to write-behind mode:
+ * minWriteDelay: Set the minimum number of seconds to wait before writing behind. If set to a value greater than 0,
+ it permits operations to build up in the queue. This is different from the maximum write delay in that by waiting
+ a minimum amount of time, work is always being built up. If the minimum write delay is set to zero and the
+ CacheWriter performs its work very quickly, the overhead of processing the write behind queue items becomes very
+ noticeable in a cluster since all the operations might be done for individual items instead of for a collection
+ of them.
+ * maxWriteDelay: Set the maximum number of seconds to wait before writing behind. If set to a value greater than 0,
+ it permits operations to build up in the queue to enable effective coalescing and batching optimisations.
+ * writeBatching: Sets whether to batch write operations. If set to true, writeAll and deleteAll will be called on
+ the CacheWriter rather than write and delete being called for each key. Resources such as databases can perform
+ more efficiently if updates are batched, thus reducing load.
+ * writeBatchSize: Sets the number of operations to include in each batch when writeBatching is enabled. If there are
+ less entries in the write-behind queue than the batch size, the queue length size is used.
+ * rateLimitPerSecond: Sets the maximum number of write operations to allow per second when writeBatching is enabled.
+ * writeCoalescing: Sets whether to use write coalescing. If set to true and multiple operations on the same key are
+ present in the write-behind queue, only the latest write is done, as the others are redundant.
+ * retryAttempts: Sets the number of times the operation is retried in the CacheWriter, this happens after the
+ original operation.
+ * retryAttemptDelaySeconds: Sets the number of seconds to wait before retrying an failed operation.
+
+ Cache Extension
+ +++++++++++++++
+
+ CacheExtensions are a general purpose mechanism to allow generic extensions to a Cache.
+ CacheExtensions are tied into the Cache lifecycle.
+
+ CacheExtensions are created using the CacheExtensionFactory which has a
+ <code>createCacheCacheExtension()</code> method which takes as a parameter a
+ Cache and properties. It can thus call back into any public method on Cache, including, of
+ course, the load methods.
+
+ Extensions are added as per the following example:
+
+ <cacheExtensionFactory class="com.example.FileWatchingCacheRefresherExtensionFactory"
+ properties="refreshIntervalMillis=18000, loaderTimeout=3000,
+ flushPeriod=whatever, someOtherProperty=someValue ..."/>
+
+ Cache Decorator Factory
+ +++++++++++++++++++++++
+
+ Cache decorators can be configured directly in ehcache.xml. The decorators will be created and added to the CacheManager.
+ It accepts the name of a concrete class that extends net.sf.ehcache.constructs.CacheDecoratorFactory
+ The properties will be parsed according to the delimiter (default is comma ',') and passed to the concrete factory's
+ <code>createDecoratedEhcache(Ehcache cache, Properties properties)</code> method along with the reference to the owning cache.
+
+ It is configured as per the following example:
+
+ <cacheDecoratorFactory
+ class="com.company.DecoratedCacheFactory"
+ properties="property1=true ..." />
+
+ Distributed Caching with Terracotta
+ +++++++++++++++++++++++++++++++++++
+
+ Distributed Caches connect to a Terracotta Server Array. They are configured with the <terracotta> sub-element.
+
+ The <terracotta> sub-element has the following attributes:
+
+ * clustered=true|false - indicates whether this cache should be clustered (distributed) with Terracotta. By
+ default, if the <terracotta> element is included, clustered=true.
+
+ * copyOnRead=true|false - indicates whether cache values are deserialized on every read or if the
+ materialized cache value can be re-used between get() calls. This setting is useful if a cache
+ is being shared by callers with disparate classloaders or to prevent local drift if keys/values
+ are mutated locally without being put back in the cache.
+
+ The default is false.
+
+ * consistency=strong|eventual - Indicates whether this cache should have strong consistency or eventual
+ consistency. The default is eventual. See the documentation for the meaning of these terms.
+
+ * synchronousWrites=true|false
+
+ Synchronous writes (synchronousWrites="true") maximize data safety by blocking the client thread until
+ the write has been written to the Terracotta Server Array.
+
+ This option is only available with consistency=strong. The default is false.
+
+ * concurrency - the number of segments that will be used by the map underneath the Terracotta Store.
+ Its optional and has default value of 0, which means will use default values based on the internal
+ Map being used underneath the store.
+
+ This value cannot be changed programmatically once a cache is initialized.
+
+ The <terracotta> sub-element also has a <nonstop> sub-element to allow configuration of cache behaviour if a distributed
+ cache operation cannot be completed within a set time or in the event of a clusterOffline message. If this element does not appear, nonstop behavior is off.
+
+ <nonstop> has the following attributes:
+
+ * enabled="true" - defaults to true.
+
+ * timeoutMillis - An SLA setting, so that if a cache operation takes longer than the allowed ms, it will timeout.
+
+ * searchTimeoutMillis - If a cache search operation in the nonstop mode takes longer than the allowed ms, it will timeout.
+
+ * immediateTimeout="true|false" - What to do on receipt of a ClusterOffline event indicating that communications
+ with the Terracotta Server Array were interrupted.
+
+ <nonstop> has one sub-element, <timeoutBehavior> which has the following attribute:
+
+ * type="noop|exception|localReads|localReadsAndExceptionOnWrite" - What to do when a timeout has occurred. Exception is the default.
+
+ Simplest example to indicate clustering:
+ <terracotta/>
+
+ To indicate the cache should not be clustered (or remove the <terracotta> element altogether):
+ <terracotta clustered="false"/>
+
+ To indicate the cache should be clustered using "eventual" consistency mode for better performance :
+ <terracotta clustered="true" consistency="eventual"/>
+
+ To indicate the cache should be clustered using synchronous-write locking level:
+ <terracotta clustered="true" synchronousWrites="true"/>
+ -->
+
+ <!--
+ Mandatory Default Cache configuration. These settings will be applied to caches
+ created programmtically using CacheManager.add(String cacheName)
+ -->
+ <defaultCache
+ eternal="true"
+ overflowToDisk="false"
+ memoryStoreEvictionPolicy="LRU"
+ />
+
+ <!--
+ a cache from database ID to KiWiNode; should be very large since this kind of lookup is a very frequent operation
+ -->
+ <cache name="node-cache"
+ maxBytesLocalHeap="30%"
+ timeToLiveSeconds="3600"
+ overflowToDisk="false"
+ memoryStoreEvictionPolicy="LFU"/>
+
+ <!--
+ a cache from database ID to KiWiTriple; should be fairly large since it can speed up loading query results
+ from the database by avoiding reconstructing each triple from the database result
+ -->
+ <cache name="triple-cache"
+ maxBytesLocalHeap="10%"
+ overflowToDisk="false"
+ timeToLiveSeconds="3600"
+ memoryStoreEvictionPolicy="LFU"/>
+
+
+ <!-- a cache from URI to KiWiUriResource -->
+ <cache name="uri-cache"
+ maxBytesLocalHeap="10%"
+ overflowToDisk="false"
+ timeToLiveSeconds="3600"
+ memoryStoreEvictionPolicy="LRU"/>
+
+ <!-- a cache from anonymous ID to KiWiAnonResource -->
+ <cache name="bnode-cache"
+ maxBytesLocalHeap="5%"
+ overflowToDisk="false"
+ timeToLiveSeconds="3600"
+ memoryStoreEvictionPolicy="LRU"/>
+
+
+ <!-- a cache from literal cache key to KiWiLiteral -->
+ <cache name="literal-cache"
+ maxBytesLocalHeap="10%"
+ overflowToDisk="false"
+ timeToLiveSeconds="3600"
+ memoryStoreEvictionPolicy="LFU"/>
+
+
+ <cache name="namespace-prefix-cache"
+ maxBytesLocalHeap="5%"
+ eternal="true"
+ overflowToDisk="false"
+ memoryStoreEvictionPolicy="LFU"/>
+
+ <cache name="namespace-uri-cache"
+ maxBytesLocalHeap="5%"
+ eternal="true"
+ overflowToDisk="false"
+ memoryStoreEvictionPolicy="LFU"/>
+
+
+ <cache name="registry-cache"
+ maxEntriesLocalHeap="0"
+ eternal="true"/>
+
+
+ <!-- uncomment to enable cache debugging -->
+ <!--
+ <cacheManagerPeerListenerFactory
+ class="org.terracotta.ehcachedx.monitor.probe.ProbePeerListenerFactory"
+ properties="monitorAddress=localhost, monitorPort=9889" />
+ -->
+
+</ehcache>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2c5e8529/libraries/kiwi/kiwi-caching-ehcache/src/test/java/org/apache/marmotta/kiwi/test/caching/EHCacheRepositoryConnectionTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-ehcache/src/test/java/org/apache/marmotta/kiwi/test/caching/EHCacheRepositoryConnectionTest.java b/libraries/kiwi/kiwi-caching-ehcache/src/test/java/org/apache/marmotta/kiwi/test/caching/EHCacheRepositoryConnectionTest.java
new file mode 100644
index 0000000..80f54ad
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-ehcache/src/test/java/org/apache/marmotta/kiwi/test/caching/EHCacheRepositoryConnectionTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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.caching;
+
+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;
+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 EHCacheRepositoryConnectionTest extends RepositoryConnectionTest {
+
+ private final KiWiConfiguration config;
+
+ public EHCacheRepositoryConnectionTest(KiWiConfiguration config) {
+ this.config = config;
+ config.setClustered(false);
+ config.setCachingBackend(CachingBackends.EHCACHE);
+ }
+
+ /* (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/2c5e8529/libraries/kiwi/kiwi-caching-ehcache/src/test/java/org/apache/marmotta/kiwi/test/caching/EHCacheRepositoryTest.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-ehcache/src/test/java/org/apache/marmotta/kiwi/test/caching/EHCacheRepositoryTest.java b/libraries/kiwi/kiwi-caching-ehcache/src/test/java/org/apache/marmotta/kiwi/test/caching/EHCacheRepositoryTest.java
new file mode 100644
index 0000000..15df596
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-ehcache/src/test/java/org/apache/marmotta/kiwi/test/caching/EHCacheRepositoryTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.caching;
+
+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;
+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 EHCacheRepositoryTest extends RepositoryTest {
+
+ private final KiWiConfiguration config;
+
+ private KiWiStore store;
+
+ public EHCacheRepositoryTest(KiWiConfiguration config) {
+ this.config = config;
+ config.setClustered(false);
+ config.setCachingBackend(CachingBackends.EHCACHE);
+ }
+
+ /* (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/2c5e8529/libraries/kiwi/kiwi-caching-hazelcast/src/main/resources/META-INF/services/org.apache.marmotta.kiwi.caching.CacheManagerFactory
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-caching-hazelcast/src/main/resources/META-INF/services/org.apache.marmotta.kiwi.caching.CacheManagerFactory b/libraries/kiwi/kiwi-caching-hazelcast/src/main/resources/META-INF/services/org.apache.marmotta.kiwi.caching.CacheManagerFactory
new file mode 100644
index 0000000..dde7847
--- /dev/null
+++ b/libraries/kiwi/kiwi-caching-hazelcast/src/main/resources/META-INF/services/org.apache.marmotta.kiwi.caching.CacheManagerFactory
@@ -0,0 +1 @@
+org.apache.marmotta.kiwi.hazelcast.caching.HazelcastCacheManagerFactory
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2c5e8529/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
index 9698259..9e936d9 100644
--- 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
@@ -43,7 +43,13 @@ public enum CachingBackends {
/**
* Cache backend based on Hazelcast using a dynamic cluster setup
*/
- HAZELCAST("org.apache.marmotta.kiwi.hazelcast.caching.HazelcastCacheManagerFactory");
+ HAZELCAST("org.apache.marmotta.kiwi.hazelcast.caching.HazelcastCacheManagerFactory"),
+
+
+ /**
+ * Cache backend based in EHCache for single-machine production environments.
+ */
+ EHCACHE("org.apache.marmotta.kiwi.ehcache.caching.EHCacheManagerFactory");
CachingBackends(String factoryClass) {
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2c5e8529/libraries/kiwi/pom.xml
----------------------------------------------------------------------
diff --git a/libraries/kiwi/pom.xml b/libraries/kiwi/pom.xml
index 034464a..f86a467 100644
--- a/libraries/kiwi/pom.xml
+++ b/libraries/kiwi/pom.xml
@@ -113,6 +113,7 @@
<module>kiwi-triplestore</module>
<module>kiwi-caching-infinispan</module>
<module>kiwi-caching-hazelcast</module>
+ <module>kiwi-caching-ehcache</module>
<module>kiwi-versioning</module>
<module>kiwi-reasoner</module>
<module>kiwi-sparql</module>
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2c5e8529/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 58f7cd2..abb622c 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -1033,6 +1033,7 @@
<version>${project.version}</version>
</dependency>
+ <!-- Infinispan Caching Backend -->
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-core</artifactId>
@@ -1060,6 +1061,7 @@
</dependency>
+ <!-- Hazelcast Caching Backend -->
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
@@ -1067,6 +1069,13 @@
</dependency>
+ <!-- EHCache Caching Backend -->
+ <dependency>
+ <groupId>net.sf.ehcache</groupId>
+ <artifactId>ehcache</artifactId>
+ <version>2.8.1</version>
+ </dependency>
+
<!-- use stable versions for some dependencies -->
<dependency>
<groupId>org.jboss.spec.javax.annotation</groupId>
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2c5e8529/platform/marmotta-core/src/main/resources/META-INF/ehcache.xml
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/resources/META-INF/ehcache.xml b/platform/marmotta-core/src/main/resources/META-INF/ehcache.xml
deleted file mode 100644
index f51210a..0000000
--- a/platform/marmotta-core/src/main/resources/META-INF/ehcache.xml
+++ /dev/null
@@ -1,500 +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.
-
--->
-<!--
-CacheManager Configuration
-==========================
-An ehcache.xml corresponds to a single CacheManager.
-
-See instructions below or the ehcache schema (ehcache.xsd) on how to configure.
-
-System property tokens can be specified in this file which are replaced when the configuration
-is loaded. For example multicastGroupPort=${multicastGroupPort} can be replaced with the
-System property either from an environment variable or a system property specified with a
-command line switch such as -DmulticastGroupPort=4446.
-
-The attributes of <ehcache> are:
-* name - an optional name for the CacheManager. The name is optional and primarily used
-for documentation or to distinguish Terracotta clustered cache state. With Terracotta
-clustered caches, a combination of CacheManager name and cache name uniquely identify a
-particular cache store in the Terracotta clustered memory.
-* updateCheck - an optional boolean flag specifying whether this CacheManager should check
-for new versions of Ehcache over the Internet. If not specified, updateCheck="true".
-* monitoring - an optional setting that determines whether the CacheManager should
-automatically register the SampledCacheMBean with the system MBean server. Currently,
-this monitoring is only useful when using Terracotta and thus the "autodetect" value
-will detect the presence of Terracotta and register the MBean. Other allowed values
-are "on" and "off". The default is "autodetect".
--->
-<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd">
-
- <!--
- DiskStore configuration
- =======================
-
- The diskStore element is optional. To turn off disk store path creation, comment out the diskStore
- element below.
-
- Configure it if you have overflowToDisk or diskPersistent enabled for any cache.
-
- If it is not configured, and a cache is created which requires a disk store, a warning will be
- issued and java.io.tmpdir will automatically be used.
-
- diskStore has only one attribute - "path". It is the path to the directory where
- .data and .index files will be created.
-
- If the path is one of the following Java System Property it is replaced by its value in the
- running VM. For backward compatibility these are not specified without being enclosed in the ${token}
- replacement syntax.
-
- The following properties are translated:
- * user.home - KiWiUser's home directory
- * user.dir - KiWiUser's current working directory
- * java.io.tmpdir - Default temp file path
- * ehcache.disk.store.dir - A system property you would normally specify on the command line
- e.g. java -Dehcache.disk.store.dir=/u01/myapp/diskdir ...
-
- Subdirectories can be specified below the property e.g. java.io.tmpdir/one
-
- -->
- <diskStore path="java.io.tmpdir/marmotta-cache"/>
-
- <!--
- Cachemanagereventlistener
- =========================
- Specifies a CacheManagerEventListenerFactory which is notified when Caches are added
- or removed from the CacheManager.
-
- The attributes of CacheManagerEventListenerFactory are:
- * class - a fully qualified factory class name
- * properties - comma separated properties having meaning only to the factory.
-
- Sets the fully qualified class name to be registered as the CacheManager event listener.
-
- The events include:
- * adding a Cache
- * removing a Cache
-
- Callbacks to listener methods are synchronous and unsynchronized. It is the responsibility
- of the implementer to safely handle the potential performance and thread safety issues
- depending on what their listener is doing.
-
- If no class is specified, no listener is created. There is no default.
- -->
- <cacheManagerEventListenerFactory class="" properties=""/>
-
-
- <!--
- CacheManagerPeerProvider
- ========================
- (For distributed operation)
-
- Specifies a CacheManagerPeerProviderFactory which will be used to create a
- CacheManagerPeerProvider, which discovers other CacheManagers in the cluster.
-
- One or more providers can be configured. The first one in the ehcache.xml is the default, which is used
- for replication and bootstrapping.
-
- The attributes of cacheManagerPeerProviderFactory are:
- * class - a fully qualified factory class name
- * properties - comma separated properties having meaning only to the factory.
-
- Providers are available for RMI, JGroups and JMS as shown following.
-
- RMICacheManagerPeerProvider
- +++++++++++++++++++++++++++
-
- Ehcache comes with a built-in RMI-based distribution system with two means of discovery of
- CacheManager peers participating in the cluster:
- * automatic, using a multicast group. This one automatically discovers peers and detects
- changes such as peers entering and leaving the group
- * manual, using manual rmiURL configuration. A hardcoded list of peers is provided at
- configuration time.
-
- Configuring Automatic Discovery:
- Automatic discovery is configured as per the following example:
- <cacheManagerPeerProviderFactory
- class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
- properties="hostName=fully_qualified_hostname_or_ip,
- peerDiscovery=automatic, multicastGroupAddress=230.0.0.1,
- multicastGroupPort=4446, timeToLive=32"/>
-
- Valid properties are:
- * peerDiscovery (mandatory) - specify "automatic"
- * multicastGroupAddress (mandatory) - specify a valid multicast group address
- * multicastGroupPort (mandatory) - specify a dedicated port for the multicast heartbeat
- traffic
- * timeToLive - specify a value between 0 and 255 which determines how far the packets will
- propagate.
-
- By convention, the restrictions are:
- 0 - the same host
- 1 - the same subnet
- 32 - the same site
- 64 - the same region
- 128 - the same continent
- 255 - unrestricted
-
- * hostName - the hostname or IP of the interface to be used for sending and receiving multicast packets
- (relevant to mulithomed hosts only)
-
- Configuring Manual Discovery:
- Manual discovery requires a unique configuration per host. It is contains a list of rmiURLs for the peers, other
- than itself. So, if we have server1, server2 and server3 the configuration will be:
-
- In server1's configuration:
- <cacheManagerPeerProviderFactory class=
- "net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
- properties="peerDiscovery=manual,
- rmiUrls=//server2:40000/sampleCache1|//server3:40000/sampleCache1
- | //server2:40000/sampleCache2|//server3:40000/sampleCache2"
- propertySeparator="," />
-
- In server2's configuration:
- <cacheManagerPeerProviderFactory class=
- "net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
- properties="peerDiscovery=manual,
- rmiUrls=//server1:40000/sampleCache1|//server3:40000/sampleCache1
- | //server1:40000/sampleCache2|//server3:40000/sampleCache2"
- propertySeparator="," />
-
- In server3's configuration:
- <cacheManagerPeerProviderFactory class=
- "net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
- properties="peerDiscovery=manual,
- rmiUrls=//server1:40000/sampleCache1|//server2:40000/sampleCache1
- | //server1:40000/sampleCache2|//server2:40000/sampleCache2"
- propertySeparator="," />
-
-
- Valid properties are:
- * peerDiscovery (mandatory) - specify "manual"
- * rmiUrls (mandatory) - specify a pipe separated list of rmiUrls, in the form
- //hostname:port
- * hostname (optional) - the hostname is the hostname of the remote CacheManager peer. The port is the listening
- port of the RMICacheManagerPeerListener of the remote CacheManager peer.
-
- JGroupsCacheManagerPeerProvider
- +++++++++++++++++++++++++++++++
- <cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheManagerPeerProviderFactory"
- properties="connect=UDP(mcast_addr=231.12.21.132;mcast_port=45566;ip_ttl=32;
- mcast_send_buf_size=150000;mcast_recv_buf_size=80000):
- PING(timeout=2000;num_initial_members=6):
- MERGE2(min_interval=5000;max_interval=10000):
- FD_SOCK:VERIFY_SUSPECT(timeout=1500):
- pbcast.NAKACK(gc_lag=10;retransmit_timeout=3000):
- UNICAST(timeout=5000):
- pbcast.STABLE(desired_avg_gossip=20000):
- FRAG:
- pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;shun=false;print_local_addr=false)"
- propertySeparator="::"
- />
- The only property necessary is the connect String used by jgroups to configure itself. Refer to the Jgroups documentation for explanation
- of all the protocols. The example above uses UDP multicast. If the connect property is not specified the default JGroups connection will be
- used.
-
-
- JMSCacheManagerPeerProviderFactory
- ++++++++++++++++++++++++++++++++++
- <cacheManagerPeerProviderFactory
- class="net.sf.ehcache.distribution.jms.JMSCacheManagerPeerProviderFactory"
- properties="..."
- propertySeparator=","
- />
-
- The JMS PeerProviderFactory uses JNDI to maintain message queue independence. Refer to the manual for full configuration
- examples using ActiveMQ and Open Message Queue.
-
- Valid properties are:
- * initialContextFactoryName (mandatory) - the name of the factory used to create the message queue initial context.
- * providerURL (mandatory) - the JNDI configuration information for the service provider to use.
- * topicConnectionFactoryBindingName (mandatory) - the JNDI binding name for the TopicConnectionFactory
- * topicBindingName (mandatory) - the JNDI binding name for the topic name
- * getQueueBindingName (mandatory only if using jmsCacheLoader) - the JNDI binding name for the queue name
- * securityPrincipalName - the JNDI java.naming.security.principal
- * securityCredentials - the JNDI java.naming.security.credentials
- * urlPkgPrefixes - the JNDI java.naming.factory.url.pkgs
- * userName - the user name to use when creating the TopicConnection to the Message Queue
- * password - the password to use when creating the TopicConnection to the Message Queue
- * acknowledgementMode - the JMS Acknowledgement mode for both publisher and subscriber. The available choices are
- AUTO_ACKNOWLEDGE, DUPS_OK_ACKNOWLEDGE and SESSION_TRANSACTED. The default is AUTO_ACKNOWLEDGE.
- -->
-<!-- <cacheManagerPeerProviderFactory-->
-<!-- class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"-->
-<!-- properties="peerDiscovery=automatic,-->
-<!-- multicastGroupAddress=230.0.0.1,-->
-<!-- multicastGroupPort=4446, timeToLive=1"-->
-<!-- propertySeparator=","-->
-<!-- />-->
-
-
- <!--
- CacheManagerPeerListener
- ========================
- (Enable for distributed operation)
-
- Specifies a CacheManagerPeerListenerFactory which will be used to create a
- CacheManagerPeerListener, which listens for messages from cache replicators participating in the cluster.
-
- The attributes of cacheManagerPeerListenerFactory are:
- class - a fully qualified factory class name
- properties - comma separated properties having meaning only to the factory.
-
- Ehcache comes with a built-in RMI-based distribution system. The listener component is
- RMICacheManagerPeerListener which is configured using
- RMICacheManagerPeerListenerFactory. It is configured as per the following example:
-
- <cacheManagerPeerListenerFactory
- class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
- properties="hostName=fully_qualified_hostname_or_ip,
- port=40001,
- remoteObjectPort=40002,
- socketTimeoutMillis=120000"
- propertySeparator="," />
-
- All properties are optional. They are:
- * hostName - the hostName of the host the listener is running on. Specify
- where the host is multihomed and you want to control the interface over which cluster
- messages are received. Defaults to the host name of the default interface if not
- specified.
- * port - the port the RMI Registry listener listens on. This defaults to a free port if not specified.
- * remoteObjectPort - the port number on which the remote objects bound in the registry receive calls.
- This defaults to a free port if not specified.
- * socketTimeoutMillis - the number of ms client sockets will stay open when sending
- messages to the listener. This should be long enough for the slowest message.
- If not specified it defaults to 120000ms.
-
- -->
-<!-- <cacheManagerPeerListenerFactory-->
-<!-- class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"/>-->
-
- <!-- Cache configuration.
-
- The following attributes are required.
-
- name:
- Sets the name of the cache. This is used to identify the cache. It must be unique.
-
- maxElementsInMemory:
- Sets the maximum number of objects that will be created in memory
-
- maxElementsOnDisk:
- Sets the maximum number of objects that will be maintained in the DiskStore
- The default value is zero, meaning unlimited.
-
- eternal:
- Sets whether elements are eternal. If eternal, timeouts are ignored and the
- element is never expired.
-
- overflowToDisk:
- Sets whether elements can overflow to disk when the memory store
- has reached the maxInMemory limit.
-
- The following attributes are optional.
-
- timeToIdleSeconds:
- Sets the time to idle for an element before it expires.
- i.e. The maximum amount of time between accesses before an element expires
- Is only used if the element is not eternal.
- Optional attribute. A value of 0 means that an Element can idle for infinity.
- The default value is 0.
-
- timeToLiveSeconds:
- Sets the time to live for an element before it expires.
- i.e. The maximum time between creation time and when an element expires.
- Is only used if the element is not eternal.
- Optional attribute. A value of 0 means that and Element can live for infinity.
- The default value is 0.
-
- diskPersistent:
- Whether the disk store persists between restarts of the Virtual Machine.
- The default value is false.
-
- diskExpiryThreadIntervalSeconds:
- The number of seconds between runs of the disk expiry thread. The default value
- is 120 seconds.
-
- memoryStoreEvictionPolicy:
- Policy would be enforced upon reaching the maxElementsInMemory limit. Default
- policy is Least Recently Used (specified as LRU). Other policies available -
- First In First Out (specified as FIFO) and Less Frequently Used
- (specified as LFU)
-
- -->
-
- <!--
- Mandatory Default Cache configuration. These settings will be applied to caches
- created programmtically using CacheManager.add(String cacheName)
- -->
- <defaultCache
- maxElementsInMemory="20000"
- eternal="true"
- overflowToDisk="false"
- memoryStoreEvictionPolicy="LRU"
- />
-
- <cache name="org.apache.marmotta.platform.core.model.rdf.KiWiNode"
- statistics="true"
- maxElementsInMemory="10000"
- eternal="true"
- overflowToDisk="false"
- memoryStoreEvictionPolicy="LRU"/>
-
- <cache name="org.apache.marmotta.platform.versioning.model.Version"
- statistics="true"
- maxElementsInMemory="10000"
- eternal="true"
- overflowToDisk="false"
- memoryStoreEvictionPolicy="LRU"/>
-
-
- <cache name="org.apache.marmotta.platform.core.model.rdf.KiWiNamespace"
- statistics="true"
- maxElementsInMemory="100"
- eternal="true"
- overflowToDisk="false"
- memoryStoreEvictionPolicy="LRU"/>
-
- <cache name="org.apache.marmotta.platform.core.model.user.KiWiGroup"
- statistics="true"
- maxElementsInMemory="100"
- eternal="true"
- overflowToDisk="false"
- memoryStoreEvictionPolicy="LRU"/>
-
- <cache name="org.apache.marmotta.platform.core.model.user.MarmottaUser"
- statistics="true"
- maxElementsInMemory="100"
- eternal="true"
- overflowToDisk="false"
- memoryStoreEvictionPolicy="LRU"/>
-
-
- <cache name="org.apache.marmotta.platform.core.model.rdf.KiWiTriple"
- statistics="true"
- maxElementsInMemory="100000"
- eternal="true"
- overflowToDisk="false"
- memoryStoreEvictionPolicy="LRU"/>
-
- <cache name="org.apache.marmotta.platform.reasoner.model.Pattern"
- statistics="true"
- maxElementsInMemory="1000"
- eternal="true"
- overflowToDisk="false"
- memoryStoreEvictionPolicy="LRU"/>
-
- <cache name="org.apache.marmotta.platform.reasoner.model.Field"
- statistics="true"
- maxElementsInMemory="10000"
- eternal="true"
- overflowToDisk="false"
- memoryStoreEvictionPolicy="LRU"/>
-
- <!--
- <cache name="org.hibernate.cache.StandardQueryCache"
- statistics="true"
- maxElementsInMemory="10000"
- eternal="true"
- overflowToDisk="false"
- memoryStoreEvictionPolicy="LRU"/>
-
- <cache name="org.hibernate.cache.UpdateTimestampsCache"
- statistics="true"
- maxElementsInMemory="10000"
- eternal="true"
- overflowToDisk="false"/>
- -->
-
- <!-- the cache used for triple queries by KiWi -->
- <!-- the cache used for triple queries by KiWi -->
- <cache name="uri-node-cache"
- statistics="true"
- maxElementsInMemory="100000"
- timeToIdleSeconds="3600"
- overflowToDisk="false"/>
- <cache name="anon-node-cache"
- statistics="true"
- maxElementsInMemory="10000"
- timeToIdleSeconds="3600"
- overflowToDisk="false"/>
- <cache name="literal-cache"
- statistics="true"
- maxElementsInMemory="10000"
- timeToIdleSeconds="3600"
- overflowToDisk="false"/>
-
- <cache name="triple-cache"
- statistics="true"
- maxElementsInMemory="100000"
- memoryStoreEvictionPolicy="LRU"
- overflowToDisk="false"/>
-
- <cache name="namespace-prefix-cache"
- statistics="true"
- maxElementsInMemory="100"
- overflowToDisk="true"/>
-
- <cache name="namespace-uri-cache"
- statistics="true"
- maxElementsInMemory="100"
- overflowToDisk="true"/>
-
- <!-- the cache used for triple queries by KiWi -->
- <cache name="query-cache"
- statistics="true"
- maxElementsInMemory="10000"
- timeToIdleSeconds="3600"
- overflowToDisk="false"/>
-
- <!-- the cache used for resource lookups from module jar files -->
- <cache name="resource-cache"
- statistics="true"
- maxElementsInMemory="10000"
- timeToIdleSeconds="3600"
- timeToLiveSeconds="3600"
- overflowToDisk="false"
- memoryStoreEvictionPolicy="LRU"/>
-
- <!-- the cache used for triple queries by KiWi -->
- <cache name="page-cache"
- statistics="true"
- maxElementsInMemory="500"
- timeToIdleSeconds="3600"
- memoryStoreEvictionPolicy="LRU"
- overflowToDisk="true"/>
-
- <!-- the cache used by the file system importer module -->
- <cache name="fsimport-file-cache"
- statistics="true"
- maxElementsInMemory="500"
- timeToIdleSeconds="3600"
- memoryStoreEvictionPolicy="LRU"
- diskPersistent="true"
- eternal="true"/>
-
-<!-- uncomment to enable cache debugging -->
-<!--
- <cacheManagerPeerListenerFactory
- class="org.terracotta.ehcachedx.monitor.probe.ProbePeerListenerFactory"
- properties="monitorAddress=localhost, monitorPort=9889" />
--->
-
-</ehcache>
[14/32] 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/develop
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);
+ }
+}
[20/32] 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/develop
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();
[28/32] git commit: upgrade JBoss Marshalling to 1.4.5,
which is Apache License (fixes MARMOTTA-412)
Posted by ss...@apache.org.
upgrade JBoss Marshalling to 1.4.5, which is Apache License (fixes MARMOTTA-412)
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/18db9451
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/18db9451
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/18db9451
Branch: refs/heads/develop
Commit: 18db94512d672324c62f91363d8650adfd0022c3
Parents: cebdd64
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Mon Mar 17 10:03:32 2014 +0100
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Mon Mar 17 10:03:32 2014 +0100
----------------------------------------------------------------------
parent/pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/18db9451/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 8abc2b2..58f7cd2 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -1091,12 +1091,12 @@
<dependency>
<groupId>org.jboss.marshalling</groupId>
<artifactId>jboss-marshalling</artifactId>
- <version>1.4.3.Final</version>
+ <version>1.4.5.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.marshalling</groupId>
<artifactId>jboss-marshalling-river</artifactId>
- <version>1.4.3.Final</version>
+ <version>1.4.5.Final</version>
</dependency>
<!--
<dependency>
[07/32] 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/develop
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();
- }
-
-}
[16/32] 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/develop
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>
[06/32] 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/develop
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>
[04/32] 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
[05/32] 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/develop
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;
- }
-}
[26/32] git commit: Merge branch 'master' into MARMOTTA-450
Posted by ss...@apache.org.
Merge branch 'master' into MARMOTTA-450
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/b07ed138
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/b07ed138
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/b07ed138
Branch: refs/heads/develop
Commit: b07ed13830c003ae05dbe2abf9ef85cc8e0c6101
Parents: 61ba807 a9bf7e4
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Mon Mar 17 09:50:35 2014 +0100
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Mon Mar 17 09:50:35 2014 +0100
----------------------------------------------------------------------
----------------------------------------------------------------------
[25/32] git commit: working webapp launcher for different cluster
backends
Posted by ss...@apache.org.
working webapp launcher for different cluster backends
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/61ba807a
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/61ba807a
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/61ba807a
Branch: refs/heads/develop
Commit: 61ba807ad17ea99bfbc1e23ad00b3ab982c87ece
Parents: 7c40b53
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Wed Mar 5 15:16:03 2014 +0100
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Wed Mar 5 15:16:03 2014 +0100
----------------------------------------------------------------------
launchers/marmotta-webapp/pom.xml | 38 ++++++++++++++++++++
.../backend/kiwi/KiWiStoreProvider.java | 6 +++-
.../resources/config-descriptions.properties | 18 +++++-----
3 files changed, 52 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/61ba807a/launchers/marmotta-webapp/pom.xml
----------------------------------------------------------------------
diff --git a/launchers/marmotta-webapp/pom.xml b/launchers/marmotta-webapp/pom.xml
index bf7bf27..ae061e2 100644
--- a/launchers/marmotta-webapp/pom.xml
+++ b/launchers/marmotta-webapp/pom.xml
@@ -345,6 +345,44 @@
</dependencies>
</profile>
+
+ <!-- Caching Backends for KiWi -->
+
+ <profile>
+ <id>infinispan</id>
+ <activation>
+ <property>
+ <name>marmotta.caching</name>
+ <value>infinispan</value>
+ </property>
+ </activation>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.marmotta</groupId>
+ <artifactId>kiwi-caching-infinispan</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+ </profile>
+
+ <profile>
+ <id>hazelcast</id>
+ <activation>
+ <property>
+ <name>marmotta.caching</name>
+ <value>hazelcast</value>
+ </property>
+ </activation>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.marmotta</groupId>
+ <artifactId>kiwi-caching-hazelcast</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+ </profile>
+
+
<profile>
<id>cleanall</id>
<build>
http://git-wip-us.apache.org/repos/asf/marmotta/blob/61ba807a/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 2091b0e..346d4cc 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
@@ -180,7 +180,11 @@ public class KiWiStoreProvider implements StoreProvider {
e.containsChangedKey(KiWiOptions.CACHING_TRIPLE_SIZE) ||
e.containsChangedKey(KiWiOptions.CACHING_URI_SIZE) ||
e.containsChangedKey(KiWiOptions.CACHING_BNODE_SIZE) ||
- e.containsChangedKey(KiWiOptions.CACHING_QUERY_ENABLED)
+ e.containsChangedKey(KiWiOptions.CACHING_QUERY_ENABLED) ||
+ e.containsChangedKey(KiWiOptions.CLUSTERING_BACKEND) ||
+ e.containsChangedKey(KiWiOptions.CLUSTERING_ADDRESS) ||
+ e.containsChangedKey(KiWiOptions.CLUSTERING_PORT) ||
+ e.containsChangedKey(KiWiOptions.CLUSTERING_MODE)
) {
log.info("KiWi backend configuration changed, re-initialising triple store");
http://git-wip-us.apache.org/repos/asf/marmotta/blob/61ba807a/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 3cb207b..2bcc248 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,21 +64,21 @@ 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|*)
-clustering.enabled.description = Turn on cluster-specific configuration options (e.g. replicated and distributed caching, synchronization, ...)
+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 \
+ 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, \
+ 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.
+ 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
@@ -87,6 +87,6 @@ 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")
+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")
[15/32] 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/develop
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
*
[13/32] - 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;
[31/32] git commit: - add EHCache backend as profile to webapp
launcher
Posted by ss...@apache.org.
- add EHCache backend as profile to webapp launcher
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/d04e10b8
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/d04e10b8
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/d04e10b8
Branch: refs/heads/develop
Commit: d04e10b85f3ae9f946025089adc3c2c0beb1bbc6
Parents: 2c5e852
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Mon Mar 17 11:18:13 2014 +0100
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Mon Mar 17 11:18:13 2014 +0100
----------------------------------------------------------------------
launchers/marmotta-webapp/pom.xml | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d04e10b8/launchers/marmotta-webapp/pom.xml
----------------------------------------------------------------------
diff --git a/launchers/marmotta-webapp/pom.xml b/launchers/marmotta-webapp/pom.xml
index 36c45df..1364170 100644
--- a/launchers/marmotta-webapp/pom.xml
+++ b/launchers/marmotta-webapp/pom.xml
@@ -381,6 +381,23 @@
</dependencies>
</profile>
+ <profile>
+ <id>ehcache</id>
+ <activation>
+ <property>
+ <name>marmotta.caching</name>
+ <value>ehcache</value>
+ </property>
+ </activation>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.marmotta</groupId>
+ <artifactId>kiwi-caching-ehcache</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+ </profile>
+
<profile>
<id>cleanall</id>