uk.ac.cam.juliet.twitter.main
Class TwitterStreamingAPI

java.lang.Object
  extended by uk.ac.cam.juliet.twitter.main.TwitterStreamingAPI

public class TwitterStreamingAPI
extends java.lang.Object

represents a thread in the middle

Author:
Ahmad Akra

Nested Class Summary
private  class TwitterStreamingAPI.StreamHandler
          the class that handles every tweet returned from the twitter Search API, not storing or analysing, but simply adding it to a queue
 
Field Summary
private  java.util.Collection<java.lang.String> keywords
          the keywords to filter the tweet stream
private  com.crepezzi.tweetstream4j.TwitterStream stream
          represnts the runnable object that will call the Twitter streaming API
private  java.util.concurrent.BlockingQueue<Tweet> tweetQueue
          where the stream of tweets should be queued for analysis
private  com.crepezzi.tweetstream4j.TwitterStreamConfiguration tws
          the stream configurations to use when connecting
 
Constructor Summary
TwitterStreamingAPI(java.util.concurrent.BlockingQueue<Tweet> queue, java.util.Collection<java.lang.String> keywords, IDatabase db)
          constructor of the class
 
Method Summary
private  java.lang.String authenticateManually(java.lang.String url)
          asks the user to authenticate the application with the OAuth ptotocol required by the twitter API
 void callStream()
          starts waiting for new tweets from Twitter streaming API
Note: shoud be invoked only once at a time, otherwise behaviour is undefined
 void shutDown()
          the opposite of callStream() stops waiting for new tweets from Twitter streaming API and terminates the connection
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tweetQueue

private java.util.concurrent.BlockingQueue<Tweet> tweetQueue
where the stream of tweets should be queued for analysis


stream

private com.crepezzi.tweetstream4j.TwitterStream stream
represnts the runnable object that will call the Twitter streaming API


keywords

private java.util.Collection<java.lang.String> keywords
the keywords to filter the tweet stream


tws

private com.crepezzi.tweetstream4j.TwitterStreamConfiguration tws
the stream configurations to use when connecting

Constructor Detail

TwitterStreamingAPI

public TwitterStreamingAPI(java.util.concurrent.BlockingQueue<Tweet> queue,
                           java.util.Collection<java.lang.String> keywords,
                           IDatabase db)
constructor of the class

Parameters:
queue - the queue to which the API should add any new tweets
keywords - the stream of tweets should be filtered based on this collection of key words
Method Detail

authenticateManually

private java.lang.String authenticateManually(java.lang.String url)
                                       throws java.io.IOException
asks the user to authenticate the application with the OAuth ptotocol required by the twitter API

Parameters:
url - the url to visit for authentication
Returns:
the pin from the user
Throws:
java.io.IOException - if the pin cannot be read from user

callStream

public void callStream()
starts waiting for new tweets from Twitter streaming API
Note: shoud be invoked only once at a time, otherwise behaviour is undefined


shutDown

public void shutDown()
the opposite of callStream() stops waiting for new tweets from Twitter streaming API and terminates the connection