streams-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfranklin <>
Subject [GitHub] incubator-streams pull request: Streams 144
Date Mon, 18 Aug 2014 15:50:58 GMT
Github user mfranklin commented on a diff in the pull request:
    --- Diff: streams-contrib/streams-provider-instagram/src/main/java/org/apache/streams/instagram/provider/
    @@ -0,0 +1,192 @@
    +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 *
    + *
    +Unless required by applicable law or agreed to in writing,
    +software distributed under the License is distributed on an
    +KIND, either express or implied. See the License for the
    +specific language governing permissions and limitations
    +under the License. */
    +package org.apache.streams.instagram.provider;
    +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.instagram.InstagramConfiguration;
    +import org.apache.streams.instagram.InstagramConfigurator;
    +import org.apache.streams.instagram.User;
    +import org.apache.streams.instagram.UsersInfo;
    +import org.apache.streams.util.ComponentUtils;
    +import org.apache.streams.util.SerializationUtil;
    +import org.joda.time.DateTime;
    +import java.math.BigInteger;
    +import java.util.Collection;
    +import java.util.Map;
    +import java.util.Queue;
    +import java.util.Set;
    +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 Instagram
data for a group of users
    + */
    +public abstract class InstagramAbstractProvider implements StreamsProvider {
    +    protected InstagramConfiguration config;
    +    private InstagramDataCollector dataCollector;
    +    protected Queue<StreamsDatum> dataQueue; //exposed for testing
    +    private ExecutorService executorService;
    +    private AtomicBoolean isCompleted;
    +    public InstagramAbstractProvider() {
    +        this.config = InstagramConfigurator.detectInstagramConfiguration(StreamsConfigurator.config.getConfig("instagram"));
    +    }
    +    public InstagramAbstractProvider(InstagramConfiguration config) {
    +        this.config = SerializationUtil.cloneBySerialization(config);
    +    }
    +    @Override
    +    public void startStream() {
    +        this.dataCollector = getInstagramDataCollector();
    +        this.executorService = Executors.newSingleThreadExecutor();
    +        this.executorService.submit(this.dataCollector);
    +    }
    +    /**
    +     * Return the data collector to use to connect to instagram.
    +     * @return
    +     */
    +    protected abstract InstagramDataCollector getInstagramDataCollector();
    +    @Override
    +    public StreamsResultSet readCurrent() {
    +        Queue<StreamsDatum> batch = Queues.newConcurrentLinkedQueue();
    +        while(!this.dataQueue.isEmpty()) {
    --- End diff --
    since the data queue can continue to be added to, the readCurrent COULD enter a case where
the method does not return until the data stops being inserted into the queue.  I would add
a max batch size that would ensure the method returns.
    Also, you probably only want one thread calling readCurrent at a time.

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 or file a JIRA ticket
with INFRA.

View raw message