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: Twitter Modificaitons
Date Mon, 05 May 2014 22:28:55 GMT
Github user mfranklin commented on a diff in the pull request:

    https://github.com/apache/incubator-streams/pull/8#discussion_r12303349
  
    --- Diff: streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/provider/TwitterUserInformationProvider.java
---
    @@ -0,0 +1,286 @@
    +package org.apache.streams.twitter.provider;
    +
    +import com.google.common.base.Preconditions;
    +import com.google.common.util.concurrent.ListenableFuture;
    +import com.google.common.util.concurrent.ListeningExecutorService;
    +import com.google.common.util.concurrent.MoreExecutors;
    +import com.typesafe.config.Config;
    +import org.apache.streams.config.StreamsConfigurator;
    +import org.apache.streams.core.StreamsDatum;
    +import org.apache.streams.core.StreamsProvider;
    +import org.apache.streams.core.StreamsResultSet;
    +import org.apache.streams.twitter.TwitterStreamConfiguration;
    +import org.apache.streams.twitter.TwitterUserInformationConfiguration;
    +import org.joda.time.DateTime;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +import sun.reflect.generics.reflectiveObjects.NotImplementedException;
    +import twitter4j.*;
    +import twitter4j.conf.ConfigurationBuilder;
    +import twitter4j.json.DataObjectFactory;
    +
    +import java.io.Serializable;
    +import java.math.BigInteger;
    +import java.util.ArrayList;
    +import java.util.Iterator;
    +import java.util.List;
    +import java.util.Queue;
    +import java.util.concurrent.*;
    +
    +public class TwitterUserInformationProvider implements StreamsProvider, Serializable
    +{
    +
    +    public static final String STREAMS_ID = "TwitterUserInformationProvider";
    +    private static final Logger LOGGER = LoggerFactory.getLogger(TwitterUserInformationProvider.class);
    +
    +
    +    private TwitterUserInformationConfiguration twitterUserInformationConfiguration;
    +
    +    private Class klass;
    +    protected volatile Queue<StreamsDatum> providerQueue = new LinkedBlockingQueue<StreamsDatum>();
    +
    +    public TwitterUserInformationConfiguration getConfig()              { return twitterUserInformationConfiguration;
}
    +
    +    public void setConfig(TwitterUserInformationConfiguration config)   { this.twitterUserInformationConfiguration
= config; }
    +
    +    protected Iterator<Long[]> idsBatches;
    +    protected Iterator<String[]> screenNameBatches;
    +
    +    protected ListeningExecutorService executor;
    +
    +    protected DateTime start;
    +    protected DateTime end;
    +
    +    private static ExecutorService newFixedThreadPoolWithQueueSize(int nThreads, int
queueSize) {
    +        return new ThreadPoolExecutor(nThreads, nThreads,
    +                5000L, TimeUnit.MILLISECONDS,
    +                new ArrayBlockingQueue<Runnable>(queueSize, true), new ThreadPoolExecutor.CallerRunsPolicy());
    +    }
    +
    +    public TwitterUserInformationProvider() {
    +        Config config = StreamsConfigurator.config.getConfig("twitter");
    +        this.twitterUserInformationConfiguration = TwitterStreamConfigurator.detectTwitterUserInformationConfiguration(config);
    +
    +    }
    +
    +    public TwitterUserInformationProvider(TwitterUserInformationConfiguration config)
{
    +        this.twitterUserInformationConfiguration = config;
    +    }
    +
    +    public TwitterUserInformationProvider(Class klass) {
    +        Config config = StreamsConfigurator.config.getConfig("twitter");
    +        this.twitterUserInformationConfiguration = TwitterStreamConfigurator.detectTwitterUserInformationConfiguration(config);
    +        this.klass = klass;
    +    }
    +
    +    public TwitterUserInformationProvider(TwitterUserInformationConfiguration config,
Class klass) {
    +        this.twitterUserInformationConfiguration = config;
    +        this.klass = klass;
    +    }
    +
    +    public Queue<StreamsDatum> getProviderQueue() {
    +        return this.providerQueue;
    +    }
    +
    +    @Override
    +    public void startStream() {
    +        // no op
    +    }
    +
    +
    +    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)) {
    +                    String json = DataObjectFactory.getRawJSON(tStat);
    +                    providerQueue.offer(new StreamsDatum(json));
    --- End diff --
    
    May not succeed.  Try utility method noted above


---
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