lib3k 0.1a

Thread.js

Summary

No overview generated for 'Thread.js'


Class Summary
Thread A Thread can be either a generic java.lang.Thread object or an internal Helma request.

//
// Copyright (c) 2006 Tobi Schäfer
// Alle Rechte vorbehalten. All rights reserved.
//
// $Revision$
// $Author$
// $Date$
//

/**
 * Creates a new Thread instance.
 * @class A Thread can be either a generic java.lang.Thread
 * object or an internal Helma request. In both cases the code
 * will be evaluated "in background", ie. apart from the current
 * thread.
 * @param {Object} handler Either a function or an object. If an
 * object is assigned it will be used as context for the (then
 * mandatory) second argument.
 * @param {String} method Defines the name of the method that 
 * should be executed. All further given arguments will be 
 * used in the method call.
 * @returns A new thread.
 * @type Thread
 * @constructor
 */
var Thread = function(handler, method /*, arguments */) {
   var runner;
   if (method) {
      var args = new Array;
      var i;
      for (i=2; i<arguments.length; i+=1) {
         args.push(arguments[i]);
      }
      runner = function() {
         var ev = app.__app__.getEvaluator();
         ev.invokeInternal(handler, method.toString(), args);
         app.__app__.releaseEvaluator(ev);
         return;
      };
   } else if (handler.constructor != Function) {
      throw Error("Cannot create thread from " + handler);
   } else {
      runner = handler;
   }
   
   var thread = new java.lang.Thread(
      new java.lang.Runnable({
         run: runner
      })
   );
   
   /**
    * Starts the thread.
    */
   this.start = function() {
      thread.start();
      return;
   };
   
   /**
    * Stops the thread.
    */
   this.stop = function() {
      thread = null;
      return;
   };
   
   /**
    * Returns the current state of the thread.
    * @returns True if the thread is alive, false otherwise.
    * @type Boolean
    */
   this.isRunning = function() {
      return thread ? true: false;
   };

   return this;
};

lib3k 0.1a

Documentation generated by JSDoc on Sun Mar 4 00:51:24 2007