uk.ac.ic.doc.automed.p2p
Class QueryCache

java.lang.Object
  extended by uk.ac.ic.doc.automed.p2p.QueryCache
All Implemented Interfaces:
uk.ac.ic.doc.automed.util.cache.Cacheable

public class QueryCache
extends java.lang.Object
implements uk.ac.ic.doc.automed.util.cache.Cacheable


Method Summary
 void addListener(uk.ac.ic.doc.automed.util.cache.CacheListener cacheListener)
          Register a listener for handling cache-related events
 void addQuery(java.lang.String query, java.lang.Object resultObj)
          Add a new query to cache.
 void clear()
          Clear the cache
 java.util.List getCachedQueries()
          Return all queries in the cache
protected  uk.ac.ic.doc.automed.util.cache.CacheContentDescription getContent()
          Implements interface Cacheable.
 uk.ac.ic.doc.automed.util.cache.CacheContentDescription getContentObject()
          Return the cache data bag
static QueryCache getInstance(long ageTime)
          A singleton method to make sure that there is only one instance of query cache per peer
 java.lang.Object getMaximalQuery(java.lang.String query)
          Unlike #getQuery(query) which performs an exact query match, this method
attempts to perform a maximal query rewriting against the
existing views/queries in the cache and aggregate the results of the found views
.
 java.lang.Object getQuery(java.lang.String query)
          Check in the cache for an exact query match.
If so return the associated result object; otherwise return null
 void notifyListeners(uk.ac.ic.doc.automed.util.cache.Cacheable cacheObj)
          Notify listeners to handle a specific event
 void refresh()
          refresh cache
 void serialise()
          Save cache content to disk (or database).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static QueryCache getInstance(long ageTime)
A singleton method to make sure that there is only one instance of query cache per peer


addQuery

public void addQuery(java.lang.String query,
                     java.lang.Object resultObj)
Add a new query to cache. The query is used as the key and result object
is the value.

Parameters:
query - the actual query string used for execution
resultObj - the result object from query execution

getQuery

public java.lang.Object getQuery(java.lang.String query)
Check in the cache for an exact query match.
If so return the associated result object; otherwise return null

Returns:
Object the result object from query execution

getCachedQueries

public java.util.List getCachedQueries()
Return all queries in the cache

Returns:
List a list of queries in the cache OR null
if no queries are found

getMaximalQuery

public java.lang.Object getMaximalQuery(java.lang.String query)
Unlike #getQuery(query) which performs an exact query match, this method
attempts to perform a maximal query rewriting against the
existing views/queries in the cache and aggregate the results of the found views
.

Parameters:
query - a new query to search

getContent

protected uk.ac.ic.doc.automed.util.cache.CacheContentDescription getContent()
Implements interface Cacheable. Returns a List object of cache content. Each item in the list is
a HashMap object containing id, query, result and timestamp values
of each cached query.


getContentObject

public uk.ac.ic.doc.automed.util.cache.CacheContentDescription getContentObject()
Return the cache data bag

Specified by:
getContentObject in interface uk.ac.ic.doc.automed.util.cache.Cacheable

serialise

public void serialise()
Save cache content to disk (or database). Note that the cache should not perform
any IO operations here. It merely prepares the data and notifies the appropriate
listener to save the data


clear

public void clear()
Clear the cache

Specified by:
clear in interface uk.ac.ic.doc.automed.util.cache.Cacheable

refresh

public void refresh()
refresh cache

Specified by:
refresh in interface uk.ac.ic.doc.automed.util.cache.Cacheable

addListener

public void addListener(uk.ac.ic.doc.automed.util.cache.CacheListener cacheListener)
Register a listener for handling cache-related events

Specified by:
addListener in interface uk.ac.ic.doc.automed.util.cache.Cacheable
Parameters:
cacheListener - a CacheListener object to add

notifyListeners

public void notifyListeners(uk.ac.ic.doc.automed.util.cache.Cacheable cacheObj)
Notify listeners to handle a specific event

Parameters:
cacheObj - the Cacheable object to be used by listener to handle event