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/01/10 18:09:22 UTC
[4/4] git commit: MARMOTTA-418: removed old LDCache API
MARMOTTA-418: removed old LDCache API
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/8941574c
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/8941574c
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/8941574c
Branch: refs/heads/develop
Commit: 8941574ce76f806b0f20ad805ab9766ca7dc13ad
Parents: aa84345
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Fri Jan 10 18:09:01 2014 +0100
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Fri Jan 10 18:09:01 2014 +0100
----------------------------------------------------------------------
.../marmotta/ldcache/api/LDCachingBackend.java | 64 ++-
.../ldcache/api/LDCachingBackendNG.java | 75 ----
.../marmotta/ldcache/api/LDCachingService.java | 101 ++---
.../ldcache/api/LDCachingServiceNG.java | 92 ----
.../marmotta/ldcache/sail/LDCachingSail.java | 34 --
.../ldcache/sail/LDCachingSailConnection.java | 57 ---
.../backend/file/LDCachingFileBackend.java | 185 +++++---
.../backend/file/LDCachingFileBackendNG.java | 227 ----------
.../LDCachingFileRepositoryConnection.java | 70 ---
.../backend/file/test/LDCacheBackendTest.java | 226 ----------
.../backend/file/test/LDCacheFileNGTest.java | 74 ----
.../backend/file/test/LDCacheFileTest.java | 74 ++++
.../infinispan/LDCachingInfinispanBackend.java | 89 ++--
.../LDCachingInfinispanBackendNG.java | 222 ----------
...LDCachingInfinispanRepositoryConnection.java | 130 ------
.../test/LDCacheInfinispanNGTest.java | 43 --
.../infinispan/test/LDCacheInfinispanTest.java | 124 +-----
.../backend/kiwi/LDCachingKiWiBackend.java | 307 ++++++++------
.../backend/kiwi/LDCachingKiWiBackendNG.java | 305 -------------
.../LDCachingSailRepositoryConnection.java | 91 ----
.../backend/kiwi/sail/LDCachingKiWiSail.java | 60 ---
.../kiwi/sail/LDCachingKiWiSailConnection.java | 134 ------
.../backend/kiwi/test/LDCacheBackendTest.java | 315 --------------
.../services/test/LDCacheKiWiNGTest.java | 168 --------
.../ldcache/services/test/LDCacheKiWiTest.java | 221 ++--------
.../marmotta/ldcache/services/LDCache.java | 425 ++++---------------
.../marmotta/ldcache/services/LDCacheNG.java | 230 ----------
.../services/test/ng/BaseLDCacheNGTest.java | 168 --------
.../services/test/ng/BaseLDCacheTest.java | 168 ++++++++
.../ldcache/sail/GenericLinkedDataSail.java | 26 +-
.../sail/GenericLinkedDataSailConnection.java | 8 +-
.../test/GenericLinkedDataSailOfflineTest.java | 6 +-
.../ldcache/sail/KiWiLinkedDataSail.java | 16 +-
.../sail/KiWiLinkedDataSailConnection.java | 6 +-
.../backend/linkeddata/LDPersistentBackend.java | 6 +-
.../api/ldcache/LDCacheSailProvider.java | 4 +-
.../services/kiwi/FileLDCacheSailProvider.java | 10 +-
.../services/kiwi/KiWiLDCacheSailProvider.java | 4 +-
38 files changed, 847 insertions(+), 3718 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/8941574c/libraries/ldcache/ldcache-api/src/main/java/org/apache/marmotta/ldcache/api/LDCachingBackend.java
----------------------------------------------------------------------
diff --git a/libraries/ldcache/ldcache-api/src/main/java/org/apache/marmotta/ldcache/api/LDCachingBackend.java b/libraries/ldcache/ldcache-api/src/main/java/org/apache/marmotta/ldcache/api/LDCachingBackend.java
index a121e20..34a2028 100644
--- a/libraries/ldcache/ldcache-api/src/main/java/org/apache/marmotta/ldcache/api/LDCachingBackend.java
+++ b/libraries/ldcache/ldcache-api/src/main/java/org/apache/marmotta/ldcache/api/LDCachingBackend.java
@@ -1,13 +1,12 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -15,57 +14,53 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.marmotta.ldcache.api;
-import info.aduna.iteration.CloseableIteration;
import org.apache.marmotta.ldcache.model.CacheEntry;
-import org.openrdf.repository.RepositoryException;
+import org.openrdf.model.URI;
/**
- * This interface defines the API for different backends for storing the caching results.
- * <p/>
- * Author: Sebastian Schaffert (sschaffert@apache.org)
+ * Next generation caching backend API. Needs to be implemented by backend providers to offer caching support.
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
*/
public interface LDCachingBackend {
+
/**
- * Return a repository connection that can be used for caching. The LDCache will first remove all statements for
- * the newly cached resources and then add retrieved statements as-is to this connection and properly commit and
- * close it after use.
- * <p/>
- * Note that in case the statements should be rewritten this method must take care of providing the proper
- * connection, e.g. by using a ContextAwareRepositoryConnection to add a context to all statements when adding them.
+ * Return the cache entry for the given resource, or null if this entry does not exist.
*
*
- * @param resource the resource that will be cached
- * @return a repository connection that can be used for storing retrieved triples for caching
+ * @param resource the resource to retrieve the cache entry for
+ * @return
*/
- public LDCachingConnection getCacheConnection(String resource) throws RepositoryException;
+ public CacheEntry getEntry(URI resource);
/**
- * Return an iterator over all expired cache entries (can e.g. be used for refreshing).
+ * Update the cache entry for the given resource with the given entry.
*
- * @return
+ * @param resource the resource to update
+ * @param entry the entry for the resource
*/
- public CloseableIteration<CacheEntry,RepositoryException> listExpiredEntries() throws RepositoryException;
+ public void putEntry(URI resource, CacheEntry entry);
/**
- * Return an iterator over all cache entries (can e.g. be used for refreshing or expiring).
+ * Remove the cache entry for the given resource if it exists. Does nothing otherwise.
*
- * @return
+ * @param resource the resource to remove the entry for
*/
- public CloseableIteration<CacheEntry,RepositoryException> listCacheEntries() throws RepositoryException;
+ public void removeEntry(URI resource);
/**
- * Return true in case the resource is a cached resource.
- *
- * @param resource the URI of the resource to check
- * @return true in case the resource is a cached resource
+ * Clear all entries in the cache backend.
*/
- public boolean isCached(String resource) throws RepositoryException;
+ public void clear();
+
+
/**
* Carry out any initialization tasks that might be necessary
@@ -76,4 +71,5 @@ public interface LDCachingBackend {
* Shutdown the backend and free all runtime resources.
*/
public void shutdown();
+
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/8941574c/libraries/ldcache/ldcache-api/src/main/java/org/apache/marmotta/ldcache/api/LDCachingBackendNG.java
----------------------------------------------------------------------
diff --git a/libraries/ldcache/ldcache-api/src/main/java/org/apache/marmotta/ldcache/api/LDCachingBackendNG.java b/libraries/ldcache/ldcache-api/src/main/java/org/apache/marmotta/ldcache/api/LDCachingBackendNG.java
deleted file mode 100644
index 1f0e6b9..0000000
--- a/libraries/ldcache/ldcache-api/src/main/java/org/apache/marmotta/ldcache/api/LDCachingBackendNG.java
+++ /dev/null
@@ -1,75 +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.ldcache.api;
-
-import org.apache.marmotta.ldcache.model.CacheEntry;
-import org.openrdf.model.URI;
-
-/**
- * Next generation caching backend API. Needs to be implemented by backend providers to offer caching support.
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public interface LDCachingBackendNG {
-
-
- /**
- * Return the cache entry for the given resource, or null if this entry does not exist.
- *
- *
- * @param resource the resource to retrieve the cache entry for
- * @return
- */
- public CacheEntry getEntry(URI resource);
-
-
- /**
- * Update the cache entry for the given resource with the given entry.
- *
- * @param resource the resource to update
- * @param entry the entry for the resource
- */
- public void putEntry(URI resource, CacheEntry entry);
-
-
- /**
- * Remove the cache entry for the given resource if it exists. Does nothing otherwise.
- *
- * @param resource the resource to remove the entry for
- */
- public void removeEntry(URI resource);
-
-
- /**
- * Clear all entries in the cache backend.
- */
- public void clear();
-
-
-
- /**
- * Carry out any initialization tasks that might be necessary
- */
- public void initialize();
-
- /**
- * Shutdown the backend and free all runtime resources.
- */
- public void shutdown();
-
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/8941574c/libraries/ldcache/ldcache-api/src/main/java/org/apache/marmotta/ldcache/api/LDCachingService.java
----------------------------------------------------------------------
diff --git a/libraries/ldcache/ldcache-api/src/main/java/org/apache/marmotta/ldcache/api/LDCachingService.java b/libraries/ldcache/ldcache-api/src/main/java/org/apache/marmotta/ldcache/api/LDCachingService.java
index bd385ca..82c2df7 100644
--- a/libraries/ldcache/ldcache-api/src/main/java/org/apache/marmotta/ldcache/api/LDCachingService.java
+++ b/libraries/ldcache/ldcache-api/src/main/java/org/apache/marmotta/ldcache/api/LDCachingService.java
@@ -1,13 +1,12 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -17,13 +16,12 @@
*/
package org.apache.marmotta.ldcache.api;
-import info.aduna.iteration.CloseableIteration;
-import org.apache.marmotta.ldcache.model.CacheEntry;
+import org.openrdf.model.Model;
import org.openrdf.model.URI;
-import org.openrdf.repository.RepositoryException;
/**
- * Add file description here!
+ * This is the next-generation API for LDCache that will become the default in Marmotta 3.3 or 4.0. For now,
+ * LDCache implements both the old and the new style.
* <p/>
* User: sschaffe
*/
@@ -31,47 +29,50 @@ public interface LDCachingService {
/**
- * Refresh the cached resource passed as argument. The method will do nothing for local
- * resources.
- * Calling the method will carry out the following tasks:
- * 1. check whether the resource is a remote resource; if no, returns immediately
- * 2. check whether the resource has a cache entry; if no, goto 4
- * 3. check whether the expiry time of the cache entry has passed; if no, returns immediately
- * 4. retrieve the triples for the resource from the Linked Data Cloud using the methods offered
- * by the
- * LinkedDataClientService (registered endpoints etc); returns immediately if the result is null
- * or
- * an exception is thrown
- * 5. remove all old triples for the resource and add all new triples for the resource
- * 6. create new expiry information of the cache entry and persist it in the transaction
+ * Refresh the resource passed as argument. If the resource is not yet cached or the cache entry is
+ * expired or refreshing is forced, the remote resource is retrieved using LDClient and the result stored
+ * in the cache. Otherwise the method does nothing.
*
*
- * @param resource
- * @param forceRefresh if <code>true</code> the resource will be refreshed despite the
+ * @param resource the resource to refresh
+ * @param options options for refreshing
*/
- public void refreshResource(URI resource, boolean forceRefresh);
+ public void refresh(URI resource, RefreshOpts... options);
+
/**
- * Refresh all expired resources by listing the cache entries that have expired and calling refreshResource on
- * them. This method can e.g. be called by a scheduled task to regularly update cache entries to always have
- * the latest version available in the Search Index and elsewhere.
+ * Refresh and return the resource passed as argument. If the resource is not yet cached or the cache entry is
+ * expired or refreshing is forced, the remote resource is retrieved using LDClient and the result stored
+ * in the cache. Otherwise the method does nothing.
+ *
+ * @param resource the resource to retrieve
+ * @param options options for refreshing
+ * @return a Sesame Model holding the triples representing the resource
*/
- public void refreshExpired();
+ public Model get(URI resource, RefreshOpts... options);
+
/**
* Manually expire the caching information for the given resource. The resource will be
* re-retrieved upon the next access.
*
- * @param resource the Resource to expire.
+ * @param resource the resource to expire.
*/
public void expire(URI resource);
+
+ /**
+ * Return true in case the cache contains an entry for the resource given as argument.
+ *
+ * @param resource the resource to check
+ * @return true in case the resource is contained in the cache
+ */
+ public boolean contains(URI resource);
+
/**
* Manually expire all cached resources.
- *
- * @see #expire(org.openrdf.model.URI)
*/
- public void expireAll();
+ public void clear();
/**
@@ -79,25 +80,13 @@ public interface LDCachingService {
*/
public void shutdown();
- /**
- * Return a repository connection that can be used for accessing cached resources.
- *
- * @param resource the resource that will be cached
- * @return a repository connection that can be used for storing retrieved triples for caching
- */
- LDCachingConnection getCacheConnection(String resource) throws RepositoryException;
- /**
- * Return an iterator over all cache entries (can e.g. be used for refreshing or expiring).
- *
- * @return
- */
- CloseableIteration<CacheEntry, RepositoryException> listCacheEntries() throws RepositoryException;
- /**
- * Return an iterator over all expired cache entries (can e.g. be used for refreshing).
- *
- * @return
- */
- CloseableIteration<CacheEntry, RepositoryException> listExpiredEntries() throws RepositoryException;
+ public enum RefreshOpts {
+
+ /**
+ * Refresh the resource even if it is not yet expired
+ */
+ FORCE
+ }
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/8941574c/libraries/ldcache/ldcache-api/src/main/java/org/apache/marmotta/ldcache/api/LDCachingServiceNG.java
----------------------------------------------------------------------
diff --git a/libraries/ldcache/ldcache-api/src/main/java/org/apache/marmotta/ldcache/api/LDCachingServiceNG.java b/libraries/ldcache/ldcache-api/src/main/java/org/apache/marmotta/ldcache/api/LDCachingServiceNG.java
deleted file mode 100644
index 1a9d549..0000000
--- a/libraries/ldcache/ldcache-api/src/main/java/org/apache/marmotta/ldcache/api/LDCachingServiceNG.java
+++ /dev/null
@@ -1,92 +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.ldcache.api;
-
-import org.openrdf.model.Model;
-import org.openrdf.model.URI;
-
-/**
- * This is the next-generation API for LDCache that will become the default in Marmotta 3.3 or 4.0. For now,
- * LDCache implements both the old and the new style.
- * <p/>
- * User: sschaffe
- */
-public interface LDCachingServiceNG {
-
-
- /**
- * Refresh the resource passed as argument. If the resource is not yet cached or the cache entry is
- * expired or refreshing is forced, the remote resource is retrieved using LDClient and the result stored
- * in the cache. Otherwise the method does nothing.
- *
- *
- * @param resource the resource to refresh
- * @param options options for refreshing
- */
- public void refresh(URI resource, RefreshOpts... options);
-
-
- /**
- * Refresh and return the resource passed as argument. If the resource is not yet cached or the cache entry is
- * expired or refreshing is forced, the remote resource is retrieved using LDClient and the result stored
- * in the cache. Otherwise the method does nothing.
- *
- * @param resource the resource to retrieve
- * @param options options for refreshing
- * @return a Sesame Model holding the triples representing the resource
- */
- public Model get(URI resource, RefreshOpts... options);
-
-
- /**
- * Manually expire the caching information for the given resource. The resource will be
- * re-retrieved upon the next access.
- *
- * @param resource the resource to expire.
- */
- public void expire(URI resource);
-
-
- /**
- * Return true in case the cache contains an entry for the resource given as argument.
- *
- * @param resource the resource to check
- * @return true in case the resource is contained in the cache
- */
- public boolean contains(URI resource);
-
- /**
- * Manually expire all cached resources.
- */
- public void clear();
-
-
- /**
- * Shutdown the caching service and free all occupied runtime resources.
- */
- public void shutdown();
-
-
-
- public enum RefreshOpts {
-
- /**
- * Refresh the resource even if it is not yet expired
- */
- FORCE
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/8941574c/libraries/ldcache/ldcache-api/src/main/java/org/apache/marmotta/ldcache/sail/LDCachingSail.java
----------------------------------------------------------------------
diff --git a/libraries/ldcache/ldcache-api/src/main/java/org/apache/marmotta/ldcache/sail/LDCachingSail.java b/libraries/ldcache/ldcache-api/src/main/java/org/apache/marmotta/ldcache/sail/LDCachingSail.java
deleted file mode 100644
index 4bd678b..0000000
--- a/libraries/ldcache/ldcache-api/src/main/java/org/apache/marmotta/ldcache/sail/LDCachingSail.java
+++ /dev/null
@@ -1,34 +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.ldcache.sail;
-
-import org.openrdf.sail.Sail;
-
-/**
- * Add file description here!
- * <p/>
- * Author: Sebastian Schaffert (sschaffert@apache.org)
- */
-public interface LDCachingSail extends Sail {
-
- /**
- * Return a caching connection.
- * @return
- */
- public LDCachingSailConnection getConnection();
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/8941574c/libraries/ldcache/ldcache-api/src/main/java/org/apache/marmotta/ldcache/sail/LDCachingSailConnection.java
----------------------------------------------------------------------
diff --git a/libraries/ldcache/ldcache-api/src/main/java/org/apache/marmotta/ldcache/sail/LDCachingSailConnection.java b/libraries/ldcache/ldcache-api/src/main/java/org/apache/marmotta/ldcache/sail/LDCachingSailConnection.java
deleted file mode 100644
index bc4f0ce..0000000
--- a/libraries/ldcache/ldcache-api/src/main/java/org/apache/marmotta/ldcache/sail/LDCachingSailConnection.java
+++ /dev/null
@@ -1,57 +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.ldcache.sail;
-
-import org.apache.marmotta.ldcache.model.CacheEntry;
-import org.openrdf.model.URI;
-import org.openrdf.sail.SailConnection;
-import org.openrdf.sail.SailException;
-
-/**
- * Add file description here!
- * <p/>
- * Author: Sebastian Schaffert (sschaffert@apache.org)
- */
-public interface LDCachingSailConnection extends SailConnection {
-
- /**
- * Get the cache entry for the passed resource, if any. Returns null in case there is no cache entry.
- *
- *
- * @param resource the resource to look for
- * @return the cache entry for the resource, or null if the resource has never been cached or is expired
- */
- public CacheEntry getCacheEntry(URI resource) throws SailException;
-
- /**
- * Store a cache entry for the passed resource in the backend. Depending on the backend, this can be a
- * persistent storage or an in-memory storage.
- *
- * @param resource
- * @param entry
- */
- public void addCacheEntry(URI resource, CacheEntry entry) throws SailException;
-
-
- /**
- * Remove the currently stored cache entry for the passed resource from the backend.
- * @param resource
- */
- public void removeCacheEntry(URI resource) throws SailException;
-
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/8941574c/libraries/ldcache/ldcache-backend-file/src/main/java/org/apache/marmotta/ldcache/backend/file/LDCachingFileBackend.java
----------------------------------------------------------------------
diff --git a/libraries/ldcache/ldcache-backend-file/src/main/java/org/apache/marmotta/ldcache/backend/file/LDCachingFileBackend.java b/libraries/ldcache/ldcache-backend-file/src/main/java/org/apache/marmotta/ldcache/backend/file/LDCachingFileBackend.java
index bff143a..205933d 100644
--- a/libraries/ldcache/ldcache-backend-file/src/main/java/org/apache/marmotta/ldcache/backend/file/LDCachingFileBackend.java
+++ b/libraries/ldcache/ldcache-backend-file/src/main/java/org/apache/marmotta/ldcache/backend/file/LDCachingFileBackend.java
@@ -15,38 +15,32 @@
* limitations under the License.
*/
-/**
- *
- */
package org.apache.marmotta.ldcache.backend.file;
-import info.aduna.iteration.CloseableIteration;
-import info.aduna.iteration.ConvertingIteration;
-import info.aduna.iteration.FilterIteration;
-import info.aduna.iteration.IteratorIteration;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Date;
-
+import org.apache.marmotta.commons.sesame.model.ModelCommons;
import org.apache.marmotta.ldcache.api.LDCachingBackend;
-import org.apache.marmotta.ldcache.api.LDCachingConnection;
-import org.apache.marmotta.ldcache.backend.file.repository.LDCachingFileRepositoryConnection;
import org.apache.marmotta.ldcache.backend.file.util.FileBackendUtils;
import org.apache.marmotta.ldcache.model.CacheEntry;
+import org.openrdf.model.Model;
+import org.openrdf.model.URI;
import org.openrdf.model.ValueFactory;
+import org.openrdf.model.impl.TreeModel;
import org.openrdf.model.impl.ValueFactoryImpl;
import org.openrdf.repository.Repository;
+import org.openrdf.repository.RepositoryConnection;
import org.openrdf.repository.RepositoryException;
import org.openrdf.repository.sail.SailRepository;
-import org.openrdf.sail.SailException;
import org.openrdf.sail.nativerdf.NativeStore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.File;
+import java.io.IOException;
+
/**
- * @author jakob
+ * File-based implementation of the next generation LDCaching Backend API
*
+ * @author Sebastian Schaffert (sschaffert@apache.org)
*/
public class LDCachingFileBackend implements LDCachingBackend {
@@ -62,75 +56,135 @@ public class LDCachingFileBackend implements LDCachingBackend {
}
- /* (non-Javadoc)
- * @see org.apache.marmotta.ldcache.api.LDCachingBackend#getCacheConnection(java.lang.String)
+
+ /**
+ * Return the cache entry for the given resource, or null if this entry does not exist.
+ *
+ *
+ * @param resource the resource to retrieve the cache entry for
+ * @return
*/
@Override
- public LDCachingConnection getCacheConnection(String resource) throws RepositoryException {
+ public CacheEntry getEntry(URI resource) {
+ try {
+ // load metadata from disk
+ final File dataFile = FileBackendUtils.getMetaFile(resource, storageDir);
+ if (!(dataFile.exists())) return null;
+ final CacheEntry ce = FileBackendUtils.readCacheEntry(dataFile, getValueFactory());
+ if (FileBackendUtils.isExpired(ce)) return null;
+
+ // read triples for this entry from cache repository
+ RepositoryConnection con = cacheRepository.getConnection();
+ try {
+ con.begin();
+
+ Model triples = new TreeModel();
+ ModelCommons.add(triples, con.getStatements(resource,null,null,true));
+ ce.setTriples(triples);
+
+ con.commit();
+ } catch(RepositoryException ex) {
+ con.rollback();
+ } finally {
+ con.close();
+ }
+
+ return ce;
+ } catch (IOException | RepositoryException e) {
+ log.error("error while loading cache entry from file system:",e);
- return new LDCachingFileRepositoryConnection(cacheRepository, cacheRepository.getConnection(), storageDir);
+ return null;
+ }
}
- /* (non-Javadoc)
- * @see org.apache.marmotta.ldcache.api.LDCachingBackend#listExpiredEntries()
+
+ /**
+ * Update the cache entry for the given resource with the given entry.
+ *
+ * @param resource the resource to update
+ * @param entry the entry for the resource
*/
@Override
- public CloseableIteration<CacheEntry, RepositoryException> listExpiredEntries() throws RepositoryException {
- final Date now = new Date();
- return new FilterIteration<CacheEntry, RepositoryException>(listCacheEntries()) {
-
- @Override
- protected boolean accept(CacheEntry object)
- throws RepositoryException {
- return object.getExpiryDate().before(now);
+ public void putEntry(URI resource, CacheEntry entry) {
+ try {
+ FileBackendUtils.writeCacheEntry(entry, storageDir);
+
+ // update the repository with the triples from the entry
+ RepositoryConnection con = cacheRepository.getConnection();
+ try {
+ con.begin();
+
+ con.remove(resource,null,null);
+ con.add(entry.getTriples());
+
+ con.commit();
+ } catch(RepositoryException ex) {
+ con.rollback();
+ } finally {
+ con.close();
}
- };
+ } catch (IOException | RepositoryException e) {
+ log.error("could not store cache entry for {}: {}", resource.stringValue(), e.getMessage());
+ }
+
}
- /* (non-Javadoc)
- * @see org.apache.marmotta.ldcache.api.LDCachingBackend#listCacheEntries()
+ /**
+ * Remove the cache entry for the given resource if it exists. Does nothing otherwise.
+ *
+ * @param resource the resource to remove the entry for
*/
@Override
- public CloseableIteration<CacheEntry, RepositoryException> listCacheEntries()
- throws RepositoryException {
-
- final IteratorIteration<File, RepositoryException> ii = new IteratorIteration<File, RepositoryException>(FileBackendUtils.listMetaFiles(storageDir).iterator());
- return new ConvertingIteration<File, CacheEntry, RepositoryException>(ii) {
-
- @Override
- protected CacheEntry convert(File sourceObject)
- throws RepositoryException {
- try {
- return FileBackendUtils.readCacheEntry(sourceObject, cacheRepository.getValueFactory());
- } catch (IOException e) {
- log.warn("Could not read caching properties from '{}'", sourceObject.getPath());
- throw new RepositoryException(e);
- }
- }
+ public void removeEntry(URI resource) {
+ try {
+ final File metaFile = FileBackendUtils.getMetaFile(resource, storageDir);
+ if (metaFile.exists()) metaFile.delete();
+
+ // update the repository with the triples from the entry
+ RepositoryConnection con = cacheRepository.getConnection();
+ try {
+ con.begin();
- };
+ con.remove(resource, null, null);
+
+ con.commit();
+ } catch(RepositoryException ex) {
+ con.rollback();
+ } finally {
+ con.close();
+ }
+ } catch (RepositoryException e) {
+ log.error("could not remove cache entry for {}: {}", resource.stringValue(), e.getMessage());
+ }
}
/**
- * Return true in case the resource is a cached resource.
- *
- * @param resource the URI of the resource to check
- * @return true in case the resource is a cached resource
+ * Clear all entries in the cache backend.
*/
@Override
- public boolean isCached(String resource) throws RepositoryException {
+ public void clear() {
+ for(File metaFile : FileBackendUtils.listMetaFiles(storageDir)) {
+ metaFile.delete();
+ }
+
try {
- final File dataFile = FileBackendUtils.getMetaFile(resource, storageDir);
- if (!(dataFile.exists())) return false;
- final CacheEntry ce = FileBackendUtils.readCacheEntry(dataFile, new ValueFactoryImpl());
- //return ce != null && !FileBackendUtils.isExpired(ce) && ce.getTripleCount() > 0;
- return ce != null && ce.getTripleCount() > 0;
- } catch (IOException e) {
- throw new RepositoryException(e);
+ RepositoryConnection con = cacheRepository.getConnection();
+ try {
+ con.begin();
+
+ con.clear();
+
+ con.commit();
+ } catch(RepositoryException ex) {
+ con.rollback();
+ } finally {
+ con.close();
+ }
+ } catch(RepositoryException ex) {
+ log.error("could not clear cache: {}", ex.getMessage());
}
}
-
/* (non-Javadoc)
* @see org.apache.marmotta.ldcache.api.LDCachingBackend#initialize()
*/
@@ -165,4 +219,9 @@ public class LDCachingFileBackend implements LDCachingBackend {
}
+
+ private ValueFactory getValueFactory() {
+ return ValueFactoryImpl.getInstance();
+ }
+
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/8941574c/libraries/ldcache/ldcache-backend-file/src/main/java/org/apache/marmotta/ldcache/backend/file/LDCachingFileBackendNG.java
----------------------------------------------------------------------
diff --git a/libraries/ldcache/ldcache-backend-file/src/main/java/org/apache/marmotta/ldcache/backend/file/LDCachingFileBackendNG.java b/libraries/ldcache/ldcache-backend-file/src/main/java/org/apache/marmotta/ldcache/backend/file/LDCachingFileBackendNG.java
deleted file mode 100644
index d6c99fa..0000000
--- a/libraries/ldcache/ldcache-backend-file/src/main/java/org/apache/marmotta/ldcache/backend/file/LDCachingFileBackendNG.java
+++ /dev/null
@@ -1,227 +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.ldcache.backend.file;
-
-import org.apache.marmotta.commons.sesame.model.ModelCommons;
-import org.apache.marmotta.ldcache.api.LDCachingBackendNG;
-import org.apache.marmotta.ldcache.backend.file.util.FileBackendUtils;
-import org.apache.marmotta.ldcache.model.CacheEntry;
-import org.openrdf.model.Model;
-import org.openrdf.model.URI;
-import org.openrdf.model.ValueFactory;
-import org.openrdf.model.impl.TreeModel;
-import org.openrdf.model.impl.ValueFactoryImpl;
-import org.openrdf.repository.Repository;
-import org.openrdf.repository.RepositoryConnection;
-import org.openrdf.repository.RepositoryException;
-import org.openrdf.repository.sail.SailRepository;
-import org.openrdf.sail.nativerdf.NativeStore;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.File;
-import java.io.IOException;
-
-/**
- * File-based implementation of the next generation LDCaching Backend API
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class LDCachingFileBackendNG implements LDCachingBackendNG {
-
- private static Logger log = LoggerFactory.getLogger(LDCachingFileBackend.class);
-
- private final File storageDir;
-
- private Repository cacheRepository;
-
- public LDCachingFileBackendNG(File storageDir) throws RepositoryException {
- if (storageDir == null) throw new NullPointerException();
- this.storageDir = storageDir;
-
- }
-
-
- /**
- * Return the cache entry for the given resource, or null if this entry does not exist.
- *
- *
- * @param resource the resource to retrieve the cache entry for
- * @return
- */
- @Override
- public CacheEntry getEntry(URI resource) {
- try {
- // load metadata from disk
- final File dataFile = FileBackendUtils.getMetaFile(resource, storageDir);
- if (!(dataFile.exists())) return null;
- final CacheEntry ce = FileBackendUtils.readCacheEntry(dataFile, getValueFactory());
- if (FileBackendUtils.isExpired(ce)) return null;
-
- // read triples for this entry from cache repository
- RepositoryConnection con = cacheRepository.getConnection();
- try {
- con.begin();
-
- Model triples = new TreeModel();
- ModelCommons.add(triples, con.getStatements(resource,null,null,true));
- ce.setTriples(triples);
-
- con.commit();
- } catch(RepositoryException ex) {
- con.rollback();
- } finally {
- con.close();
- }
-
- return ce;
- } catch (IOException | RepositoryException e) {
- log.error("error while loading cache entry from file system:",e);
-
- return null;
- }
- }
-
-
- /**
- * Update the cache entry for the given resource with the given entry.
- *
- * @param resource the resource to update
- * @param entry the entry for the resource
- */
- @Override
- public void putEntry(URI resource, CacheEntry entry) {
- try {
- FileBackendUtils.writeCacheEntry(entry, storageDir);
-
- // update the repository with the triples from the entry
- RepositoryConnection con = cacheRepository.getConnection();
- try {
- con.begin();
-
- con.remove(resource,null,null);
- con.add(entry.getTriples());
-
- con.commit();
- } catch(RepositoryException ex) {
- con.rollback();
- } finally {
- con.close();
- }
- } catch (IOException | RepositoryException e) {
- log.error("could not store cache entry for {}: {}", resource.stringValue(), e.getMessage());
- }
-
- }
-
- /**
- * Remove the cache entry for the given resource if it exists. Does nothing otherwise.
- *
- * @param resource the resource to remove the entry for
- */
- @Override
- public void removeEntry(URI resource) {
- try {
- final File metaFile = FileBackendUtils.getMetaFile(resource, storageDir);
- if (metaFile.exists()) metaFile.delete();
-
- // update the repository with the triples from the entry
- RepositoryConnection con = cacheRepository.getConnection();
- try {
- con.begin();
-
- con.remove(resource, null, null);
-
- con.commit();
- } catch(RepositoryException ex) {
- con.rollback();
- } finally {
- con.close();
- }
- } catch (RepositoryException e) {
- log.error("could not remove cache entry for {}: {}", resource.stringValue(), e.getMessage());
- }
- }
-
- /**
- * Clear all entries in the cache backend.
- */
- @Override
- public void clear() {
- for(File metaFile : FileBackendUtils.listMetaFiles(storageDir)) {
- metaFile.delete();
- }
-
- try {
- RepositoryConnection con = cacheRepository.getConnection();
- try {
- con.begin();
-
- con.clear();
-
- con.commit();
- } catch(RepositoryException ex) {
- con.rollback();
- } finally {
- con.close();
- }
- } catch(RepositoryException ex) {
- log.error("could not clear cache: {}", ex.getMessage());
- }
- }
-
- /* (non-Javadoc)
- * @see org.apache.marmotta.ldcache.api.LDCachingBackend#initialize()
- */
- @Override
- public void initialize() {
- if (!storageDir.exists() && !storageDir.mkdirs()){
- log.error("Could not create storage directory: " + storageDir.getPath());
- } else if (!storageDir.isDirectory()) {
- log.error(storageDir.getPath() + " is not a directory");
- }
-
- File tripleDir = new File(storageDir,"triples");
-
- try {
- cacheRepository = new SailRepository(new NativeStore(tripleDir, "spoc"));
- cacheRepository.initialize();
- } catch (RepositoryException ex) {
- log.error("could not initialize cache directory",ex);
- }
- }
-
- /* (non-Javadoc)
- * @see org.apache.marmotta.ldcache.api.LDCachingBackend#shutdown()
- */
- @Override
- public void shutdown() {
- try {
- cacheRepository.shutDown();
- } catch (RepositoryException e) {
- log.error("error while shutting down cache repository", e);
- }
-
- }
-
-
- private ValueFactory getValueFactory() {
- return ValueFactoryImpl.getInstance();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/8941574c/libraries/ldcache/ldcache-backend-file/src/main/java/org/apache/marmotta/ldcache/backend/file/repository/LDCachingFileRepositoryConnection.java
----------------------------------------------------------------------
diff --git a/libraries/ldcache/ldcache-backend-file/src/main/java/org/apache/marmotta/ldcache/backend/file/repository/LDCachingFileRepositoryConnection.java b/libraries/ldcache/ldcache-backend-file/src/main/java/org/apache/marmotta/ldcache/backend/file/repository/LDCachingFileRepositoryConnection.java
deleted file mode 100644
index 959e424..0000000
--- a/libraries/ldcache/ldcache-backend-file/src/main/java/org/apache/marmotta/ldcache/backend/file/repository/LDCachingFileRepositoryConnection.java
+++ /dev/null
@@ -1,70 +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.ldcache.backend.file.repository;
-
-import org.apache.marmotta.ldcache.api.LDCachingConnection;
-import org.apache.marmotta.ldcache.backend.file.util.FileBackendUtils;
-import org.apache.marmotta.ldcache.model.CacheEntry;
-import org.openrdf.model.URI;
-import org.openrdf.repository.Repository;
-import org.openrdf.repository.RepositoryConnection;
-import org.openrdf.repository.RepositoryException;
-import org.openrdf.repository.base.RepositoryConnectionWrapper;
-
-import java.io.File;
-import java.io.IOException;
-
-public class LDCachingFileRepositoryConnection extends RepositoryConnectionWrapper implements LDCachingConnection {
-
- private final File baseDir;
-
- public LDCachingFileRepositoryConnection(Repository repository, RepositoryConnection repositoryConnection, File baseDir) {
- super(repository, repositoryConnection);
- this.baseDir = baseDir;
- }
-
- @Override
- public CacheEntry getCacheEntry(URI resource) throws RepositoryException {
- try {
- final File dataFile = FileBackendUtils.getMetaFile(resource, baseDir);
- if (!(dataFile.exists())) return null;
- final CacheEntry ce = FileBackendUtils.readCacheEntry(dataFile, getValueFactory());
- if (FileBackendUtils.isExpired(ce)) return null;
- return ce;
- } catch (IOException e) {
- throw new RepositoryException("could not read cache entry for " + resource.stringValue(), e);
- }
- }
-
- @Override
- public void addCacheEntry(URI resource, CacheEntry entry)
- throws RepositoryException {
- try {
- FileBackendUtils.writeCacheEntry(entry, baseDir);
- } catch (IOException e) {
- throw new RepositoryException("could not store cache entry for " + resource.stringValue(), e);
- }
- }
-
- @Override
- public void removeCacheEntry(URI resource) throws RepositoryException {
- final File metaFile = FileBackendUtils.getMetaFile(resource, baseDir);
- if (metaFile.exists()) metaFile.delete();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/8941574c/libraries/ldcache/ldcache-backend-file/src/test/java/org/apache/marmotta/ldcache/backend/file/test/LDCacheBackendTest.java
----------------------------------------------------------------------
diff --git a/libraries/ldcache/ldcache-backend-file/src/test/java/org/apache/marmotta/ldcache/backend/file/test/LDCacheBackendTest.java b/libraries/ldcache/ldcache-backend-file/src/test/java/org/apache/marmotta/ldcache/backend/file/test/LDCacheBackendTest.java
deleted file mode 100644
index 0a24002..0000000
--- a/libraries/ldcache/ldcache-backend-file/src/test/java/org/apache/marmotta/ldcache/backend/file/test/LDCacheBackendTest.java
+++ /dev/null
@@ -1,226 +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.ldcache.backend.file.test;
-
-import com.google.common.io.Files;
-import info.aduna.iteration.CloseableIteration;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang3.RandomStringUtils;
-import org.apache.marmotta.ldcache.api.LDCachingConnection;
-import org.apache.marmotta.ldcache.backend.file.LDCachingFileBackend;
-import org.apache.marmotta.ldcache.model.CacheEntry;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TestWatcher;
-import org.junit.runner.Description;
-import org.openrdf.model.Literal;
-import org.openrdf.model.Statement;
-import org.openrdf.model.URI;
-import org.openrdf.repository.RepositoryConnection;
-import org.openrdf.repository.RepositoryException;
-import org.openrdf.repository.RepositoryResult;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-/**
- * This test checks if the ldcache backend works, i.e. the system properly stores cache entries and cached triples.
- *
- * <p/>
- * Author: Sebastian Schaffert
- */
-public class LDCacheBackendTest {
-
-
- private LDCachingFileBackend backend;
-
- private File tmpDirectory;
-
- @Before
- public void initDatabase() throws RepositoryException {
- tmpDirectory = Files.createTempDir();
-
- backend = new LDCachingFileBackend(tmpDirectory);
- backend.initialize();
- }
-
- @After
- public void dropDatabase() throws RepositoryException, IOException {
- backend.shutdown();
-
- FileUtils.deleteDirectory(tmpDirectory);
- }
-
-
- final Logger logger =
- LoggerFactory.getLogger(this.getClass());
-
- @Rule
- public TestWatcher watchman = new TestWatcher() {
- /**
- * Invoked when a test is about to start
- */
- @Override
- protected void starting(Description description) {
- logger.info("{} being run...", description.getMethodName());
- }
- };
- /**
- * This test verifies if triples are added to the correct context using the repository connection obtained from the backend
- * @throws Exception
- */
- @Test
- public void testStoreTriples() throws Exception {
-
- RepositoryConnection con = backend.getCacheConnection("http://localhost/resource/1");
- try {
- con.begin();
-
- URI subject = con.getValueFactory().createURI("http://localhost/resource/1");
- URI predicate = con.getValueFactory().createURI("http://localhost/resource/" + RandomStringUtils.randomAlphanumeric(8));
- Literal object1 = con.getValueFactory().createLiteral(RandomStringUtils.random(64));
- Literal object2 = con.getValueFactory().createLiteral(RandomStringUtils.random(64));
-
- Statement stmt1 = con.getValueFactory().createStatement(subject,predicate,object1);
- Statement stmt2 = con.getValueFactory().createStatement(subject,predicate,object2);
-
- con.add(stmt1);
- con.add(stmt2);
-
- con.commit();
-
- RepositoryResult<Statement> it = con.getStatements(subject,predicate,null,true);
- try {
- while(it.hasNext()) {
- Statement next = it.next();
- Assert.assertEquals(subject, next.getSubject());
- }
- } finally {
- it.close();
- }
-
- con.commit();
- } catch(RepositoryException ex) {
- con.rollback();
- } finally {
- con.close();
- }
- }
-
- /**
- * Test storing and retrieving cache entries
- *
- * @throws Exception
- */
- @Test
- public void testStoreEntries() throws Exception {
- LDCachingConnection con = backend.getCacheConnection("http://localhost/resource/1");
- try {
- con.begin();
-
- URI subject1 = con.getValueFactory().createURI("http://localhost/resource/"+ RandomStringUtils.randomAlphanumeric(8));
- URI subject2 = con.getValueFactory().createURI("http://localhost/resource/"+ RandomStringUtils.randomAlphanumeric(8));
- Literal object1 = con.getValueFactory().createLiteral(RandomStringUtils.random(64));
- Literal object2 = con.getValueFactory().createLiteral(RandomStringUtils.random(64));
- URI predicate = con.getValueFactory().createURI("http://localhost/resource/"+ RandomStringUtils.randomAlphanumeric(8));
-
- Statement stmt1 = con.getValueFactory().createStatement(subject1,predicate,object1);
- Statement stmt2 = con.getValueFactory().createStatement(subject2,predicate,object2);
-
- con.add(stmt1);
- con.add(stmt2);
-
- con.commit();
-
- con.begin();
- CacheEntry entry1 = new CacheEntry();
- entry1.setExpiryDate(new Date(System.currentTimeMillis()+1000*60));
- entry1.setLastRetrieved(new Date());
- entry1.setUpdateCount(1);
- entry1.setResource(subject1);
- entry1.setTripleCount(1);
- con.addCacheEntry(subject1, entry1);
- con.commit();
-
- Assert.assertTrue(backend.isCached(subject1.stringValue()));
- Assert.assertFalse(backend.isCached(subject2.stringValue()));
- Assert.assertEquals(1,asList(backend.listCacheEntries()).size());
- Assert.assertEquals(0,asList(backend.listExpiredEntries()).size());
-
- con.begin();
- CacheEntry entry2 = new CacheEntry();
- entry2.setExpiryDate(new Date(System.currentTimeMillis() - 1000 * 60));
- entry2.setLastRetrieved(new Date());
- entry2.setUpdateCount(1);
- entry2.setResource(subject2);
- entry2.setTripleCount(1);
- con.addCacheEntry(subject2,entry2);
-
- con.commit();
-
- Assert.assertTrue(backend.isCached(subject1.stringValue()));
- Assert.assertTrue(backend.isCached(subject2.stringValue()));
- Assert.assertEquals(2,asList(backend.listCacheEntries()).size());
- Assert.assertEquals(1,asList(backend.listExpiredEntries()).size());
-
- con.begin();
- con.removeCacheEntry(subject1);
- con.commit();
-
- Assert.assertFalse(backend.isCached(subject1.stringValue()));
- Assert.assertTrue(backend.isCached(subject2.stringValue()));
- Assert.assertEquals(1,asList(backend.listCacheEntries()).size());
- Assert.assertEquals(1,asList(backend.listExpiredEntries()).size());
- } catch(RepositoryException ex) {
- con.rollback();
- } finally {
- con.close();
- }
- }
-
-
- /**
- * Workaround for https://openrdf.atlassian.net/browse/SES-1702 in Sesame 2.7.0-beta1
- * @param <E>
- * @return
- */
- public static <E,X extends Exception> List<E> asList(CloseableIteration<E,X> result) throws RepositoryException {
- ArrayList<E> collection = new ArrayList<E>();
- try {
- try {
- while (result.hasNext()) {
- collection.add(result.next());
- }
-
- return collection;
- } finally {
- result.close();
- }
- } catch(Throwable ex) {
- throw new RepositoryException(ex);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/8941574c/libraries/ldcache/ldcache-backend-file/src/test/java/org/apache/marmotta/ldcache/backend/file/test/LDCacheFileNGTest.java
----------------------------------------------------------------------
diff --git a/libraries/ldcache/ldcache-backend-file/src/test/java/org/apache/marmotta/ldcache/backend/file/test/LDCacheFileNGTest.java b/libraries/ldcache/ldcache-backend-file/src/test/java/org/apache/marmotta/ldcache/backend/file/test/LDCacheFileNGTest.java
deleted file mode 100644
index 333057e..0000000
--- a/libraries/ldcache/ldcache-backend-file/src/test/java/org/apache/marmotta/ldcache/backend/file/test/LDCacheFileNGTest.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.ldcache.backend.file.test;
-
-import com.google.common.io.Files;
-import org.apache.commons.io.FileUtils;
-import org.apache.marmotta.ldcache.api.LDCachingBackendNG;
-import org.apache.marmotta.ldcache.backend.file.LDCachingFileBackendNG;
-import org.apache.marmotta.ldcache.services.test.ng.BaseLDCacheNGTest;
-import org.junit.internal.AssumptionViolatedException;
-import org.openrdf.repository.RepositoryException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.File;
-import java.io.IOException;
-
-/**
- * Add file description here!
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class LDCacheFileNGTest extends BaseLDCacheNGTest {
-
- private static Logger log = LoggerFactory.getLogger(LDCacheFileNGTest.class);
-
- /**
- * Needs to be implemented by tests to provide the correct backend. Backend needs to be properly initialised.
- *
- * @return
- */
- @Override
- protected LDCachingBackendNG createBackend() {
- final File storageDir = Files.createTempDir();
-
- LDCachingBackendNG backend = null;
- try {
- backend = new LDCachingFileBackendNG(storageDir) {
- @Override
- public void shutdown() {
- super.shutdown();
-
- try {
- FileUtils.deleteDirectory(storageDir);
- } catch (IOException e) {
- }
- }
- };
- backend.initialize();
-
- return backend;
- } catch (RepositoryException e) {
- throw new AssumptionViolatedException("could not initialise backend",e);
- }
- }
-
-
-
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/8941574c/libraries/ldcache/ldcache-backend-file/src/test/java/org/apache/marmotta/ldcache/backend/file/test/LDCacheFileTest.java
----------------------------------------------------------------------
diff --git a/libraries/ldcache/ldcache-backend-file/src/test/java/org/apache/marmotta/ldcache/backend/file/test/LDCacheFileTest.java b/libraries/ldcache/ldcache-backend-file/src/test/java/org/apache/marmotta/ldcache/backend/file/test/LDCacheFileTest.java
new file mode 100644
index 0000000..d08d866
--- /dev/null
+++ b/libraries/ldcache/ldcache-backend-file/src/test/java/org/apache/marmotta/ldcache/backend/file/test/LDCacheFileTest.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.ldcache.backend.file.test;
+
+import com.google.common.io.Files;
+import org.apache.commons.io.FileUtils;
+import org.apache.marmotta.ldcache.api.LDCachingBackend;
+import org.apache.marmotta.ldcache.backend.file.LDCachingFileBackend;
+import org.apache.marmotta.ldcache.services.test.ng.BaseLDCacheTest;
+import org.junit.internal.AssumptionViolatedException;
+import org.openrdf.repository.RepositoryException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Add file description here!
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class LDCacheFileTest extends BaseLDCacheTest {
+
+ private static Logger log = LoggerFactory.getLogger(LDCacheFileTest.class);
+
+ /**
+ * Needs to be implemented by tests to provide the correct backend. Backend needs to be properly initialised.
+ *
+ * @return
+ */
+ @Override
+ protected LDCachingBackend createBackend() {
+ final File storageDir = Files.createTempDir();
+
+ LDCachingBackend backend = null;
+ try {
+ backend = new LDCachingFileBackend(storageDir) {
+ @Override
+ public void shutdown() {
+ super.shutdown();
+
+ try {
+ FileUtils.deleteDirectory(storageDir);
+ } catch (IOException e) {
+ }
+ }
+ };
+ backend.initialize();
+
+ return backend;
+ } catch (RepositoryException e) {
+ throw new AssumptionViolatedException("could not initialise backend",e);
+ }
+ }
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/8941574c/libraries/ldcache/ldcache-backend-infinispan/src/main/java/org/apache/marmotta/ldcache/backend/infinispan/LDCachingInfinispanBackend.java
----------------------------------------------------------------------
diff --git a/libraries/ldcache/ldcache-backend-infinispan/src/main/java/org/apache/marmotta/ldcache/backend/infinispan/LDCachingInfinispanBackend.java b/libraries/ldcache/ldcache-backend-infinispan/src/main/java/org/apache/marmotta/ldcache/backend/infinispan/LDCachingInfinispanBackend.java
index 686d11a..d112a32 100644
--- a/libraries/ldcache/ldcache-backend-infinispan/src/main/java/org/apache/marmotta/ldcache/backend/infinispan/LDCachingInfinispanBackend.java
+++ b/libraries/ldcache/ldcache-backend-infinispan/src/main/java/org/apache/marmotta/ldcache/backend/infinispan/LDCachingInfinispanBackend.java
@@ -14,14 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.marmotta.ldcache.backend.infinispan;
-import info.aduna.iteration.CloseableIteration;
-import info.aduna.iteration.CloseableIteratorIteration;
-import info.aduna.iteration.EmptyIteration;
import org.apache.marmotta.ldcache.api.LDCachingBackend;
-import org.apache.marmotta.ldcache.api.LDCachingConnection;
-import org.apache.marmotta.ldcache.backend.infinispan.repository.LDCachingInfinispanRepositoryConnection;
import org.apache.marmotta.ldcache.model.CacheEntry;
import org.infinispan.Cache;
import org.infinispan.configuration.cache.CacheMode;
@@ -34,8 +30,7 @@ import org.infinispan.distribution.ch.SyncConsistentHashFactory;
import org.infinispan.eviction.EvictionStrategy;
import org.infinispan.manager.DefaultCacheManager;
import org.infinispan.manager.EmbeddedCacheManager;
-import org.openrdf.model.Model;
-import org.openrdf.repository.RepositoryException;
+import org.openrdf.model.URI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -48,9 +43,10 @@ import java.util.concurrent.TimeUnit;
*/
public class LDCachingInfinispanBackend implements LDCachingBackend {
+ private static Logger log = LoggerFactory.getLogger(LDCachingInfinispanBackend.class);
+
public static final String LDCACHE_ENTRY_CACHE = "ldcache-entry-cache";
public static final String LDCACHE_TRIPLE_CACHE = "ldcache-triple-cache";
- private static Logger log = LoggerFactory.getLogger(LDCachingInfinispanBackend.class);
private EmbeddedCacheManager cacheManager;
@@ -61,7 +57,6 @@ public class LDCachingInfinispanBackend implements LDCachingBackend {
private boolean clustered;
private Cache<String,CacheEntry> entryCache;
- private Cache<String,Model> tripleCache;
/**
* Create a non-clustered instance of the infinispan cache.
@@ -137,73 +132,59 @@ public class LDCachingInfinispanBackend implements LDCachingBackend {
}
- public Cache<String,CacheEntry> getEntryCache() {
- if(entryCache == null) {
- cacheManager.defineConfiguration(LDCACHE_ENTRY_CACHE, defaultConfiguration);
-
- entryCache = cacheManager.<String,CacheEntry>getCache(LDCACHE_ENTRY_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
- }
-
+ public synchronized Cache<String,CacheEntry> getEntryCache() {
return entryCache;
}
- public Cache<String,Model> getTripleCache() {
- if(tripleCache == null) {
- cacheManager.defineConfiguration(LDCACHE_TRIPLE_CACHE, defaultConfiguration);
-
- tripleCache = cacheManager.<String,Model>getCache(LDCACHE_TRIPLE_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
- }
-
- return tripleCache;
-
- }
/**
- * Return a repository connection that can be used for caching. The LDCache will first remove all statements for
- * the newly cached resources and then add retrieved statements as-is to this connection and properly commit and
- * close it after use.
- * <p/>
- * Note that in case the statements should be rewritten this method must take care of providing the proper
- * connection, e.g. by using a ContextAwareRepositoryConnection to add a context to all statements when adding them.
+ * Return the cache entry for the given resource, or null if this entry does not exist.
*
- * @param resource the resource that will be cached
- * @return a repository connection that can be used for storing retrieved triples for caching
+ *
+ * @param resource the resource to retrieve the cache entry for
+ * @return
*/
@Override
- public LDCachingConnection getCacheConnection(String resource) throws RepositoryException {
- return new LDCachingInfinispanRepositoryConnection(this, resource);
+ public CacheEntry getEntry(URI resource) {
+ CacheEntry entry = getEntryCache().get(resource.stringValue());
+
+ log.debug("retrieved entry for resource {}: {}", resource.stringValue(), entry);
+
+ return entry;
}
/**
- * Return an iterator over all expired cache entries (can e.g. be used for refreshing).
+ * Update the cache entry for the given resource with the given entry.
*
- * @return
+ * @param resource the resource to update
+ * @param entry the entry for the resource
*/
@Override
- public CloseableIteration<CacheEntry, RepositoryException> listExpiredEntries() throws RepositoryException {
- return new EmptyIteration<>(); // Infinispan does not allow listing expired entries
+ public void putEntry(URI resource, CacheEntry entry) {
+ log.debug("updating entry for resource {} to {}", resource.stringValue(), entry);
+
+ getEntryCache().put(resource.stringValue(), entry);
}
/**
- * Return an iterator over all cache entries (can e.g. be used for refreshing or expiring).
+ * Remove the cache entry for the given resource if it exists. Does nothing otherwise.
*
- * @return
+ * @param resource the resource to remove the entry for
*/
@Override
- public CloseableIteration<CacheEntry, RepositoryException> listCacheEntries() throws RepositoryException {
- return new CloseableIteratorIteration<>(getEntryCache().values().iterator());
+ public void removeEntry(URI resource) {
+ log.debug("removing entry for resource {}", resource.stringValue());
+
+ getEntryCache().remove(resource.stringValue());
}
/**
- * Return true in case the resource is a cached resource.
- *
- * @param resource the URI of the resource to check
- * @return true in case the resource is a cached resource
+ * Clear all entries in the cache backend.
*/
@Override
- public boolean isCached(String resource) throws RepositoryException {
- return getEntryCache().containsKey(resource);
+ public void clear() {
+ getEntryCache().clear();
}
/**
@@ -213,8 +194,12 @@ public class LDCachingInfinispanBackend implements LDCachingBackend {
public void initialize() {
cacheManager = new DefaultCacheManager(globalConfiguration, defaultConfiguration, true);
- getEntryCache();
- getTripleCache();
+ if(entryCache == null) {
+ cacheManager.defineConfiguration(LDCACHE_ENTRY_CACHE, defaultConfiguration);
+
+ entryCache = cacheManager.<String,CacheEntry>getCache(LDCACHE_ENTRY_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
+ }
+
log.info("initialised cache manager ({})", globalConfiguration.isClustered() ? "cluster name: "+globalConfiguration.transport().clusterName() : "single host");
http://git-wip-us.apache.org/repos/asf/marmotta/blob/8941574c/libraries/ldcache/ldcache-backend-infinispan/src/main/java/org/apache/marmotta/ldcache/backend/infinispan/LDCachingInfinispanBackendNG.java
----------------------------------------------------------------------
diff --git a/libraries/ldcache/ldcache-backend-infinispan/src/main/java/org/apache/marmotta/ldcache/backend/infinispan/LDCachingInfinispanBackendNG.java b/libraries/ldcache/ldcache-backend-infinispan/src/main/java/org/apache/marmotta/ldcache/backend/infinispan/LDCachingInfinispanBackendNG.java
deleted file mode 100644
index 74c6c78..0000000
--- a/libraries/ldcache/ldcache-backend-infinispan/src/main/java/org/apache/marmotta/ldcache/backend/infinispan/LDCachingInfinispanBackendNG.java
+++ /dev/null
@@ -1,222 +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.ldcache.backend.infinispan;
-
-import org.apache.marmotta.ldcache.api.LDCachingBackendNG;
-import org.apache.marmotta.ldcache.model.CacheEntry;
-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.context.Flag;
-import org.infinispan.distribution.ch.SyncConsistentHashFactory;
-import org.infinispan.eviction.EvictionStrategy;
-import org.infinispan.manager.DefaultCacheManager;
-import org.infinispan.manager.EmbeddedCacheManager;
-import org.openrdf.model.URI;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.concurrent.TimeUnit;
-
-/**
- * Add file description here!
- * <p/>
- * Author: Sebastian Schaffert (sschaffert@apache.org)
- */
-public class LDCachingInfinispanBackendNG implements LDCachingBackendNG {
-
- private static Logger log = LoggerFactory.getLogger(LDCachingInfinispanBackendNG.class);
-
- public static final String LDCACHE_ENTRY_CACHE = "ldcache-entry-cache";
- public static final String LDCACHE_TRIPLE_CACHE = "ldcache-triple-cache";
-
- private EmbeddedCacheManager cacheManager;
-
- private GlobalConfiguration globalConfiguration;
-
- private Configuration defaultConfiguration;
-
- private boolean clustered;
-
- private Cache<String,CacheEntry> entryCache;
-
- /**
- * Create a non-clustered instance of the infinispan cache.
- */
- public LDCachingInfinispanBackendNG() {
- globalConfiguration = new GlobalConfigurationBuilder()
- .classLoader(LDCachingInfinispanBackendNG.class.getClassLoader())
- .globalJmxStatistics()
- .jmxDomain("org.apache.marmotta.ldcache")
- .allowDuplicateDomains(true)
- .build();
-
- defaultConfiguration = new ConfigurationBuilder()
- .clustering()
- .cacheMode(CacheMode.LOCAL)
- .eviction()
- .strategy(EvictionStrategy.LIRS)
- .maxEntries(100000)
- .expiration()
- .lifespan(7, TimeUnit.DAYS)
- .maxIdle(1, TimeUnit.DAYS)
- .build();
-
- clustered = false;
-
- }
-
- /**
- * Create a clustered instane of the infinispan cache backend using the provided cluster and machine name
- * @param clusterName
- * @param machineName
- */
- public LDCachingInfinispanBackendNG(String clusterName, String machineName) {
- globalConfiguration = new GlobalConfigurationBuilder()
- .classLoader(LDCachingInfinispanBackendNG.class.getClassLoader())
- .transport()
- .defaultTransport()
- .clusterName(clusterName)
- .machineId(machineName)
- .addProperty("configurationFile", "jgroups-kiwi.xml")
- .globalJmxStatistics()
- .jmxDomain("org.apache.marmotta.ldcache")
- .allowDuplicateDomains(true)
- .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(7, TimeUnit.DAYS)
- .maxIdle(1, TimeUnit.DAYS)
- .build();
-
-
- clustered = true;
-
-
- }
-
-
- public synchronized Cache<String,CacheEntry> getEntryCache() {
- return entryCache;
-
- }
-
-
- /**
- * Return the cache entry for the given resource, or null if this entry does not exist.
- *
- *
- * @param resource the resource to retrieve the cache entry for
- * @return
- */
- @Override
- public CacheEntry getEntry(URI resource) {
- CacheEntry entry = getEntryCache().get(resource.stringValue());
-
- log.debug("retrieved entry for resource {}: {}", resource.stringValue(), entry);
-
- return entry;
- }
-
- /**
- * Update the cache entry for the given resource with the given entry.
- *
- * @param resource the resource to update
- * @param entry the entry for the resource
- */
- @Override
- public void putEntry(URI resource, CacheEntry entry) {
- log.debug("updating entry for resource {} to {}", resource.stringValue(), entry);
-
- getEntryCache().put(resource.stringValue(), entry);
- }
-
- /**
- * Remove the cache entry for the given resource if it exists. Does nothing otherwise.
- *
- * @param resource the resource to remove the entry for
- */
- @Override
- public void removeEntry(URI resource) {
- log.debug("removing entry for resource {}", resource.stringValue());
-
- getEntryCache().remove(resource.stringValue());
- }
-
- /**
- * Clear all entries in the cache backend.
- */
- @Override
- public void clear() {
- getEntryCache().clear();
- }
-
- /**
- * Carry out any initialization tasks that might be necessary
- */
- @Override
- public void initialize() {
- cacheManager = new DefaultCacheManager(globalConfiguration, defaultConfiguration, true);
-
- if(entryCache == null) {
- cacheManager.defineConfiguration(LDCACHE_ENTRY_CACHE, defaultConfiguration);
-
- entryCache = cacheManager.<String,CacheEntry>getCache(LDCACHE_ENTRY_CACHE).getAdvancedCache().withFlags(Flag.SKIP_LOCKING, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP);
- }
-
-
- log.info("initialised cache manager ({})", globalConfiguration.isClustered() ? "cluster name: "+globalConfiguration.transport().clusterName() : "single host");
-
- }
-
- /**
- * Shutdown the backend and free all runtime resources.
- */
- @Override
- public void shutdown() {
- 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!");
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/8941574c/libraries/ldcache/ldcache-backend-infinispan/src/main/java/org/apache/marmotta/ldcache/backend/infinispan/repository/LDCachingInfinispanRepositoryConnection.java
----------------------------------------------------------------------
diff --git a/libraries/ldcache/ldcache-backend-infinispan/src/main/java/org/apache/marmotta/ldcache/backend/infinispan/repository/LDCachingInfinispanRepositoryConnection.java b/libraries/ldcache/ldcache-backend-infinispan/src/main/java/org/apache/marmotta/ldcache/backend/infinispan/repository/LDCachingInfinispanRepositoryConnection.java
deleted file mode 100644
index 863c78d..0000000
--- a/libraries/ldcache/ldcache-backend-infinispan/src/main/java/org/apache/marmotta/ldcache/backend/infinispan/repository/LDCachingInfinispanRepositoryConnection.java
+++ /dev/null
@@ -1,130 +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.ldcache.backend.infinispan.repository;
-
-import org.apache.marmotta.ldcache.api.LDCachingConnection;
-import org.apache.marmotta.ldcache.backend.infinispan.LDCachingInfinispanBackend;
-import org.apache.marmotta.ldcache.model.CacheEntry;
-import org.openrdf.model.Model;
-import org.openrdf.model.Statement;
-import org.openrdf.model.URI;
-import org.openrdf.model.impl.TreeModel;
-import org.openrdf.repository.Repository;
-import org.openrdf.repository.RepositoryConnection;
-import org.openrdf.repository.RepositoryException;
-import org.openrdf.repository.RepositoryResult;
-import org.openrdf.repository.base.RepositoryConnectionWrapper;
-import org.openrdf.repository.sail.SailRepository;
-import org.openrdf.sail.memory.MemoryStore;
-
-import java.util.concurrent.TimeUnit;
-
-/**
- * Add file description here!
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class LDCachingInfinispanRepositoryConnection extends RepositoryConnectionWrapper implements LDCachingConnection {
-
- private LDCachingInfinispanBackend backend;
-
- private String resource;
-
- public LDCachingInfinispanRepositoryConnection(LDCachingInfinispanBackend backend, String resource) throws RepositoryException {
- super(getModelRepository(backend.getTripleCache().get(resource)));
- setDelegate(getRepository().getConnection());
- this.backend = backend;
- this.resource = resource;
- }
-
-
- private static Repository getModelRepository(Model model) throws RepositoryException {
- Repository repository = new SailRepository(new MemoryStore());
- repository.initialize();
-
- RepositoryConnection con = repository.getConnection();
- try {
- con.begin();
-
- if(model != null) {
- con.add(model);
- }
-
- con.commit();
- } catch(RepositoryException ex) {
- con.rollback();
- } finally {
- con.close();
- }
-
- return repository;
- }
-
-
- /**
- * Get the cache entry for the passed resource, if any. Returns null in case there is no cache entry.
- *
- * @param resource the resource to look for
- * @return the cache entry for the resource, or null if the resource has never been cached or is expired
- */
- @Override
- public CacheEntry getCacheEntry(URI resource) throws RepositoryException {
- return backend.getEntryCache().get(resource.stringValue());
- }
-
- /**
- * Store a cache entry for the passed resource in the backend. Depending on the backend, this can be a
- * persistent storage or an in-memory storage.
- *
- * @param resource
- * @param entry
- */
- @Override
- public void addCacheEntry(URI resource, CacheEntry entry) throws RepositoryException {
- backend.getEntryCache().put(resource.stringValue(),entry,entry.getExpiryDate().getTime() - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
-
- Model model = new TreeModel();
-
- RepositoryResult<Statement> triples = getStatements(resource,null,null,true);
- try {
- while(triples.hasNext()) {
- model.add(triples.next());
- }
- } finally {
- triples.close();
- }
-
- backend.getTripleCache().put(resource.stringValue(),model,entry.getExpiryDate().getTime() - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
- }
-
- /**
- * Remove the currently stored cache entry for the passed resource from the backend.
- *
- * @param resource
- */
- @Override
- public void removeCacheEntry(URI resource) throws RepositoryException {
- backend.getEntryCache().remove(resource.stringValue());
- backend.getTripleCache().remove(resource.stringValue());
- }
-
- @Override
- public void close() throws RepositoryException {
- super.close();
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/8941574c/libraries/ldcache/ldcache-backend-infinispan/src/test/java/org/apache/marmotta/ldcache/infinispan/test/LDCacheInfinispanNGTest.java
----------------------------------------------------------------------
diff --git a/libraries/ldcache/ldcache-backend-infinispan/src/test/java/org/apache/marmotta/ldcache/infinispan/test/LDCacheInfinispanNGTest.java b/libraries/ldcache/ldcache-backend-infinispan/src/test/java/org/apache/marmotta/ldcache/infinispan/test/LDCacheInfinispanNGTest.java
deleted file mode 100644
index 5710042..0000000
--- a/libraries/ldcache/ldcache-backend-infinispan/src/test/java/org/apache/marmotta/ldcache/infinispan/test/LDCacheInfinispanNGTest.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.ldcache.infinispan.test;
-
-import org.apache.marmotta.ldcache.api.LDCachingBackendNG;
-import org.apache.marmotta.ldcache.backend.infinispan.LDCachingInfinispanBackendNG;
-import org.apache.marmotta.ldcache.services.test.ng.BaseLDCacheNGTest;
-
-/**
- * Add file description here!
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public class LDCacheInfinispanNGTest extends BaseLDCacheNGTest {
-
- /**
- * Needs to be implemented by tests to provide the correct backend. Backend needs to be properly initialised.
- *
- * @return
- */
- @Override
- protected LDCachingBackendNG createBackend() {
- LDCachingBackendNG backend = new LDCachingInfinispanBackendNG();
- backend.initialize();
-
- return backend;
- }
-}