You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2016/06/29 15:39:31 UTC

[2/6] jena git commit: JENA-901 Avoid exposing the Guava cache as protected

JENA-901 Avoid exposing the Guava cache as protected

.. but just in case (and to match the rest of the class)
add protected methods for manipulating the cache


Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/529fc965
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/529fc965
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/529fc965

Branch: refs/heads/master
Commit: 529fc9656a9742e47a0ce4a2a6e21a6257c6cc05
Parents: a9b8dc1
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Tue Mar 31 00:58:23 2015 +0100
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Jun 24 13:26:52 2016 +0100

----------------------------------------------------------------------
 jena-core/pom.xml                               |  2 +-
 .../reasoner/rulesys/impl/LPBRuleEngine.java    | 83 +++++++++++---------
 2 files changed, 45 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/529fc965/jena-core/pom.xml
----------------------------------------------------------------------
diff --git a/jena-core/pom.xml b/jena-core/pom.xml
index 2261db9..a142371 100644
--- a/jena-core/pom.xml
+++ b/jena-core/pom.xml
@@ -59,7 +59,7 @@
 
     <dependency>
     	<groupId>org.apache.jena</groupId>
-    	<artifactId>jena-shadowed-guava</artifactId>
+    	<artifactId>jena-shaded-guava</artifactId>
     	<version>3.1.1-SNAPSHOT</version>
     </dependency>
 

http://git-wip-us.apache.org/repos/asf/jena/blob/529fc965/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/impl/LPBRuleEngine.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/impl/LPBRuleEngine.java b/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/impl/LPBRuleEngine.java
index edfc575..4ce515d 100644
--- a/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/impl/LPBRuleEngine.java
+++ b/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/impl/LPBRuleEngine.java
@@ -73,8 +73,11 @@ public class LPBRuleEngine {
 
     /** Table mapping tabled goals to generators for those goals.
      *  This is here so that partial goal state can be shared across multiple queries.
+     *
+     *  Note: Do no expose as protected/public, as this depends on
+     *  the shadowed org.apache.jena.ext.com.google.common.*
      */
-    protected Cache<TriplePattern, Generator> tabledGoals = CacheBuilder.newBuilder()
+    Cache<TriplePattern, Generator> tabledGoals = CacheBuilder.newBuilder()
     	       .maximumSize(MAX_CACHED_TABLED_GOALS).weakValues().build();
 
     /** Set of generators waiting to be run */
@@ -130,7 +133,7 @@ public class LPBRuleEngine {
      */
     public synchronized void reset() {
         checkSafeToUpdate();
-        tabledGoals.invalidateAll();
+        clearCachedTabledGoals();
         agenda.clear();
     }
 
@@ -277,30 +280,23 @@ public class LPBRuleEngine {
      * @param clauses the precomputed set of code blocks used to implement the goal
      */
     public synchronized Generator generatorFor(final TriplePattern goal, final List<RuleClauseCode> clauses) {
-        try {
-			return tabledGoals.get(goal, new Callable<Generator>() {
-			 	@Override
-			    public Generator call() {
-			 		/** FIXME: Unify with #generatorFor(TriplePattern) - but investigate what about
-			 		 * the edge case that this method might have been called with the of goal == null
-			 		 * or goal.size()==0 -- which gives different behaviour in
-			 		 * LPInterpreter constructor than through the route of
-			 		 * generatorFor(TriplePattern) which calls a different LPInterpreter constructor
-			 		 * which would fill in from RuleStore.
-			 		 */
-			        LPInterpreter interpreter = new LPInterpreter(LPBRuleEngine.this, goal, clauses, false);
-			        activeInterpreters.add(interpreter);
-			        Generator generator = new Generator(interpreter, goal);
-			        schedule(generator);
-			        return generator;
-			 	}
-			});
-		} catch (ExecutionException e) {
-			if (e.getCause() instanceof RuntimeException) {
-				throw (RuntimeException)e.getCause();
-			}
-			throw new RuntimeException(e);
-		}
+          return getCachedTabledGoal(goal, new Callable<Generator>() {
+      		 	@Override
+      		    public Generator call() {
+      		 		/** FIXME: Unify with #generatorFor(TriplePattern) - but investigate what about
+      		 		 * the edge case that this method might have been called with the of goal == null
+      		 		 * or goal.size()==0 -- which gives different behaviour in
+      		 		 * LPInterpreter constructor than through the route of
+      		 		 * generatorFor(TriplePattern) which calls a different LPInterpreter constructor
+      		 		 * which would fill in from RuleStore.
+      		 		 */
+      		        LPInterpreter interpreter = new LPInterpreter(LPBRuleEngine.this, goal, clauses, false);
+      		        activeInterpreters.add(interpreter);
+      		        Generator generator = new Generator(interpreter, goal);
+      		        schedule(generator);
+      		        return generator;
+      		 	}
+      		});
     }
 
     /**
@@ -309,29 +305,38 @@ public class LPBRuleEngine {
      * @param goal the goal whose results are to be generated
      */
     public synchronized Generator generatorFor(final TriplePattern goal) {
-        try {
-			return tabledGoals.get(goal, new Callable<Generator>() {
-			 	@Override
-			    public Generator call() {
-		            LPInterpreter interpreter = new LPInterpreter(LPBRuleEngine.this, goal, false);
-		            activeInterpreters.add(interpreter);
-		            Generator generator = new Generator(interpreter, goal);
-		            schedule(generator);
-		            return generator;
-			 	}
-			});
+		return getCachedTabledGoal(goal, new Callable<Generator>() {
+		 	@Override
+		    public Generator call() {
+	            LPInterpreter interpreter = new LPInterpreter(LPBRuleEngine.this, goal, false);
+	            activeInterpreters.add(interpreter);
+	            Generator generator = new Generator(interpreter, goal);
+	            schedule(generator);
+	            return generator;
+		 	}
+		});
+    }
+
+    protected Generator getCachedTabledGoal(TriplePattern goal,
+			Callable<Generator> callable) {
+    	try {
+			return tabledGoals.get(goal, callable);
 		} catch (ExecutionException e) {
 			if (e.getCause() instanceof RuntimeException) {
 				throw (RuntimeException)e.getCause();
 			}
 			throw new RuntimeException(e);
 		}
-    }
+	}
 
-    long cachedTabledGoals() {
+	protected long cachedTabledGoals() {
     	return tabledGoals.size();
     }
 
+	protected void clearCachedTabledGoals() {
+		tabledGoals.invalidateAll();
+	}
+
     /**
      * Register that a generator or specific generator state (Consumer choice point)
      * is now ready to run.