/**
 * 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
 * with the License.  You may obtain a copy of the License at
 *
 * 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 storm.starter.spout;

import backtype.storm.Config;
import twitter4j.conf.ConfigurationBuilder;
import twitter4j.TwitterStream;
import twitter4j.TwitterStreamFactory;
import backtype.storm.spout.SpoutOutputCollector;
import backtype.storm.task.TopologyContext;
import backtype.storm.topology.OutputFieldsDeclarer;
import backtype.storm.topology.base.BaseRichSpout;
import backtype.storm.tuple.Fields;
import backtype.storm.tuple.Values;
import backtype.storm.utils.Utils;
import java.util.Map;
import java.util.concurrent.LinkedBlockingQueue;
import twitter4j.Status;
import twitter4j.StatusDeletionNotice;
import twitter4j.StatusListener;

public class TwitterSampleSpout extends BaseRichSpout {
    SpoutOutputCollector _collector;
    LinkedBlockingQueue<Status> queue = null;
    TwitterStream _twitterStream;
    String _username;
    String _pwd;
    
    
    public TwitterSampleSpout(String username, String pwd) {
        _username = username;
        _pwd = pwd;
    }
    
    @Override
    public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
        queue = new LinkedBlockingQueue<Status>(1000);
        _collector = collector;
        StatusListener listener = new StatusListener() {

            @Override
            public void onStatus(Status status) {
                queue.offer(status);
            }

            @Override
            public void onDeletionNotice(StatusDeletionNotice sdn) {
            }

            @Override
            public void onTrackLimitationNotice(int i) {
            }

            @Override
            public void onScrubGeo(long l, long l1) {
            }

            @Override
            public void onException(Exception e) {
            }
            
        };
        TwitterStreamFactory fact = new TwitterStreamFactory(new ConfigurationBuilder().setUser(_username).setPassword(_pwd).build());
        _twitterStream = fact.getInstance();
        _twitterStream.addListener(listener);
        _twitterStream.sample();
    }

    @Override
    public void nextTuple() {
        Status ret = queue.poll();
        if(ret==null) {
            Utils.sleep(50);
        } else {
            _collector.emit(new Values(ret));
        }
    }

    @Override
    public void close() {
        _twitterStream.shutdown();
    }

    @Override
    public Map<String, Object> getComponentConfiguration() {
        Config ret = new Config();
        ret.setMaxTaskParallelism(1);
        return ret;
    }    

    @Override
    public void ack(Object id) {
    }

    @Override
    public void fail(Object id) {
    }

    @Override
    public void declareOutputFields(OutputFieldsDeclarer declarer) {
        declarer.declare(new Fields("tweet"));
    }
    
}
*/
@@ -799,11 +799,8 @@
 %0A */
-%0A/*
 %0A%0Apa
@@ -1444,16 +1444,112 @@
 istener;
+%0Aimport twitter4j.FilterQuery;%0Aimport twitter4j.StallWarning;%0Aimport twitter4j.auth.AccessToken;
 %0A%0Apublic
@@ -1726,25 +1726,108 @@
  String 
-_username
+consumerKey;%0A    String consumerSecret;%0A    String accessToken;%0A    String accessTokenSecret
 ;%0A    St
@@ -1830,21 +1830,27 @@
   String
- _pwd
+%5B%5D keyWords
 ;%0A    %0A 
@@ -1894,80 +1894,350 @@
 ing 
-username, String pwd) %7B%0A        _username = username;%0A        _pwd = pwd
+consumerKey, String consumerSecret,%0A                    String accessToken, String accessTokenSecret, String%5B%5D keyWords) %7B%0A        %0A        this.consumerKey = consumerKey;%0A        this.consumerSecret = consumerSecret;%0A        this.accessToken = accessToken;%0A        this.accessTokenSecret = accessTokenSecret;%0A        this.keyWords = keyWords
 ;%0A  
@@ -3020,16 +3020,25 @@
      %7D;%0A
+        %0A
         
@@ -3054,20 +3054,22 @@
 ream
-Factory fact
+ twitterStream
  = n
@@ -3092,16 +3092,21 @@
 Factory(
+%0A%09%09%09%09
 new Conf
@@ -3131,94 +3131,261 @@
 .set
-User(_username).setPassword(_pwd).build());%0A        _twitterStream = fact.getInstance(
+JSONStoreEnabled(true).build())%0A%09%09%09%09.getInstance();%0A         %0A         twitterStream.addListener(listener);%0A         twitterStream.setOAuthConsumer(consumerKey, consumerSecret);%0A         AccessToken token = new AccessToken(accessToken, accessTokenSecret
 );%0A 
@@ -3383,33 +3383,33 @@
 ecret);%0A        
-_
+ 
 twitterStream.ad
@@ -3406,36 +3406,220 @@
 rStream.
-addListener(listener
+setOAuthAccessToken(token);%0A         %0A         if (keyWords.length == 0) %7B%0A             twitterStream.sample();%0A         %7D%0A         else %7B%0A             FilterQuery query = new FilterQuery().track(keyWords
 );%0A     
@@ -3613,33 +3613,37 @@
 Words);%0A        
-_
+     
 twitterStream.sa
@@ -3636,33 +3636,49 @@
 itterStream.
-sample();
+filter(query);%0A         %7D
 %0A    %7D%0A%0A    
@@ -4398,10 +4398,8 @@
 %0A    %0A%7D%0A
-*/

Change Twitter authentication