org.jafer.databeans
Class ActiveBean

java.lang.Object
  extended by java.lang.Thread
      extended by org.jafer.databeans.ActiveBean
All Implemented Interfaces:
java.lang.Runnable

 class ActiveBean
extends java.lang.Thread

This inner class represents a thread that performs a search on a Jafer Client (AbstractClient). It is configured and utilised by the DataBeanManager in order to facilitate parallel searches.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
private  boolean autoPopulateCache
          Stores a reference to whether pre filling of the caching is enabled or not.
private  java.lang.String cacheRecordSchema
          Stores a reference to record schema to use when preopoulating the cache
private  Databean databean
          Stores a reference to the bean that this ActiveBean uses to perform searches and to retrieve results from.
private  int endOffset
          Stores a reference to the offset this ActiveBean ends at in the super result set of all the ActiveBeans
private static java.util.logging.Logger logger
          Stores a reference to logger instance
private  java.lang.Object query
          Stores a reference to query that should be submited to the jaferClientBean when the thread is executed
private  JaferException searchException
          Stores a reference to exception that occured in the last search or null if no errors occured
private  int startOffset
          Stores a reference to the offset this ActiveBean starts at in the super result set of all the ActiveBeans
private  boolean stillSearching
          Stores a reference to whether the search is still executing.
private  boolean stopActiveBeanSearch
          Stores a reference to a flag that indicates that the thread should terminate and prefilling of the cache should stop if it has not yet completed
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ActiveBean()
           
 
Method Summary
 boolean autoPopulateCache()
          Returns whether this active bean should prepopulate cache after search
 boolean containsRecord(int recordIndex)
          Returns a boolean to indicate if the record index supplied is contained with in the result set of this ActiveBean.
 Databean getDatabean()
          Gets a reference to the JaferClientBean for this ActiveBean
 int getNumberOfResults()
          Get the number of results that were found the last time the ActiveBeans thread was executed
protected  java.lang.String getPrepoulateCacheRecordSchema()
          Get the record schema to use when prepoulating cache
 java.lang.Object getQuery()
          get the query that will be executed when this ActiveBeans thread is run
 Field getRecord(int recordIndex, java.lang.String schema)
          Retrieve the record at the specified recordIndex
protected  Field getRecord(int recordIndex, java.lang.String schema, boolean applyOffsets)
          Retrieve the record at the specified recordIndex
 JaferException getSearchException()
          This method returns the JaferException from the last search.
 void run()
          Executes the thread to perform the search
 void setAutoPopulateCache(boolean autoPopulate)
          Sets whether this active bean should prepopulate cache after search
 void setDatabean(Databean bean)
          sets a reference to the JaferClientBean for this ActiveBean
 void setOffsets(int start, int end)
          Sets the offsets for this ActiveBean result set in respect to the super result set of all the ActiveBeans
protected  void setPrepoulateCacheRecordSchema(java.lang.String recordSchema)
          Set the record schema to use when prepoulating cache
protected  void setSearchException(JaferException exc)
          This method sets the last exception that occurred during a search
 boolean stillSearching()
          This method checks if the search is still executing
protected  void stillSearching(boolean searchStatus)
          This method sets the flag to indicate if the search is executing or not
protected  boolean stopActiveBeanSearch()
          Checks to see if the search should be stopped premeturely
 void stopActiveBeanSearch(boolean stopStatus)
          This method allows the caller to set the stop active bean search flag
 void submitQuery(java.lang.Object query, java.lang.String schema)
          Set the query that will be executed when this ActiveBeans thread is run
 
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

stopActiveBeanSearch

private boolean stopActiveBeanSearch
Stores a reference to a flag that indicates that the thread should terminate and prefilling of the cache should stop if it has not yet completed


stillSearching

private boolean stillSearching
Stores a reference to whether the search is still executing.


autoPopulateCache

private boolean autoPopulateCache
Stores a reference to whether pre filling of the caching is enabled or not. Enabled as default.


cacheRecordSchema

private java.lang.String cacheRecordSchema
Stores a reference to record schema to use when preopoulating the cache


startOffset

private int startOffset
Stores a reference to the offset this ActiveBean starts at in the super result set of all the ActiveBeans


endOffset

private int endOffset
Stores a reference to the offset this ActiveBean ends at in the super result set of all the ActiveBeans


