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

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

public class Program
extends java.lang.Object

The class that contains the main method

Author:
Ahmad Akra

Nested Class Summary
private static class Program.UserThread
          This represents a thread that is responsible for reading input commands from the user dynamically and changing the behaviour of the program on the fly
input commands include changing how many days should the tweets remain in the DB, adding more swear words and shutting the server down gracefully
 
Field Summary
static IDatabase db
          the interface to the SQL database, which is used to store tweets, analysis and training data
private static java.io.BufferedReader input
          this is used to read any input from the user
private static java.util.Collection<java.lang.String> keywords
          the collection of keywords used to fetch tweets from Twitter
private static NewTweetsHandler newTweetsHandler
          the object that handles the incoming tweets and performs the analysis on them
private static int numberOfDays
          the number of days to leave tweets in the database before the cleanup operation can remove them and their side effects
static java.lang.String OAUTH_KEY
          the OAuth key provided for our project by twitter, it is needed everytime the application calls the twitter API
static java.lang.String OAUTH_SECRET
          the Oauth secret provided for our project by twitter, it is needed everytime the application calls the twitter API
private static OldTweetsHandler oldTweetsHandler
          the object used to clean old tweets from the database
private static java.lang.String searchString
          the search string
static TwitterStreamingAPI streamingAPI
          the thread that listens to the Twitter streaming API and adds incoming tweets to a queue
 
Constructor Summary
Program()
           
 
Method Summary
private static IDatabase createDatabaseObject(java.lang.String[] args)
          creates a database based on the database name, username and password provided by the user on the command line
private static void deployApplication(java.lang.String[] args)
          reads the swear words, the stop words and the training data from a collection of text files that should be provided in the same directory as the jar file of this application
private static boolean doubleCheckFromUser(java.lang.String msg)
          prints the msg to the user (it is expected that the msg is a yes/no question) and gets the answer (Y/N) from the user.
private static java.lang.String getPasswordFromUser()
          asks the user for the database password and when the user types the password, the characters typed are not visible
private static boolean isInteger(java.lang.String str)
          checks if "str" can be parsed into an int
static void main(java.lang.String[] args)
          The main method of the Java server
static void performCleanup()
           
private static void printHelpManual()
          prints a very small help manual to the user
static void reconnectToTwitter()
           
private static void recoverFromCrash()
          flushes all the analysis data in the database and redoes all the analysis
private static void refreshDatabase(java.lang.String[] args)
          drops all client specific data in the database and starts again using the input from the user, the input from the user contains the new search string and the limit number of tweets to fetch
static java.util.Timer scheduleCleanups()
          schedules a timer task that cleans the database from old tweets every day
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OAUTH_KEY

public static final java.lang.String OAUTH_KEY
the OAuth key provided for our project by twitter, it is needed everytime the application calls the twitter API

See Also:
Constant Field Values

OAUTH_SECRET

public static final java.lang.String OAUTH_SECRET
the Oauth secret provided for our project by twitter, it is needed everytime the application calls the twitter API

See Also:
Constant Field Values

db

public static IDatabase db
the interface to the SQL database, which is used to store tweets, analysis and training data


input

private static java.io.BufferedReader input
this is used to read any input from the user


newTweetsHandler

private static NewTweetsHandler newTweetsHandler
the object that handles the incoming tweets and performs the analysis on them


oldTweetsHandler

private static OldTweetsHandler oldTweetsHandler
the object used to clean old tweets from the database


searchString

private static java.lang.String searchString
the search string


numberOfDays

private static int numberOfDays
the number of days to leave tweets in the database before the cleanup operation can remove them and their side effects


streamingAPI

public static TwitterStreamingAPI streamingAPI
the thread that listens to the Twitter streaming API and adds incoming tweets to a queue


keywords

private static java.util.Collection<java.lang.String> keywords
the collection of keywords used to fetch tweets from Twitter

Constructor Detail

Program

public Program()
Method Detail

main

public static void main(java.lang.String[] args)
The main method of the Java server

Parameters:
args - the configurations that are passed by the user in the command line
Throws:
java.lang.Exception

refreshDatabase

private static void refreshDatabase(java.lang.String[] args)
                             throws java.io.IOException
drops all client specific data in the database and starts again using the input from the user, the input from the user contains the new search string and the limit number of tweets to fetch

Parameters:
args - the input array from the user as it is passed to the main method
Throws:
java.io.IOException

recoverFromCrash

private static void recoverFromCrash()
flushes all the analysis data in the database and redoes all the analysis


scheduleCleanups

public static java.util.Timer scheduleCleanups()
schedules a timer task that cleans the database from old tweets every day


performCleanup

public static void performCleanup()

doubleCheckFromUser

private static boolean doubleCheckFromUser(java.lang.String msg)
prints the msg to the user (it is expected that the msg is a yes/no question) and gets the answer (Y/N) from the user.
if user input cannot be read, it returns true by default.

Parameters:
msg - a yes/no question to the user
Returns:
true if the user answer is Y (or user input cannot be read) and false if the user answer is N

createDatabaseObject

private static IDatabase createDatabaseObject(java.lang.String[] args)
                                       throws java.io.IOException
creates a database based on the database name, username and password provided by the user on the command line

Parameters:
args - all the command line arguments
Returns:
the password string
Throws:
java.io.IOException - if the password cannot be read from the user
java.sql.SQLException - is the connection to the SQL cannot be made
java.lang.ClassNotFoundException - if the SQL driver cannot be loaded

deployApplication

private static void deployApplication(java.lang.String[] args)
                               throws java.io.IOException
reads the swear words, the stop words and the training data from a collection of text files that should be provided in the same directory as the jar file of this application

Throws:
java.io.IOException - if it is unable to find the files or another reason

getPasswordFromUser

private static java.lang.String getPasswordFromUser()
                                             throws java.io.IOException
asks the user for the database password and when the user types the password, the characters typed are not visible

Returns:
the password entered by the user
Throws:
java.io.IOException - if user input cannot be read

isInteger

private static boolean isInteger(java.lang.String str)
checks if "str" can be parsed into an int

Parameters:
str - the string to check
Returns:
true if "str" can be parsed and false otherwise

printHelpManual

private static void printHelpManual()
prints a very small help manual to the user


reconnectToTwitter

public static void reconnectToTwitter()