edu.sdsc.inca.consumer
Class DepotQuery

java.lang.Object
  extended by java.util.TimerTask
      extended by edu.sdsc.inca.consumer.DepotQuery
All Implemented Interfaces:
java.lang.Runnable

public class DepotQuery
extends java.util.TimerTask

Handles the prefetching and caching of HQL queries to the depot. The HQL queries allow users to request customized data from the depot. In the event that a query takes a long time to load, this class can be used to continuously query results from the depot and store them. The advantage of this is that whenever requests are made on the consumer for the data, the latest cached data can be returned immediately rather than waiting for the lengthy query to complete. Furthermore, it will reduce the load on the consumer and depot. If a cached query has parameters, it is a template for cached queries (e.g., get latest suite results for suite X)

Author:
Shava Smallen <ssmallen@sdsc.edu>

Field Summary
static java.lang.String QUERYDIR
           
 
Constructor Summary
DepotQuery(int period, java.lang.String reloadAt, java.lang.String tempDir, java.lang.String name, java.lang.String command, java.lang.Object... params)
          Create a new cache query thread for the specified query.
 
Method Summary
 java.io.File getCacheFile()
          Return the handle of the file used to store the query result.
 java.lang.String getCommand()
          Return the depot command being used to fetch data from the depot.
static java.util.Properties getDepotConfig()
          Get the configuration for connecting to the depot.
 java.lang.String getFreshResult()
          Query the depot and return the results (rows) as an XmlBean
 long getNextRefresh()
          Check the age of the cached file and return the number of milliseconds before it should be refreshed again.
 java.lang.Object[] getParams()
          Return the depot command params being used to fetch data from the depot.
 int getPeriod()
          Returns the frequency of queries to the depot.
 java.lang.String getQueryName()
          Returns the name of the query.
 java.lang.String getReloadAt()
          Set the reload start time.
 java.lang.String getStoredResult()
          Returns the latest result of the query stored in the file cache.
 java.lang.String query()
          Send a query to the depot.
static java.lang.String query(java.lang.String command, java.lang.Object... params)
          Send a query to the depot.
 void refresh()
          Query the depot for a new result and store it in the cache
 void run()
          Will first check to see if there is a result already stored on disk and if so, will check to see how fresh it is.
 void setCommand(java.lang.String command)
          Set the depot query command being used to fetch data from the depot.
static void setDepotConfig(java.util.Properties depotConfig)
          Set the configuration for connecting to the depot.
 void setParams(java.lang.Object[] params)
          Set the depot query command parameters being used to fetch data from the depot.
 void setPeriod(int period)
          Set the frequency of queries to the depot.
 void setQueryName(java.lang.String name)
          Set the name of the query.
 void setReloadAt(java.lang.String reloadAt)
          Set the reload start time
 java.lang.String toString()
          Return the query information as a string
 
Methods inherited from class java.util.TimerTask
cancel, scheduledExecutionTime
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

QUERYDIR

public static final java.lang.String QUERYDIR
See Also:
Constant Field Values
Constructor Detail

DepotQuery

public DepotQuery(int period,
                  java.lang.String reloadAt,
                  java.lang.String tempDir,
                  java.lang.String name,
                  java.lang.String command,
                  java.lang.Object... params)
Create a new cache query thread for the specified query.

Parameters:
period - The frequency of which the consumer should prefetch the query
reloadAt - Should be "*" if we don't care about the time the query is started otherwise should be WW:HH:MM.
tempDir - A temporary directory where queries can be cached
name - The name of the query (may contain whitespace)
command - The depot query command
params - The parameters for the query command
Method Detail

getCacheFile

public java.io.File getCacheFile()
Return the handle of the file used to store the query result.

Returns:
The file handle to the query result.

getCommand

public java.lang.String getCommand()
Return the depot command being used to fetch data from the depot.

Returns:
A string containing a depot command.

getDepotConfig

public static java.util.Properties getDepotConfig()
Get the configuration for connecting to the depot.

Returns:
A properties list containing config parameters for connecting to the depot.

getNextRefresh

public long getNextRefresh()
Check the age of the cached file and return the number of milliseconds before it should be refreshed again.