databean

private Databean databean
Stores a reference to the bean that this ActiveBean uses to perform searches and to retrieve results from. It must implement the Search and Present interfaces.


query

private java.lang.Object query
Stores a reference to query that should be submited to the jaferClientBean when the thread is executed


logger

private static java.util.logging.Logger logger
Stores a reference to logger instance


searchException

private JaferException searchException
Stores a reference to exception that occured in the last search or null if no errors occured

Constructor Detail

ActiveBean

ActiveBean()
Method Detail

setOffsets

public void setOffsets(int start,
                       int end)
Sets the offsets for this ActiveBean result set in respect to the super result set of all the ActiveBeans

Parameters:
start - The starting offset index
end - The ending offset index

containsRecord

public boolean containsRecord(int recordIndex)
Returns a boolean to indicate if the record index supplied is contained with in the result set of this ActiveBean. IE that the record index is between the offsets.

Parameters:
recordIndex - The index to search for
Returns:
true if the record is contained in this ActiveBean

getDatabean

public Databean getDatabean()
Gets a reference to the JaferClientBean for this ActiveBean

Returns:
The instance of the DataBean

setDatabean

public void setDatabean(Databean bean)
sets a reference to the JaferClientBean for this ActiveBean

Parameters:
bean - The JaferClientBean to store in this ActiveBean

getSearchException

public JaferException getSearchException()
This method returns the JaferException from the last search.

Returns:
JaferException instance or null if no errors were found

setSearchException

protected void setSearchException(JaferException exc)
This method sets the last exception that occurred during a search

Parameters:
exc - The exception that occurred

submitQuery

public void submitQuery(java.lang.Object query,
                        java.lang.String schema)
Set the query that will be executed when this ActiveBeans thread is run

Parameters:
query - The query to execute
schema - The schema used to auto populate cache

getQuery

public java.lang.Object getQuery()
get the query that will be executed when this ActiveBeans thread is run

Returns:
The query to be executed

setPrepoulateCacheRecordSchema

protected void setPrepoulateCacheRecordSchema(java.lang.String recordSchema)
Set the record schema to use when prepoulating cache

Parameters:
recordSchemamThe - schema to prepopulate the cache with

getPrepoulateCacheRecordSchema

protected java.lang.String getPrepoulateCacheRecordSchema()
Get the record schema to use when prepoulating cache

Returns:
The schema for prepoulating the cache

getNumberOfResults

public int getNumberOfResults()
Get the number of results that were found the last time the ActiveBeans thread was executed

Returns:
The number of results found

getRecord

public Field getRecord(int recordIndex,
                       java.lang.String schema)
                throws JaferException
Retrieve the record at the specified recordIndex

Parameters:
recordIndex - The recordIndex to retrieve
schema - The schema to apply
Returns:
The retrieved record
Throws:
JaferException

getRecord

protected Field getRecord(int recordIndex,
                          java.lang.String schema,
                          boolean applyOffsets)
                   throws JaferException
Retrieve the record at the specified recordIndex

Parameters:
recordIndex - The recordIndex to retrieve
schema - The schema to apply
applyOffsets - Should the offsets be applied to the record index, This is normally true apart from when the autopopulation of cache needs to refer to local indexs
Returns:
The retrieved record
Throws:
JaferException

stillSearching

public boolean stillSearching()
This method checks if the search is still executing

Returns:
Returns the false if the search has completed.

stillSearching

protected void stillSearching(boolean searchStatus)
This method sets the flag to indicate if the search is executing or not

Parameters:
searchStatus - The search status - true if executing search

autoPopulateCache

public boolean autoPopulateCache()
Returns whether this active bean should prepopulate cache after search

Returns:
Returns true is auto population of cache should take place

setAutoPopulateCache

public void setAutoPopulateCache(boolean autoPopulate)
Sets whether this active bean should prepopulate cache after search

Parameters:
autoPopulate - true if the cache should be auto populated

stopActiveBeanSearch

public void stopActiveBeanSearch(boolean stopStatus)
This method allows the caller to set the stop active bean search flag


stopActiveBeanSearch

protected boolean stopActiveBeanSearch()
Checks to see if the search should be stopped premeturely

Returns:
true if search process should terminate early

run

public void run()
Executes the thread to perform the search

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