stockDataRetrieval
Class NewsDownloader

java.lang.Object
  extended bystockDataRetrieval.NewsDownloader

public class NewsDownloader
extends java.lang.Object

Singleton class that controls the downloading of the news stories for all stocks.

The object is triggered to activate a new thread or store it for later when a new ticker is added or when a previously spawned thread completes.


Field Summary
private  int MAX_NUM_THREADS
          the max number of news downloading threads allowed
private  java.util.Vector newsThreads
          a collection of threads that are waiting their turn to execute
private static int numActiveThreads
          the nubmer of currently active threads
private static int numCompletedThreads
          the number of completed threads
private static NewsDownloader theInstance
          the instance of the NewsDownloader
 
Constructor Summary
private NewsDownloader()
          Configure the downloader with a set max number of simultaneous threads
 
Method Summary
 void addTicker(java.lang.String newTicker)
          Add a new ticker for which to fetch a news story for
static NewsDownloader getInstance()
          Return the instance of the singleton object
 void getStockNews(java.lang.String tickerFile)
          Retrieves files containing all news stories about a stock and stores it to a local directory.
private  void handleNotify()
          Whenever a new ticker name is added, this function enables the class to analyze the state of active threads and activate new threads or wait
 void notifyMe()
          When a thread previously spawned completes, the thread notifies the singleton via this method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

theInstance

private static NewsDownloader theInstance
the instance of the NewsDownloader


MAX_NUM_THREADS

private int MAX_NUM_THREADS
the max number of news downloading threads allowed


newsThreads

private java.util.Vector newsThreads
a collection of threads that are waiting their turn to execute


numActiveThreads

private static int numActiveThreads
the nubmer of currently active threads


numCompletedThreads

private static int numCompletedThreads
the number of completed threads

Constructor Detail

NewsDownloader

private NewsDownloader()
Configure the downloader with a set max number of simultaneous threads

Method Detail

getInstance

public static NewsDownloader getInstance()
Return the instance of the singleton object

Returns:
The instance of the singleton NewsDonwloader

addTicker

public void addTicker(java.lang.String newTicker)
Add a new ticker for which to fetch a news story for

Parameters:
newTicker - The ticker for which to add to the list tickers to get news stories for

handleNotify

private void handleNotify()
Whenever a new ticker name is added, this function enables the class to analyze the state of active threads and activate new threads or wait


notifyMe

public void notifyMe()
When a thread previously spawned completes, the thread notifies the singleton via this method.

The function calls code to determine if a new thread should be spawned.


getStockNews

public void getStockNews(java.lang.String tickerFile)
Retrieves files containing all news stories about a stock and stores it to a local directory.

Parameters:
tickerFile - The name of the file containing all the ticker - company tuples which serves as the list of tickers to get the news for