The Thread class provides a psuedo-thread implementation for Framework Objects. Each thread is sensitive to the object lifecycle, and can stop itself when the object is destroyed or when the framework is shutdown.
Creates a psuedo asynchronous thread.
See Example Thread #1 for an example of implementating the script on a page.
Demonstrate how to use the Thread component.
var MyThreadedObject = {
handle_thread_run : function(oThread){
/* basic demo */
document.title = (new Date()).getTime();
}
};
/* Prepare the MyThreadedObject for use with Engine */
Hemi.prepareObject("CustomThread","1.0",true,MyThreadedObject);
/* Create a new thread for MyThreadedObject*/
var oThread = Hemi.util.thread.newInstance(MyThreadedObject);
/* run the thread every 5 seconds */
oThread.run(5000);Creates a new instance of a psuedo thread. The thread is bound to the object lifetime of the specified object, so that when the object is explicitly destroyed or removed from the ObjectRegistry, the thread will also terminate.
t = newInstance( o )
t as Thread: A new ThreadInstance.
A psuedo thread that is created by invoking the static thread class newInstance method.
Object API structure for storing sub structures: object_config.pointers and object_config.status.
object = object.object_config
Unique instance identifier.
String = object.object_id
The type of this object.
String = object.object_type
Version of the object class.
String = object.object_version
Object load and execution state. Follows: 0 unitialized, 1 through 3 variant, 4 ready, 5 destroyed.
int = object.ready_state
Invokes the stop method and prevents the thread from further execution.
void allStop( )
Prepares the object for destruction.
void destroy( )
Returns true if the thread can be run.
b = getIsRunnable( )
b as boolean: Bit indicating whether the thread can be run.
Returns true if the thread is running, false otherwise.
b = getIsRunning( )
b as boolean: Bit indicating whether the thread is running.
Returns the delay interval used to start the thread.
i = getLastInterval( )
i as int: The interval in milliseconds used to start the thread.
Returns the unique id of the object.
i = getObjectId( )
i as String: The unique object instance id.
Returns the type of the object.
t = getObjectType( )
t as String: The type of the object instance.
Returns the version of the object.
v = getObjectVersion( )
v as String: The version of the object instance.
Returns the object_config.pointers sub structure.
o = getPointers( )
o as object: The object_config.pointers substructure.
Returns the state of the object.
s = getReadyState( )
s as int: The object ready state.
Returns the object_config.status sub structure.
o = getStatus( )
o as object: The object_config.status substructure.
Invoked when the thread is running an iteration. Method is virtual and can be overridden.
void handle_thread_run( t )
Invoked when the thread is starting. Method is virtual and can be overridden.
void handle_thread_start( t )
Invoked when the thread is shutting down. Method is virtual and can be overridden.
void handle_thread_stop( t )
Restarts the thread interval.
b = restart( )
b as boolean: Bit indicating whether the thread was restarted.
Runs the thread with the specifed delay.
b = run( d, b )
b as boolean: Bit indicating whether the thread started running.
Stops the thread.
b = stop( b )
b as boolean: Bit indicating whether the thread was stopped.
[ Hemi JavaScript Framework - Stephen W. Cote, 2002 - 2009. ]