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

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

public class NewTweetsHandler
extends java.lang.Object

a class that handles new tweets from the twitter API, the important methods are process(BlockingQueue) and all its overloads

Author:
Ahmad Akra

Field Summary
(package private)  BayesClassifier classifier
          the sentiment classifier
(package private)  FrequencyCounter counter
          the frequency counter
(package private)  IDatabase db
          the database that is used to store the analysis
(package private)  ProfanityFilter filter
          the swear filter
private  long lastCleanupTime
          time when the last cleanup operation was performed expressed as a long integer
private  boolean shutdown
          determines when to stop processing operations in process(BlockingQueue)
private  java.util.concurrent.BlockingQueue<Tweet> tweetQueue
          the queue of tweets to process when process(BlockingQueue) is called
 
Constructor Summary
NewTweetsHandler(IDatabase db)
          class constructor
 
Method Summary
 void analyse(Tweet tweet)
          calculates the statistics and analysis of this tweet and stores that in the database
types of analysis performed: NSFW, sentiment score and word count.
 ProfanityFilter getSwearFilter()
          gets the swear filter currently used by this NewTweetsHandler
private  boolean passedSinceLastCleanup(long period)
          finds out if the last cleanup operation occurred more than a period milliseconds ago by comparing to a stored value
 void process(java.util.concurrent.BlockingQueue<Tweet> tweetQueue)
          analyses and stores all the tweets in the provided queue if the queue is empty it waits until more tweets are added to it
Warning: this call blocks forever
 void process(java.util.List<Tweet> tweets)
          analyses and stores all tweets in the provided list
 void process(Tweet tweet)
          analyses and stores a single tweet
 void shutDown()
          if the handler is waiting for more tweets on the queue, it cancels, and returns when this method is called
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

db

IDatabase db
the database that is used to store the analysis


filter

ProfanityFilter filter
the swear filter


classifier

BayesClassifier classifier
the sentiment classifier


counter

FrequencyCounter counter
the frequency counter


shutdown

private boolean shutdown
determines when to stop processing operations in process(BlockingQueue)


tweetQueue

private java.util.concurrent.BlockingQueue<Tweet> tweetQueue
the queue of tweets to process when process(BlockingQueue) is called


lastCleanupTime

private long lastCleanupTime
time when the last cleanup operation was performed expressed as a long integer

Constructor Detail

NewTweetsHandler

public NewTweetsHandler(IDatabase db)
class constructor

Parameters:
db - the database that is used to store the analysis
Method Detail

process

public void process(java.util.List<Tweet> tweets)
analyses and stores all tweets in the provided list

Parameters:
tweets - the list of tweets to be analysed and stored

process

public void process(java.util.concurrent.BlockingQueue<Tweet> tweetQueue)
analyses and stores all the tweets in the provided queue if the queue is empty it waits until more tweets are added to it
Warning: this call blocks forever

Parameters:
tweetQueue - the queue of tweets to process

passedSinceLastCleanup

private boolean passedSinceLastCleanup(long period)
finds out if the last cleanup operation occurred more than a period milliseconds ago by comparing to a stored value

Parameters:
period - find out if the last cleanup occured more then this period ago
Returns:
true if the last cleanup occured more than a period ago and false otherwise

process

public void process(Tweet tweet)
analyses and stores a single tweet

Parameters:
tweet - the tweets to analyse and store

analyse

public void analyse(Tweet tweet)
calculates the statistics and analysis of this tweet and stores that in the database
types of analysis performed: NSFW, sentiment score and word count.

Parameters:
tweet - the tweet for which to store the analysis and statistics

getSwearFilter

public ProfanityFilter getSwearFilter()
gets the swear filter currently used by this NewTweetsHandler

Returns:
the swear filter currently used by this NewTweetsHandler

shutDown

public void shutDown()
if the handler is waiting for more tweets on the queue, it cancels, and returns when this method is called