streams-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sblack...@apache.org
Subject [16/18] git commit: STREAMS-121 | Change volatile booleans to AtomicBooleans per pull request feedbask
Date Mon, 21 Jul 2014 04:49:31 GMT
STREAMS-121 | Change volatile booleans to AtomicBooleans per pull request feedbask


Project: http://git-wip-us.apache.org/repos/asf/incubator-streams/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-streams/commit/110dddbd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-streams/tree/110dddbd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-streams/diff/110dddbd

Branch: refs/heads/master
Commit: 110dddbd25eefbce5ec959103f6004cca5864f28
Parents: 45510b2
Author: rebanks <rebanks@w2odigital.com>
Authored: Mon Jul 14 14:05:37 2014 -0500
Committer: rebanks <rebanks@w2odigital.com>
Committed: Mon Jul 14 14:05:37 2014 -0500

----------------------------------------------------------------------
 .../apache/streams/instagram/InstagramConfigurator.java   |  2 +-
 .../instagram/provider/InstagramRecentMediaCollector.java |  9 +++++----
 .../instagram/provider/InstagramRecentMediaProvider.java  | 10 +++++-----
 .../provider/InstagramRecentMediaProviderTest.java        |  3 ++-
 4 files changed, 13 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/110dddbd/streams-contrib/streams-provider-instagram/src/main/java/org/apache/streams/instagram/InstagramConfigurator.java
