package cse308.swift.server.quotepoller; import java.util.ArrayList; import org.apache.log4j.Logger; import cse308.swift.server.database.SwiftTradingDBUtils; import cse308.swift.shared.beans.Quote; /** * QuotePollerThread - This class is a thread that simply runs for a given * interval polling the data collected by Yahoo! Financial Services. * @author Ray * */ public class QuotePollerThread implements Runnable { /** * Log4j Object */ static Logger logger = Logger.getLogger(QuotePollerThread.class.getName()); /** * Instance of Polling Thread */ Thread runner; /** * Instance of Database Helper Object */ protected SwiftTradingDBUtils dbUtils; /** * Constructor For the Polling Thread * @param threadName The Standard Thread Name for Runnable threads * @param dbUtils The instance of the Database Utilities Object for Entering the Quote Data * into the database */ public QuotePollerThread(String threadName, SwiftTradingDBUtils dbUtils) { this.dbUtils = dbUtils; runner = new Thread(this, threadName); logger.info("Starting the Yahoo! Poller Thread"); runner.start(); } /** * Run Method: Polls Data from Yahoo! and Enters the Data Into the Database */ public void run() { while(true) { logger.info("Polling Data From Yahoo!"); YahooStockEngine engine = new YahooStockEngine(); //ArrayList quotes = engine.fetch(); ArrayList quotes = engine.fetchQuotes("AA","AAV","ABBC"); logger.info("Data Retrieved from Yahoo!"); logger.info("Entering Data Into Database"); // Call to QuotePollerDBUtils Object to Insert Data into Database try { logger.info("Sleeping for 60 Seconds"); Thread.sleep(60000); } catch(InterruptedException ie) {} } } }