edu.sdsc.inca.consumer
Class DepotBean

java.lang.Object
  extended by java.lang.Thread
      extended by edu.sdsc.inca.consumer.DepotBean
All Implemented Interfaces:
java.lang.Runnable

public class DepotBean
extends java.lang.Thread

Manages a list of stored (persistent) depot queries, some of which are longer queries that are cached to disk so that results can be prefetched.

Author:
Shava Smallen <ssmallen@sdsc.edu>

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
static java.lang.String queryStatus
           
static java.lang.String QUERYSTORE
           
static java.lang.String suiteCachePrefix
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
DepotBean()
           
DepotBean(java.lang.String filePath, java.lang.String queryDir)
          Read in or create a new list of stored queries from the provided file.
 
Method Summary
 boolean add(int cachePeriod, java.lang.String reloadAt, java.lang.String name, java.lang.String type, java.lang.String... params)
          Add a query to the query store.
 boolean add(java.lang.String name, java.lang.String type, java.lang.String... params)
          Add a query to the query store.
 void clear()
          Create a new XML file for persisting stored queries and save it to disk.
 edu.sdsc.inca.dataModel.queryStore.Query createQuery(int cachePeriod, java.lang.String reloadAt, java.lang.String name, java.lang.String type, java.lang.String... params)
          Read a query from the provided xml object and parse it into a DepotQuery object.
 boolean delete(java.lang.String name)
          Delete the specified query from the query store.
static java.lang.String getCacheName(java.lang.String guid)
          Make a distinct name for the cached suites that we add
 int getCacheReloadPeriod()
          Return the period of refreshSuiteCaching for the suite and resources in the Consumer's cache.
 java.io.File getFile()
          Return a handle to the query file.
 java.lang.String getQueriesXml()
          Return the query store xml as a string
 java.lang.String[] getQueryNames()
          Return the stored query names.
 java.lang.Object[] getQueryParams(java.lang.String name)
          Return the query params for the named query
 java.lang.String getQueryResult(java.lang.String name)
          Retrieve a result for the named query.
 java.lang.String getQueryType(java.lang.String name)
          Return the query type for the named query
 boolean hasQuery(java.lang.String name)
          Check to see if the query exists in the store already.
 java.lang.String[] list()
          Fetch the list of stored query names.
 DepotQuery readQuery(edu.sdsc.inca.dataModel.queryStore.Query q)
          Read a query from the provided xml object and parse it into a DepotQuery object.
 boolean refresh(java.lang.String name)
          Refresh the cached result for the named query.
 void refreshSuiteCaching()
          Query the depot and make sure there is a cache entry for each suite and remove those that are no longer around
 void run()
          Periodically query depot and refresh caching of suites
 void save()
          Save the query store configuration to disk.
 void setBeanConfig(java.util.Properties beanConfig)
          Set the attributes for connecting to the agent and also the maxWait and reload frequency.
 void setCacheReloadPeriod(int period)
          Set the period of refreshSuiteCaching for the suite and resources in the Consumer's cache.
 void setFile(java.lang.String filePath)
          Set the path to the file containing stored query information.
 void startQueries()
          Starts the cached query threads so that results are prefetched from the depot and continuously updated.
 void stopQueries()
          Stop prefetching query results from the depot.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, 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

QUERYSTORE

public static final java.lang.String QUERYSTORE
See Also:
Constant Field Values

suiteCachePrefix

public static final java.lang.String suiteCachePrefix
See Also:
Constant Field Values

queryStatus

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

DepotBean

public DepotBean()

DepotBean

public DepotBean(java.lang.String filePath,
                 java.lang.String queryDir)
          throws edu.sdsc.inca.ConfigurationException
Read in or create a new list of stored queries from the provided file.

Parameters:
filePath - A string containing the path to an XML file.
queryDir - A directory where cached queries can be stored
Throws:
edu.sdsc.inca.ConfigurationException - if unable to open queries
Method Detail

add

public boolean add(java.lang.String name,
                   java.lang.String type,
                   java.lang.String... params)
Add a query to the query store. The results of this query will always be fetched directly from the depot. Use this function for light to medium weight queries.

Parameters:
name - The name of the query to store the hql under.
type - The depot query command
params - The parameters for the query command
Returns:
True if the query was successfully added to the store and false if not.

add

public boolean add(int cachePeriod,
                   java.lang.String reloadAt,
                   java.lang.String name,
                   java.lang.String type,
                   java.lang.String... params)
Add a query to the query store. The results of this query will be stored to disk and continously fetched (via a thread) using the frequency provided. Use this function for heavy-duty queries.

