You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streams.apache.org by sb...@apache.org on 2015/10/20 16:36:48 UTC
[2/2] incubator-streams git commit: PR feedback
https://github.com/apache/incubator-streams/pull/263
PR feedback https://github.com/apache/incubator-streams/pull/263
Project: http://git-wip-us.apache.org/repos/asf/incubator-streams/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-streams/commit/fba147e4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-streams/tree/fba147e4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-streams/diff/fba147e4
Branch: refs/heads/master
Commit: fba147e44b14e0dc58cd3b5fa8da234b195be806
Parents: 20e7b66
Author: Steve Blackmon <sb...@apache.org>
Authored: Mon Oct 19 14:53:29 2015 -0500
Committer: Steve Blackmon <sb...@apache.org>
Committed: Mon Oct 19 14:53:29 2015 -0500
----------------------------------------------------------------------
.../provider/TwitterFollowingProviderTask.java | 31 ++--
.../provider/TwitterFriendsProviderTask.java | 181 -------------------
2 files changed, 17 insertions(+), 195 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/fba147e4/streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/provider/TwitterFollowingProviderTask.java
----------------------------------------------------------------------
diff --git a/streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/provider/TwitterFollowingProviderTask.java b/streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/provider/TwitterFollowingProviderTask.java
index 0bbdb33..1f40953 100644
--- a/streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/provider/TwitterFollowingProviderTask.java
+++ b/streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/provider/TwitterFollowingProviderTask.java
@@ -37,7 +37,7 @@ import twitter4j.TwitterObjectFactory;
import java.io.IOException;
/**
- * Retrieve recent posts for a single user id.
+ * Retrieve friend or follower connections for a single user id.
*/
public class TwitterFollowingProviderTask implements Runnable {
@@ -48,26 +48,26 @@ public class TwitterFollowingProviderTask implements Runnable {
protected TwitterFollowingProvider provider;
protected Twitter client;
protected Long id;
- protected Boolean ids_only;
+ protected Boolean idsOnly;
protected String screenName;
protected String endpoint;
private int max_per_page = 200;
- public TwitterFollowingProviderTask(TwitterFollowingProvider provider, Twitter twitter, Long id, String endpoint, Boolean ids_only) {
+ public TwitterFollowingProviderTask(TwitterFollowingProvider provider, Twitter twitter, Long id, String endpoint, Boolean idsOnly) {
this.provider = provider;
this.client = twitter;
this.id = id;
this.endpoint = endpoint;
- this.ids_only = ids_only;
+ this.idsOnly = idsOnly;
}
- public TwitterFollowingProviderTask(TwitterFollowingProvider provider, Twitter twitter, String screenName, String endpoint, Boolean ids_only) {
+ public TwitterFollowingProviderTask(TwitterFollowingProvider provider, Twitter twitter, String screenName, String endpoint, Boolean idsOnly) {
this.provider = provider;
this.client = twitter;
this.screenName = screenName;
this.endpoint = endpoint;
- this.ids_only = ids_only;
+ this.idsOnly = idsOnly;
}
@@ -89,7 +89,7 @@ public class TwitterFollowingProviderTask implements Runnable {
Preconditions.checkArgument(endpoint.equals("friends") || endpoint.equals("followers"));
- if( ids_only == true )
+ if( idsOnly )
collectIds(id);
else
collectUsers(id);
@@ -128,7 +128,7 @@ public class TwitterFollowingProviderTask implements Runnable {
String otherJson = TwitterObjectFactory.getRawJSON(other);
try {
- Follow follow;
+ Follow follow = null;
if( endpoint.equals("followers") ) {
follow = new Follow()
.withFollowee(mapper.readValue(userJson, User.class))
@@ -137,10 +137,12 @@ public class TwitterFollowingProviderTask implements Runnable {
follow = new Follow()
.withFollowee(mapper.readValue(otherJson, User.class))
.withFollower(mapper.readValue(userJson, User.class));
- } else {
- throw new Exception("endpoint must be set to 'friends' or 'followers'");
}
ComponentUtils.offerUntilSuccess(new StreamsDatum(follow), provider.providerQueue);
+
+ Preconditions.checkNotNull(follow);
+
+
} catch (JsonParseException e) {
LOGGER.warn(e.getMessage());
} catch (JsonMappingException e) {
@@ -186,7 +188,7 @@ public class TwitterFollowingProviderTask implements Runnable {
for (long otherId : ids.getIDs()) {
try {
- Follow follow;
+ Follow follow = null;
if( endpoint.equals("followers") ) {
follow = new Follow()
.withFollowee(new User().withId(id))
@@ -195,12 +197,13 @@ public class TwitterFollowingProviderTask implements Runnable {
follow = new Follow()
.withFollowee(new User().withId(otherId))
.withFollower(new User().withId(id));
- } else {
- throw new Exception("endpoint must be set to 'friends' or 'followers'");
}
ComponentUtils.offerUntilSuccess(new StreamsDatum(follow), provider.providerQueue);
+
+ Preconditions.checkNotNull(follow);
+
} catch (Exception e) {
- LOGGER.warn(e.getMessage());
+ LOGGER.warn("Exception: {}", e);
}
}
if( ids.hasNext() )
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/fba147e4/streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/provider/TwitterFriendsProviderTask.java
----------------------------------------------------------------------
diff --git a/streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/provider/TwitterFriendsProviderTask.java b/streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/provider/TwitterFriendsProviderTask.java
deleted file mode 100644
index c5ababe..0000000
--- a/streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/provider/TwitterFriendsProviderTask.java
+++ /dev/null
@@ -1,181 +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
- *
- * 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.streams.twitter.provider;
-
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.databind.JsonMappingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.common.collect.Lists;
-import org.apache.streams.core.StreamsDatum;
-import org.apache.streams.jackson.StreamsJacksonMapper;
-import org.apache.streams.twitter.pojo.Follow;
-import org.apache.streams.util.ComponentUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import twitter4j.PagableResponseList;
-import twitter4j.Twitter;
-import twitter4j.TwitterException;
-import twitter4j.TwitterObjectFactory;
-import twitter4j.User;
-
-import java.io.IOException;
-
-/**
- * Retrieve recent posts for a single user id.
- */
-public class TwitterFriendsProviderTask implements Runnable {
-
- private final static Logger LOGGER = LoggerFactory.getLogger(TwitterFriendsProviderTask.class);
-
- private final static ObjectMapper mapper = StreamsJacksonMapper.getInstance();
-
- protected TwitterFollowingProvider provider;
- protected Twitter client;
- protected Long id;
- protected String screenName;
-
- public TwitterFriendsProviderTask(TwitterFollowingProvider provider, Twitter twitter, Long id) {
- this.provider = provider;
- this.client = twitter;
- this.id = id;
- }
-
- public TwitterFriendsProviderTask(TwitterFollowingProvider provider, Twitter twitter, String screenName) {
- this.provider = provider;
- this.client = twitter;
- this.screenName = screenName;
- }
-
-
- @Override
- public void run() {
-
- if( id != null )
- getFriends(id);
- if( screenName != null)
- getFriends(screenName);
-
- LOGGER.info(id != null ? id.toString() : screenName + " Thread Finished");
-
- }
-
- protected void getFriends(Long id) {
-
- int keepTrying = 0;
-
- long curser = -1;
-
- do
- {
- try
- {
- twitter4j.User follower4j;
- String followerJson;
- try {
- follower4j = client.users().showUser(id);
- followerJson = TwitterObjectFactory.getRawJSON(follower4j);
- } catch (TwitterException e) {
- LOGGER.error("Failure looking up " + id);
- break;
- }
-
- PagableResponseList<User> followeeList = client.friendsFollowers().getFriendsList(id.longValue(), curser);
-
- for (twitter4j.User followee4j : followeeList ) {
-
- String followeeJson = TwitterObjectFactory.getRawJSON(followee4j);
-
- try {
- Follow follow = new Follow()
- .withFollowee(mapper.readValue(followeeJson, org.apache.streams.twitter.pojo.User.class))
- .withFollower(mapper.readValue(followerJson, org.apache.streams.twitter.pojo.User.class));
-
- ComponentUtils.offerUntilSuccess(new StreamsDatum(follow), provider.providerQueue);
- } catch (JsonParseException e) {
- LOGGER.warn(e.getMessage());
- } catch (JsonMappingException e) {
- LOGGER.warn(e.getMessage());
- } catch (IOException e) {
- LOGGER.warn(e.getMessage());
- }
- }
- curser = followeeList.getNextCursor();
- }
- catch(TwitterException twitterException) {
- keepTrying += TwitterErrorHandler.handleTwitterError(client, twitterException);
- }
- catch(Exception e) {
- keepTrying += TwitterErrorHandler.handleTwitterError(client, e);
- }
- } while (curser != 0 && keepTrying < 10);
- }
-
- protected void getFriends(String screenName) {
-
- int keepTrying = 0;
-
- long curser = -1;
-
- do
- {
- try
- {
- twitter4j.User follower4j;
- String followerJson;
- try {
- follower4j = client.users().showUser(screenName);
- followerJson = TwitterObjectFactory.getRawJSON(follower4j);
- } catch (TwitterException e) {
- LOGGER.error("Failure looking up " + screenName);
- break;
- }
-
- PagableResponseList<User> followeeList = client.friendsFollowers().getFriendsList(screenName, curser);
-
- for (twitter4j.User followee4j : followeeList ) {
-
- String followeeJson = TwitterObjectFactory.getRawJSON(followee4j);
-
- try {
- Follow follow = new Follow()
- .withFollowee(mapper.readValue(followeeJson, org.apache.streams.twitter.pojo.User.class))
- .withFollower(mapper.readValue(followerJson, org.apache.streams.twitter.pojo.User.class));
-
- ComponentUtils.offerUntilSuccess(new StreamsDatum(follow), provider.providerQueue);
- } catch (JsonParseException e) {
- LOGGER.warn(e.getMessage());
- } catch (JsonMappingException e) {
- LOGGER.warn(e.getMessage());
- } catch (IOException e) {
- LOGGER.warn(e.getMessage());
- }
- }
- curser = followeeList.getNextCursor();
- }
- catch(TwitterException twitterException) {
- keepTrying += TwitterErrorHandler.handleTwitterError(client, twitterException);
- }
- catch(Exception e) {
- keepTrying += TwitterErrorHandler.handleTwitterError(client, e);
- }
- } while (curser != 0 && keepTrying < 10);
- }
-
-
-}