stockDataRetrieval
Class NewsDownloaderThread

java.lang.Object
  extended byjava.lang.Thread
      extended bystockDataRetrieval.NewsDownloaderThread
All Implemented Interfaces:
java.lang.Runnable

public class NewsDownloaderThread
extends java.lang.Thread

Threaded class to allow the aynchronous downloading of news stories pertaining to a single company.


Nested Class Summary
private  class NewsDownloaderThread.NotifyThread
          Class to handle the notification of the owner class that the NewsDownloaderThread has completed.
 
Field Summary
private  java.lang.Object registeredOwner
          the object who spawned this thread, used to notify that owner when the thread completes
private  java.lang.String ticker
          the ticker name which the current thread is responsible for for downloading news stories for
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
NewsDownloaderThread(java.lang.String ticker, java.lang.Object registeredOwner)
          Constructor to initialize tell the thread its target
 
Method Summary
private  java.util.ArrayList addFetchedStories(java.util.ArrayList oldStories, java.util.ArrayList newStories)
          Add the fetched stories to the growing stories array
 java.lang.String getTicker()
          Gets the ticker name this thread is downloading
private  void notifyOwner()
          Spawn a thread that now has the responsibility of notifying the owner of the thread.
 void run()
           
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ticker

private java.lang.String ticker
the ticker name which the current thread is responsible for for downloading news stories for


registeredOwner

private java.lang.Object registeredOwner
the object who spawned this thread, used to notify that owner when the thread completes

Constructor Detail

NewsDownloaderThread

public NewsDownloaderThread(java.lang.String ticker,
                            java.lang.Object registeredOwner)
Constructor to initialize tell the thread its target

Parameters:
ticker - The target company the thread is to download
registeredOwner - The owner of this object who requires notification when the thread completes. The owner can be null, in which case no notifications are sent when the thread completes
Method Detail

getTicker

public java.lang.String getTicker()
Gets the ticker name this thread is downloading

Returns:
The ticker this thread is downloading stories for

addFetchedStories

private java.util.ArrayList addFetchedStories(java.util.ArrayList oldStories,
                                              java.util.ArrayList newStories)
Add the fetched stories to the growing stories array

Parameters:
oldStories - the old list of stories on which to append newStories
newStories - the stories list gathered from a single page
Returns:
a list with the new stories appended onto the old stories list

run

public void run()

notifyOwner

private void notifyOwner()
Spawn a thread that now has the responsibility of notifying the owner of the thread.

This prevents the thread from waiting unnecessarily queuing on the owner's synchronized notify function.