streams-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfranklin <...@git.apache.org>
Subject [GitHub] incubator-streams pull request: Streams 115
Date Mon, 21 Jul 2014 14:05:31 GMT
Github user mfranklin commented on a diff in the pull request:

    https://github.com/apache/incubator-streams/pull/51#discussion_r15169900
  
    --- Diff: streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/provider/TwitterTimelineProvider.java
---
    @@ -125,101 +104,88 @@ public TwitterTimelineProvider(TwitterStreamConfiguration config,
Class klass) {
         @Override
         public void startStream() {
             LOGGER.debug("{} startStream", STREAMS_ID);
    -        throw new org.apache.commons.lang.NotImplementedException();
    -    }
     
    -    protected void captureTimeline(long currentId) {
    +        Preconditions.checkArgument(idsBatches.hasNext() || screenNameBatches.hasNext());
     
    -        Paging paging = new Paging(1, 200);
    -        List<Status> statuses = null;
    -        boolean KeepGoing = true;
    -        boolean hadFailure = false;
    +        LOGGER.info("readCurrent");
     
    -        do
    -        {
    -            int keepTrying = 0;
    +        while(idsBatches.hasNext())
    +            loadBatch(idsBatches.next());
     
    -            // keep trying to load, give it 5 attempts.
    -            //This value was chosen because it seemed like a reasonable number of times
    -            //to retry capturing a timeline given the sorts of errors that could potentially
    -            //occur (network timeout/interruption, faulty client, etc.)
    -            while (keepTrying < 5)
    -            {
    +        while(screenNameBatches.hasNext())
    +            loadBatch(screenNameBatches.next());
     
    -                try
    -                {
    -                    statuses = client.getUserTimeline(currentId, paging);
    -                    for (Status tStat : statuses) {
    -                        String json = TwitterObjectFactory.getRawJSON(tStat);
    -                        try {
    -                            lock.readLock().lock();
    -                            ComponentUtils.offerUntilSuccess(new StreamsDatum(json),
providerQueue);
    -                        } finally {
    -                            lock.readLock().unlock();
    -                        }
    -                    }
    -
    -                    paging.setPage(paging.getPage() + 1);
    -
    -                    keepTrying = 10;
    -                }
    -                catch(TwitterException twitterException) {
    -                    keepTrying += TwitterErrorHandler.handleTwitterError(client, twitterException);
    -                }
    -                catch(Exception e) {
    -                    keepTrying += TwitterErrorHandler.handleTwitterError(client, e);
    -                }
    -            }
    -        }
    -        while (shouldContinuePulling(statuses));
    +        executor.shutdown();
         }
     
    -    private Map<Long, Long> userPullInfo;
    -
         protected boolean shouldContinuePulling(List<Status> statuses) {
             return (statuses != null) && (statuses.size() > 0);
         }
     
    -    private void sleep()
    -    {
    -        Thread.yield();
    -        try {
    -            // wait one tenth of a millisecond
    -            Thread.yield();
    -            Thread.sleep(1);
    -            Thread.yield();
    -        }
    -        catch(IllegalArgumentException e) {
    -            // passing in static values, this will never happen
    -        }
    -        catch(InterruptedException e) {
    -            // noOp, there must have been an issue sleeping
    +    private void loadBatch(Long[] ids) {
    +        Twitter client = getTwitterClient();
    +        int keepTrying = 0;
    +
    +        // keep trying to load, give it 5 attempts.
    +        //while (keepTrying < 10)
    +        while (keepTrying < 1)
    +        {
    +            try
    +            {
    +                long[] toQuery = new long[ids.length];
    +                for(int i = 0; i < ids.length; i++)
    +                    toQuery[i] = ids[i];
    +
    +                for (User tStat : client.lookupUsers(toQuery)) {
    +
    +                    TwitterTimelineProviderTask providerTask = new TwitterTimelineProviderTask(this,
client, tStat.getId());
    +                    executor.submit(providerTask);
    +
    +                }
    +                keepTrying = 10;
    +            }
    +            catch(TwitterException twitterException) {
    +                keepTrying += TwitterErrorHandler.handleTwitterError(client, twitterException);
    +            }
    +            catch(Exception e) {
    +                keepTrying += TwitterErrorHandler.handleTwitterError(client, e);
    +            }
             }
    -        Thread.yield();
         }
     
    -    public StreamsResultSet readCurrent() {
    -        LOGGER.debug("{} readCurrent", STREAMS_ID);
    -
    -        Preconditions.checkArgument(ids.hasNext());
    -        StreamsResultSet result;
    +    private void loadBatch(String[] ids) {
    --- End diff --
    
    This appears to be the exact same logic, but with a different type parameter.  Wouldn't
it make more sense to have one method convert the argument to the target type and then use
the same logic?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message