org.opensubsystems.patterns.listdata.util
Class AsyncDataLoader

java.lang.Object
  extended by java.lang.Thread
      extended by org.opensubsystems.patterns.listdata.util.AsyncDataLoader
All Implemented Interfaces:
java.lang.Runnable

public class AsyncDataLoader
extends java.lang.Thread

Thread used to load data asynchronously using list controller interface. The class, which wants to perform async data processing will usually derive new class inline and define method createAddItemsRunnable. TODO: Performance: We may want to convert this to Runnable and the user pool of threads to run them instead of creating new thread all the time.

Version:
$Id: AsyncDataLoader.java,v 1.9 2007/01/07 06:14:10 bastafidli Exp $
Author:
Miro Halas
Code reviewer:
Miro Halas
Code reviewed:
1.5 2006/03/13 16:58:37 bastafidli

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 ASYNC_LOADER_PAGE_SIZE
          Configuration setting for how many items to load at once when loading data in the background.
static int ASYNC_LOADER_PAGE_SIZE_DEFAULT
          Default value for how many items to load at once when loading data in the background.
protected  java.lang.Class m_clsListFactoryClassName
          Class for the list factory to use.
protected  int m_iCurrentObjectVersion
          Value uniquely identifying the current state of the object to which the data should be added.
protected  int m_iLoaderIdentification
          Identification of this loader which is send back to owner to distinguish if there are multiple loader present.
protected  AsyncDataLoaderOwner m_owner
          Owner which is loading with data using this thread.
static java.lang.Runnable NOTHING_TO_DO
          This object should be used as a placeholder when there is nothing to do to prevent creation of new objects and exhausting memory.
protected static int s_iPageSize
          How many items to load at once when loading data in the background.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
AsyncDataLoader(int iLoaderIdentification, AsyncDataLoaderOwner owner, java.lang.Class clsListFactoryClassName, int iObjectVersion)
          Construct new loader.
 
Method Summary
protected  void allDataLoaded()
          This function is called where data loading finished.
protected  ListOptions getInitialListOptions()
          Return the initial ListOptions structure used to load the list of data objects.
protected  ListController getListController()
          Get list controller to use.
protected  void processData(java.util.List lstDataToAdd, int iOriginalObjectVersion)
          Process data which were asynchronously loaded.
 void run()
          
protected  boolean stopLoading()
          This method should return true if the async thread should stop loading data.
 
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

ASYNC_LOADER_PAGE_SIZE

public static final java.lang.String ASYNC_LOADER_PAGE_SIZE
Configuration setting for how many items to load at once when loading data in the background. If this is equal to ListOptions.PAGE_SIZE_ALL then all items will be loaded at once.

See Also:
Constant Field Values

ASYNC_LOADER_PAGE_SIZE_DEFAULT

public static final int ASYNC_LOADER_PAGE_SIZE_DEFAULT
Default value for how many items to load at once when loading data in the background.

See Also:
Constant Field Values

NOTHING_TO_DO

public static final java.lang.Runnable NOTHING_TO_DO
This object should be used as a placeholder when there is nothing to do to prevent creation of new objects and exhausting memory.


m_iLoaderIdentification

protected int m_iLoaderIdentification
Identification of this loader which is send back to owner to distinguish if there are multiple loader present.


m_owner

protected AsyncDataLoaderOwner m_owner
Owner which is loading with data using this thread.


m_clsListFactoryClassName

protected java.lang.Class m_clsListFactoryClassName
Class for the list factory to use.


m_iCurrentObjectVersion

protected int m_iCurrentObjectVersion
Value uniquely identifying the current state of the object to which the data should be added. This is used to detect when to stop loading by increasing the value of the original variable to be different from this value.


s_iPageSize

protected static int s_iPageSize
How many items to load at once when loading data in the background. If this is equal to ListOptions.PAGE_SIZE_ALL then all items will be loaded at once.

Constructor Detail

AsyncDataLoader

public AsyncDataLoader(int iLoaderIdentification,
                       AsyncDataLoaderOwner owner,
                       java.lang.Class clsListFactoryClassName,
                       int iObjectVersion)
Construct new loader.

Parameters:
iLoaderIdentification - - identification of this loader which is send back to owner to distinguish if there are multiple loader present
owner - - owner of this data loader TODO: Improve: It doesn't necessarily make sence for everybody to know what factory class to user
clsListFactoryClassName - - name of the class for the list factory to use
iObjectVersion - - value uniquely identifying the current state of the object to which the data should be added
Method Detail

run

public void run()

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

getInitialListOptions

protected ListOptions getInitialListOptions()
Return the initial ListOptions structure used to load the list of data objects. This method may be overriden if some parameters should be preset.

Returns:
ListOptions - initialized list options

stopLoading

protected boolean stopLoading()
This method should return true if the async thread should stop loading data.

Returns:
boolean - true if the async thread should stop loading data, false to continue loading

processData

protected void processData(java.util.List lstDataToAdd,
                           int iOriginalObjectVersion)
Process data which were asynchronously loaded.

Parameters:
lstDataToAdd - - list of data items to add to the container
iOriginalObjectVersion - - version of the object by which the data should be processed, which is the version which was used to construct this object. If the version of the object at the time when the data are being processed is different from this version, then the data will not be processed or the processing of the data stops.

allDataLoaded

protected void allDataLoaded()
This function is called where data loading finished. It is useful if you want do same changes or ask for information relevant to the whole dataset.


getListController

protected ListController getListController()
                                    throws org.opensubsystems.core.error.OSSException
Get list controller to use.

Returns:
ListController
Throws:
org.opensubsystems.core.error.OSSException - - an error has occured


Copyright © 2003 - 2006 OpenSubsystems s.r.o.