edu.berkeley.guir.ptk.input
Class StockInput

java.lang.Object
  extended byedu.berkeley.guir.ptk.PTK
      extended byedu.berkeley.guir.ptk.input.InputSource
          extended byedu.berkeley.guir.ptk.input.StockInput
All Implemented Interfaces:
java.lang.Runnable

public class StockInput
extends InputSource

Uses the StockParser class to get stock quotes from quotes.nasdaq.com and * dispatches all the quotes in one event to the PTK Server. Extends the class * InputSource and implements newInput() (an inherited, abstract method). This * method is responsible for calling the utility class, StockParser, to get the * actual input data from the NASDAQ Web page. *

* This class sets the inherited Metadata mds field in the main * function where the Stocks instance is created. It is necessary to set the metadata * because this is what identifies the events this input creates to outputs and to * the PTK server. Outputs that want stock input would subscribe to same metadata * that is added to the event in the newInput method, here. Metadata is added * using a Metadata object, which includes the ID of the metadata (which type * of metadata it is) and the value of the metadata (the value that separates it * from other events. Multiple events can have Metadatas with the same * ID, but if it is important to tell them apart, their values should be different. * For this stock input, the only Metadata in the event is the * EVENT_TYPE_ID (the metadata ID), which is set to StockConstants.STOCK * (the metadata value). All event should have a EVENT_TYPE_ID. *

* To start the input, run this class as a Java application. The main class * creates a new Stocks input and calls getThenSendInputData() to get new input * and dispatch it to the PTK server. This method is called in a loop, with a * waiting period between each call where the process sleeps. The sleeping time is * specified by the constant PTKConstants.TIME_BETWEEN_EVENTS.


Field Summary
static java.lang.String MY_ID
          The unique ID String for this input, found in StockConstants, which is an application specific class.
 
Fields inherited from class edu.berkeley.guir.ptk.input.InputSource
history, mds, my_id, my_ip, time_between_events
 
Fields inherited from class edu.berkeley.guir.ptk.PTK
debug, MAX_DEBUG, MED_DEBUG, MIN_DEBUG, NO_DEBUG
 
Constructor Summary
StockInput()
          Constructor for non-distributed applications.
StockInput(java.lang.String my_ip)
          Constructor for distributed applications.
 
Method Summary
static void main(java.lang.String[] argsv)
          This main method allows the input to run, continually getting new input and * dispatching the data in events to the PTK server.
 Events newInput()
          Gets stock quote input from the data source, quotes.nasdaq.com, and fills an * Events with the stock quote strings.
 
Methods inherited from class edu.berkeley.guir.ptk.input.InputSource
addMetadata, addMetadataItem, addMyMetadataToEvent, dispatchEvent, finalize, getAbstractThenSendInputEvent, getMetadata, getMetadataItemsAsArray, getThenSendInputEvent, register, run, setMetadata, setTimeBetweenEvents, startInput
 
Methods inherited from class edu.berkeley.guir.ptk.PTK
getMAX, getMED, getMIN, getNO, printDebug, printDebug, printError
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MY_ID

public static final java.lang.String MY_ID
The unique ID String for this input, found in StockConstants, which is an application specific class. The ID must be unique per PTK server instance.

See Also:
Constant Field Values
Constructor Detail

StockInput

public StockInput()
Constructor for non-distributed applications. An input that uses this constructor cannot be part of an application on another machine.


StockInput

public StockInput(java.lang.String my_ip)
Constructor for distributed applications. An input that uses this constructor can send input events to a remote application. * @param my_ip

Method Detail

newInput

public Events newInput()
Gets stock quote input from the data source, quotes.nasdaq.com, and fills an * Events with the stock quote strings. The Events is returned when it has * one quote for each symbol specified in StockConstants.ALL_COMPANY_SYMBOLS. * This event is what will be dispatched to the PTK server and eventually * sent to outputs that subscribe to its metadata. Uses the StockParser class * to parse the NASDAQ Web page. * @return Events an Events object that contains a single Event with the stock quotes. * There is one DataNumber object created containing * a quote value for each symbol specified in * StockConstants.ALL_COMPANY_SYMBOLS. These DataNumbers * are then added to the event. * Each DataNumber is given an ID, which is the stock * symbol associated with the quote. from the array * StockConstants.ALL_IDS, which is an array of news * headline IDs indexed by the number of the headline * (i.e., the first headline is in the first position * of the array, etc.).

Specified by:
newInput in class InputSource

main

public static void main(java.lang.String[] argsv)
This main method allows the input to run, continually getting new input and * dispatching the data in events to the PTK server.