jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [03/11] jena git commit: Renamed CanAbortComparator to AbortableComparator.
Date Wed, 27 Jul 2016 12:06:32 GMT
Renamed CanAbortComparator to AbortableComparator.

Moved volatile boolean into AbortableComparator and give that
class a cancel method, called from SortedDataBag, and make
AbortableComparator a static class so the management of the
comparator is explicit.


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

Branch: refs/heads/master
Commit: 5d09cb51f42635989ce8ead5e032a15bcf672100
Parents: 4493dd3
Author: Chris Dollin <ehog.hedge@googlemail.com>
Authored: Tue Jul 19 12:13:03 2016 +0100
Committer: Chris Dollin <ehog.hedge@googlemail.com>
Committed: Tue Jul 19 12:13:03 2016 +0100

----------------------------------------------------------------------
 .../apache/jena/atlas/data/SortedDataBag.java   | 24 ++++++++++++++------
 1 file changed, 17 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/5d09cb51/jena-arq/src/main/java/org/apache/jena/atlas/data/SortedDataBag.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/atlas/data/SortedDataBag.java b/jena-arq/src/main/java/org/apache/jena/atlas/data/SortedDataBag.java
index f01e9d6..68de3f6 100644
--- a/jena-arq/src/main/java/org/apache/jena/atlas/data/SortedDataBag.java
+++ b/jena-arq/src/main/java/org/apache/jena/atlas/data/SortedDataBag.java
@@ -69,21 +69,20 @@ public class SortedDataBag<E> extends AbstractDataBag<E>
     
     protected final ThresholdPolicy<E> policy;
     protected final SerializationFactory<E> serializationFactory;
-    protected final CanAbortComparator comparator;
+    protected final AbortableComparator<E> comparator;
     
     protected boolean finishedAdding = false;
     protected boolean spilled = false;
     protected boolean closed = false;
-    protected volatile boolean cancelled;
     
     public SortedDataBag(ThresholdPolicy<E> policy, SerializationFactory<E> serializerFactory,
Comparator<? super E> comparator)
     {
         this.policy = policy;
         this.serializationFactory = serializerFactory;
-        this.comparator = new CanAbortComparator(comparator);
+        this.comparator = new AbortableComparator<E>(comparator);
     }
     
-    private final class CanAbortComparator implements Comparator<E> 
+    private static final class AbortableComparator<E> implements Comparator<E>

     	{
     	/**
     	    The test for whether the sort has been cancelled is
@@ -98,9 +97,11 @@ public class SortedDataBag<E> extends AbstractDataBag<E>
     	*/
 		int count = 0;
 		
+		protected volatile boolean cancelled;
+		
 		final Comparator<? super E> baseComparator;
 		
-		public CanAbortComparator(Comparator<? super E> comparator) 
+		public AbortableComparator(Comparator<? super E> comparator) 
 		{
 			this.baseComparator = comparator;
 		}
@@ -131,11 +132,20 @@ public class SortedDataBag<E> extends AbstractDataBag<E>
 			}
 			return false;
 		}
+		
+		/**
+		    Arrange that the next on-frequency cancellation test
+		    in compare will succeed, aborting the sort. 
+		*/
+		public void cancel() 
+		{
+			cancelled = true;
+		}
 	}
 
     /**
         <code>AbandonSort</code> is the exception thrown from
-        <code>CanAbortComparator</code> to abandon a sort.
+        <code>AbortableComparator</code> to abandon a sort.
     */
 	public static class AbandonSort extends RuntimeException 
     {
@@ -148,7 +158,7 @@ public class SortedDataBag<E> extends AbstractDataBag<E>
 	*/
 	public void cancel() 
 	{
-		cancelled = true;
+		comparator.cancel();
 	}
     
     protected void checkClosed()


Mime
View raw message