----------------------------------------------------------------------
diff --git a/streams-contrib/streams-provider-instagram/src/main/java/org/apache/streams/instagram/InstagramConfigurator.java
b/streams-contrib/streams-provider-instagram/src/main/java/org/apache/streams/instagram/InstagramConfigurator.java
index cab072d..11e6d79 100644
--- a/streams-contrib/streams-provider-instagram/src/main/java/org/apache/streams/instagram/InstagramConfigurator.java
+++ b/streams-contrib/streams-provider-instagram/src/main/java/org/apache/streams/instagram/InstagramConfigurator.java
@@ -28,7 +28,7 @@ import org.slf4j.LoggerFactory;
 import java.io.IOException;
 
 /**
- * 
+ *
  */
 public class InstagramConfigurator {
 

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/110dddbd/streams-contrib/streams-provider-instagram/src/main/java/org/apache/streams/instagram/provider/InstagramRecentMediaCollector.java
----------------------------------------------------------------------
diff --git a/streams-contrib/streams-provider-instagram/src/main/java/org/apache/streams/instagram/provider/InstagramRecentMediaCollector.java
b/streams-contrib/streams-provider-instagram/src/main/java/org/apache/streams/instagram/provider/InstagramRecentMediaCollector.java
index e459a0a..4f27e49 100644
--- a/streams-contrib/streams-provider-instagram/src/main/java/org/apache/streams/instagram/provider/InstagramRecentMediaCollector.java
+++ b/streams-contrib/streams-provider-instagram/src/main/java/org/apache/streams/instagram/provider/InstagramRecentMediaCollector.java
@@ -25,6 +25,7 @@ import org.slf4j.LoggerFactory;
 
 import java.util.Queue;
 import java.util.Set;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 /**
  * Executes on all of the Instagram requests to collect the media feed data.
@@ -43,14 +44,14 @@ public class InstagramRecentMediaCollector implements Runnable {
     protected Queue dataQueue; //exposed for testing
     private InstagramUserInformationConfiguration config;
     private Instagram instagramClient;
-    private volatile boolean isCompleted;
+    private AtomicBoolean isCompleted;
 
 
     public InstagramRecentMediaCollector(Queue<MediaFeedData> queue, InstagramUserInformationConfiguration
config) {
         this.dataQueue = queue;
         this.config = config;
         this.instagramClient = new Instagram(this.config.getClientId());
-        this.isCompleted = false;
+        this.isCompleted = new AtomicBoolean(false);
     }
 
     /**
@@ -151,7 +152,7 @@ public class InstagramRecentMediaCollector implements Runnable {
      * @return true when the collector has queued all of available media feed data for the
provided users.
      */
     public boolean isCompleted() {
-        return this.isCompleted;
+        return this.isCompleted.get();
     }
 
     @Override
@@ -159,6 +160,6 @@ public class InstagramRecentMediaCollector implements Runnable {
         for(Long userId : getUserIds()) {
             getUserMedia(userId);
         }
-        this.isCompleted = true;
+        this.isCompleted.set(true);
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/110dddbd/streams-contrib/streams-provider-instagram/src/main/java/org/apache/streams/instagram/provider/InstagramRecentMediaProvider.java
----------------------------------------------------------------------
diff --git a/streams-contrib/streams-provider-instagram/src/main/java/org/apache/streams/instagram/provider/InstagramRecentMediaProvider.java
b/streams-contrib/streams-provider-instagram/src/main/java/org/apache/streams/instagram/provider/InstagramRecentMediaProvider.java
index 3d67a48..30ddda4 100644
--- a/streams-contrib/streams-provider-instagram/src/main/java/org/apache/streams/instagram/provider/InstagramRecentMediaProvider.java
+++ b/streams-contrib/streams-provider-instagram/src/main/java/org/apache/streams/instagram/provider/InstagramRecentMediaProvider.java
@@ -29,6 +29,7 @@ import java.util.Queue;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 /**
  * Instagram {@link org.apache.streams.core.StreamsProvider} that provides the recent media
data for a group of users
@@ -39,7 +40,7 @@ public class InstagramRecentMediaProvider implements StreamsProvider {
     private InstagramRecentMediaCollector dataCollector;
     protected Queue<MediaFeedData> mediaFeedQueue; //exposed for testing
     private ExecutorService executorService;
-    private volatile boolean isCompleted;
+    private AtomicBoolean isCompleted;
 
     public InstagramRecentMediaProvider() {
         this(InstagramConfigurator.detectInstagramUserInformationConfiguration(StreamsConfigurator.config.getConfig("instagram")));
@@ -48,7 +49,6 @@ public class InstagramRecentMediaProvider implements StreamsProvider {
     public InstagramRecentMediaProvider(InstagramUserInformationConfiguration config) {
         this.config = config;
         this.mediaFeedQueue = Queues.newConcurrentLinkedQueue();
-        this.isCompleted = false;
     }
 
     @Override
@@ -77,7 +77,7 @@ public class InstagramRecentMediaProvider implements StreamsProvider {
                 batch.add(new StreamsDatum(data, data.getId()));
             }
         }
-        this.isCompleted = batch.size() == 0 && this.mediaFeedQueue.isEmpty() &&
this.dataCollector.isCompleted();
+        this.isCompleted.set(batch.size() == 0 && this.mediaFeedQueue.isEmpty() &&
this.dataCollector.isCompleted());
         return new StreamsResultSet(batch);
     }
 
@@ -93,12 +93,12 @@ public class InstagramRecentMediaProvider implements StreamsProvider {
 
     @Override
     public boolean isRunning() {
-        return !this.isCompleted;
+        return !this.isCompleted.get();
     }
 
     @Override
     public void prepare(Object configurationObject) {
-
+        this.isCompleted = new AtomicBoolean(false);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/110dddbd/streams-contrib/streams-provider-instagram/src/test/java/org/apache/streams/instagram/provider/InstagramRecentMediaProviderTest.java
----------------------------------------------------------------------
diff --git a/streams-contrib/streams-provider-instagram/src/test/java/org/apache/streams/instagram/provider/InstagramRecentMediaProviderTest.java
b/streams-contrib/streams-provider-instagram/src/test/java/org/apache/streams/instagram/provider/InstagramRecentMediaProviderTest.java
index 59e90b4..d81f85a 100644
--- a/streams-contrib/streams-provider-instagram/src/test/java/org/apache/streams/instagram/provider/InstagramRecentMediaProviderTest.java
+++ b/streams-contrib/streams-provider-instagram/src/test/java/org/apache/streams/instagram/provider/InstagramRecentMediaProviderTest.java
@@ -63,7 +63,7 @@ public class InstagramRecentMediaProviderTest {
                 return collectorStub;
             }
         };
-
+        provider.prepare(null);
         provider.startStream();
 
         latch.await();
@@ -141,6 +141,7 @@ public class InstagramRecentMediaProviderTest {
                 };
             }
         };
+        provider.prepare(null);
         provider.startStream();
         while(provider.isRunning()) {
             try {


Mime
View raw message