Parameters:
cachePeriod - The frequency in seconds to fetch the results of the query periodically from the depot.
reloadAt - The start time for the cache in the form WW:HH:MM
name - The name of the query to store the hql under.
type - The depot query command
params - The parameters for the query command
Returns:
True if the query was successfully added to the store and false if not.

delete

public boolean delete(java.lang.String name)
Delete the specified query from the query store.

Parameters:
name - The name of the query to remove.
Returns:
True if the query was successfully deleted and false if not.

getCacheReloadPeriod

public int getCacheReloadPeriod()
Return the period of refreshSuiteCaching for the suite and resources in the Consumer's cache.

Returns:
the number of milliseconds in between reloads of cached objects.

getFile

public java.io.File getFile()
Return a handle to the query file.

Returns:
A File object.

getQueriesXml

public java.lang.String getQueriesXml()
Return the query store xml as a string

Returns:
An xml document containing the query store info

getQueryNames

public java.lang.String[] getQueryNames()
Return the stored query names.

Returns:
An array of stored query names.

getQueryParams

public java.lang.Object[] getQueryParams(java.lang.String name)
Return the query params for the named query

Parameters:
name - The name of a query
Returns:
The query params or null if query not found

getQueryResult

public java.lang.String getQueryResult(java.lang.String name)
Retrieve a result for the named query. The result will either be fetched directly from the depot or from disk (if it is cached). This is a blocking function.

Parameters:
name - The name of the query to retrieve the results for
Returns:
A string containing the result of the query.

getQueryType

public java.lang.String getQueryType(java.lang.String name)
Return the query type for the named query

Parameters:
name - The name of a query
Returns:
The type of query or null if query not found

hasQuery

public boolean hasQuery(java.lang.String name)
Check to see if the query exists in the store already.

Parameters:
name - The name of the query to search for.
Returns:
True if the query exists in the store and false if not.

list

public java.lang.String[] list()
Fetch the list of stored query names.

Returns:
A list containing the names of the stored queries.

refresh

public boolean refresh(java.lang.String name)
Refresh the cached result for the named query.

Parameters:
name - The name of the query to retrieve the results for
Returns:
true if query was refreshed and false if not or is not a cached query.

refreshSuiteCaching

public void refreshSuiteCaching()
Query the depot and make sure there is a cache entry for each suite and remove those that are no longer around


run

public void run()
Periodically query depot and refresh caching of suites

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

save

public void save()
          throws java.io.IOException
Save the query store configuration to disk.

Throws:
java.io.IOException - if trouble while writing to disk

setBeanConfig

public void setBeanConfig(java.util.Properties beanConfig)
                   throws edu.sdsc.inca.ConfigurationException
Set the attributes for connecting to the agent and also the maxWait and reload frequency.

Parameters:
beanConfig - A properties object containing the config options for this object
Throws:
edu.sdsc.inca.ConfigurationException - if problem with config params

setCacheReloadPeriod

public void setCacheReloadPeriod(int period)
Set the period of refreshSuiteCaching for the suite and resources in the Consumer's cache.

Parameters:
period - the number of milliseconds in between reloads of cached objects

setFile

public void setFile(java.lang.String filePath)
Set the path to the file containing stored query information.

Parameters:
filePath - A path to an XML file.

startQueries

public void startQueries()
Starts the cached query threads so that results are prefetched from the depot and continuously updated.


stopQueries

public void stopQueries()
Stop prefetching query results from the depot.


clear

public void clear()
           throws edu.sdsc.inca.ConfigurationException
Create a new XML file for persisting stored queries and save it to disk.

Throws:
edu.sdsc.inca.ConfigurationException - if unable to create query store xml.

getCacheName

public static java.lang.String getCacheName(java.lang.String guid)
Make a distinct name for the cached suites that we add

Parameters:
guid - The guid of the suite
Returns:
A distinct name for a suite guid that is likely not to clash with a name a user would pick

createQuery

public edu.sdsc.inca.dataModel.queryStore.Query createQuery(int cachePeriod,
                                                            java.lang.String reloadAt,
                                                            java.lang.String name,
                                                            java.lang.String type,
                                                            java.lang.String... params)
Read a query from the provided xml object and parse it into a DepotQuery object.

Parameters:
cachePeriod - The frequency in seconds to fetch the results of the query periodically from the depot.
reloadAt - Should be "*" if we don't care about the time the query is started otherwise should be WW:HH:MM.
name - The name of the query to store the hql under.
type - The depot query command
params - The parameters for the query command @return A new DepotQuery object that can be used to fetch results
Returns:
a query object from the queryStore schema

readQuery

public DepotQuery readQuery(edu.sdsc.inca.dataModel.queryStore.Query q)
Read a query from the provided xml object and parse it into a DepotQuery object.

Parameters:
q - A xml object that describes a query
Returns:
A new DepotQuery object that can be used to fetch results