Returns:
Number of milliseconds before next refresh

getParams

public java.lang.Object[] getParams()
Return the depot command params being used to fetch data from the depot.

Returns:
A string array containing depot command parameters.

getPeriod

public int getPeriod()
Returns the frequency of queries to the depot.

Returns:
The number of seconds used to wait before querying the depot again.

getQueryName

public java.lang.String getQueryName()
Returns the name of the query.

Returns:
A string containing the name of the HQL query.

getReloadAt

public java.lang.String getReloadAt()
Set the reload start time.

Returns:
Should be "*" if we don't care about the time the query is started otherwise should be WW:HH:MM.

getStoredResult

public java.lang.String getStoredResult()
Returns the latest result of the query stored in the file cache. Does a synchronized read of the data from file and returns it.

Returns:
An XML document containing the results of the query or null if nothing has been cached yet or there are problems reading the file from disk.

getFreshResult

public java.lang.String getFreshResult()
                                throws edu.sdsc.inca.ConfigurationException,
                                       java.io.IOException,
                                       edu.sdsc.inca.protocol.ProtocolException
Query the depot and return the results (rows) as an XmlBean

Returns:
An XmlBean containing the query results.
Throws:
edu.sdsc.inca.ConfigurationException - if complete or incorrect depot parameters
java.io.IOException - if trouble connecting to depot
edu.sdsc.inca.protocol.ProtocolException - if trouble talking to depot

query

public java.lang.String query()
                       throws edu.sdsc.inca.ConfigurationException,
                              java.io.IOException
Send a query to the depot.

Returns:
An XML document complying to the queryResults schema
Throws:
edu.sdsc.inca.ConfigurationException - if problem with depot contact info
java.io.IOException - iif trouble connecting to depot

query

public static java.lang.String query(java.lang.String command,
                                     java.lang.Object... params)
                              throws edu.sdsc.inca.ConfigurationException,
                                     java.io.IOException
Send a query to the depot.

Parameters:
command - The query command to call on the depot client (e.g., querySuite, queryHql, etc.)
params - The parameters for the query command
Returns:
An XML document complying to the queryResults schema
Throws:
edu.sdsc.inca.ConfigurationException - if problem with depot contact info
java.io.IOException - iif trouble connecting to depot

run

public void run()
Will first check to see if there is a result already stored on disk and if so, will check to see how fresh it is. If the result is younger than the refreshSuiteCaching period, we will wait until it has expired before querying the depot. Once the first query is made, this thread will continously query until it receives an interrupt.

Specified by:
run in interface java.lang.Runnable
Specified by:
run in class java.util.TimerTask

refresh

public void refresh()
             throws edu.sdsc.inca.ConfigurationException,
                    java.io.IOException,
                    edu.sdsc.inca.protocol.ProtocolException
Query the depot for a new result and store it in the cache

Throws:
edu.sdsc.inca.ConfigurationException - if unable to read depot config params
java.io.IOException - if unable to contact depot
edu.sdsc.inca.protocol.ProtocolException - if trouble talking to depot

setCommand

public void setCommand(java.lang.String command)
Set the depot query command being used to fetch data from the depot.

Parameters:
command - A string containing a depot query command

setDepotConfig

public static void setDepotConfig(java.util.Properties depotConfig)
Set the configuration for connecting to the depot.

Parameters:
depotConfig - A properties list containing config parameters for connecting to the depot.

setParams

public void setParams(java.lang.Object[] params)
Set the depot query command parameters being used to fetch data from the depot.

Parameters:
params - A string array containing parameters for a depot query command

setPeriod

public void setPeriod(int period)
Set the frequency of queries to the depot.

Parameters:
period - Set the number of seconds used to wait before querying the depot again.

setQueryName

public void setQueryName(java.lang.String name)
Set the name of the query.

Parameters:
name - A string containing the name of the HQL query.

setReloadAt

public void setReloadAt(java.lang.String reloadAt)
Set the reload start time

Parameters:
reloadAt - Should be "*" if we don't care about the time the query is started otherwise should be WW:HH:MM.

toString

public java.lang.String toString()
Return the query information as a string

Overrides:
toString in class java.lang.Object
Returns:
A string representation of the query