|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.ObjectstockDataRetrieval.DownloadManager
Manages the downloading of stock/comapny information from a specific set of web pages and the downloading of stock history files from Yahoo's web servers.
The manager downloads all stocks from NYSE, AMEX, and NASDAQ and saves them to a directory structure created in the local file system. In order to download the thousands of individual stock history files, the manager spawns threads and keeps, at most, a constant number of threads open at once to optimize the network delay problem.
| Nested Class Summary | |
private class |
DownloadManager.DownloaderThread
Threaded class to download the webpages in a threaded manner instead of in a sequential manner. |
| Field Summary | |
private static int |
completedThreads
the number of completed threads |
private java.lang.Object |
lock
a lock object to synchronize threads |
private java.lang.String |
market
the market to which the list of tickers belongs |
private int |
MAX_CONNECTIONS
the maximum number of HTTP connections allowed to be open at once |
private static int |
numThreads
the number of currently active threads |
private java.util.Vector |
threadVector
a collection of threads that are waiting their turn to execute |
private java.lang.String |
tickerFile
the file to which to save the list of tickers to |
private static java.lang.String |
YAHOO_DefaultDownloadPage
direct link to yahoo's page to download a stock's .csv file with date and ticker information removed and replaced with easy to find identifiers |
private static java.lang.String |
YAHOO_DownloadPage
yahoo's URL with date and ticker information removed and replaced with easy to find identifyers |
| Constructor Summary | |
DownloadManager(int maxConnections,
java.lang.String tickerFile,
java.lang.String market)
Constructor allows user to specify the maximum number of parallel connections to be active and downloading from the internet at one time. |
|
| Method Summary | |
private java.lang.String |
addCurrentDate(java.lang.String oldString,
java.lang.String newString)
Inserts the current date into the download URL so that when fetching the history files, the correct date range is used |
private java.lang.String |
constructTickerURL(java.lang.String ticker)
Constructs a URL with the ticker symbol passed suitable for downloading stock information from finance.yahoo.com. |
boolean |
createDirectory(java.lang.String directory)
Create the directory given as a parameter |
void |
createDirectoryStructure()
Creates all the directories and files necessary to store information from the web pages containing ticker information |
private int |
getCounter()
Gets the current number of threads running. |
void |
getNewsStories()
Fetch all news stories for every ticker in the current market |
void |
getStockHistoryFiles()
Retrieves files containing all historical information about a stock and stores it to a local directory. |
abstract void |
getStockTickers()
Compiles a list of all stock ticker symbols from the given market. |
void |
getTickerAndCompany(java.lang.String targetURL,
java.lang.String embeddedTickerCode)
Series of commands to download the web page specified, parse it for relevant information, and write the extracted data to a file. |
private void |
incrementCounter()
Called when a thread starts to increment the counter of the number of current threads running. |
static void |
main(java.lang.String[] args)
|
private void |
threadFinished()
Called when a thread finishes. |
void |
writeDataToFile(java.util.ArrayList data)
Write all data gathered from the web page containing ticker/company information to the file "./Data/tickers.txt". |
private void |
writeHistoryFile(java.lang.String data,
java.lang.String ticker)
Function writes downloaded stock ticker data to a file in a specific folder and names the files "'ticker'_'market'.txt". |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
private static java.lang.String YAHOO_DownloadPage
private static java.lang.String YAHOO_DefaultDownloadPage
private java.lang.String tickerFile
private java.lang.String market
private int MAX_CONNECTIONS
private static int numThreads
private static int completedThreads
private java.lang.Object lock
private java.util.Vector threadVector
| Constructor Detail |
public DownloadManager(int maxConnections,
java.lang.String tickerFile,
java.lang.String market)
maxConnections - the maximum number of files to download in parallel. If
a number < 1 is given, the default is 50.| Method Detail |
private java.lang.String addCurrentDate(java.lang.String oldString,
java.lang.String newString)
oldString - the original portion of the URL to replacenewString - the replacement of the date portion of the URL
public void createDirectoryStructure()
public boolean createDirectory(java.lang.String directory)
directory - the directory path to create
public abstract void getStockTickers()
Delegates responsibility to functions to go to a specific website and repeatedly hit and parse pages containing company name and ticker symbols.
public void getNewsStories()
public void getTickerAndCompany(java.lang.String targetURL,
java.lang.String embeddedTickerCode)
targetURL - the target URL for which to download all ticker/company names fromembeddedTickerCode - the pattern of the HTML that contains an individual ticker namepublic void writeDataToFile(java.util.ArrayList data)
data - an ArrayList containing entries of Ticker/CompanyName
information in a String array of size [2]public void getStockHistoryFiles()
private java.lang.String constructTickerURL(java.lang.String ticker)
ticker - the ticker symbol to be embedded into the initial link
private void writeHistoryFile(java.lang.String data,
java.lang.String ticker)
data - the historical data file downloaded from YAHOOticker - the ticker symbol used to determine the file name to saveprivate int getCounter()
private void incrementCounter()
private void threadFinished()
Accesses a Vector of threads that have not yet begun, picks the first thread from the Vector, removes it from the Vector and tells it to start.
Updates the number of current threads running counter as well as the counter tracking the number of successfully completed threads.
public static void main(java.lang.String[] args)
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||