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 2013/01/26 21:12:31 UTC

svn commit: r1438954 - /jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/lang/StreamedRDFIterator.java

Author: andy
Date: Sat Jan 26 20:12:31 2013
New Revision: 1438954

URL: http://svn.apache.org/viewvc?rev=1438954&view=rev
Log:
Use AtomicBoolean for private member variables shared across threads.

Modified:
    jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/lang/StreamedRDFIterator.java

Modified: jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/lang/StreamedRDFIterator.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/lang/StreamedRDFIterator.java?rev=1438954&r1=1438953&r2=1438954&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/lang/StreamedRDFIterator.java (original)
+++ jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/lang/StreamedRDFIterator.java Sat Jan 26 20:12:31 2013
@@ -21,6 +21,7 @@ package org.apache.jena.riot.lang;
 import java.util.NoSuchElementException;
 import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.atomic.AtomicBoolean ;
 
 import org.apache.jena.riot.system.PrefixMap;
 import org.apache.jena.riot.system.StreamRDF;
@@ -43,7 +44,8 @@ import org.apache.jena.riot.system.Strea
 public abstract class StreamedRDFIterator<T> implements RDFParserOutputIterator<T> {
 
     protected BlockingQueue<T> buffer;
-    private boolean started = false, finished = false;
+    private AtomicBoolean started = new AtomicBoolean(false) ;
+    private AtomicBoolean finished = new AtomicBoolean(false) ;
     private T next = null;
     private PrefixMap prefixes = new PrefixMap();
     private String baseIri;
@@ -85,11 +87,11 @@ public abstract class StreamedRDFIterato
      */
     @Override
     public final boolean hasNext() {
-        if (!this.started) {
+        if (!this.started.get()) {
             throw new IllegalStateException("Tried to read from iterator before the Stream was started, please ensure that a producer thread has called start() on the stream before attempting to iterate over it");
         } else if (this.next != null) {
             return true;
-        } else if (this.finished && buffer.isEmpty()) {
+        } else if (this.finished.get() && buffer.isEmpty()) {
             return false;
         } else {
             this.getNext();
@@ -120,7 +122,7 @@ public abstract class StreamedRDFIterato
 
             // As soon as we see the finished signal has been set stop
             // waiting for more elements
-            if (this.finished)
+            if (this.finished.get())
                 break;
 
             // Back off
@@ -146,7 +148,7 @@ public abstract class StreamedRDFIterato
      */
     @Override
     public final T next() {
-        if (!this.started) {
+        if (!this.started.get()) {
             throw new IllegalStateException("Tried to read from iterator before the Stream was started, please ensure that a producer thread has called start() on the stream before attempting to iterate over it");
         } else if (this.hasNext()) {
             T t = this.next;
@@ -164,10 +166,10 @@ public abstract class StreamedRDFIterato
 
     @Override
     public final void start() {
-        if (this.started) {
+        if (this.started.get()) {
             throw new IllegalStateException("A StreamedRDFIterator is not reusable, please create a new instance");
         }
-        this.started = true;
+        this.started.set(true);
     }
     
     /**
@@ -176,7 +178,7 @@ public abstract class StreamedRDFIterato
      * @return True if safe to iterate
      */
     public final boolean canIterate() {
-        return this.started;
+        return this.started.get();
     }
 
     @Override
@@ -207,7 +209,7 @@ public abstract class StreamedRDFIterato
 
     @Override
     public final void finish() {
-        this.finished = true;
+        this.finished.set(true) ;
     }
 
 }
\ No newline at end of file