GODPAPER | All Packages | All Classes | Index | Frames No Frames |
GreenThread

Package | org.generalrelativity.thread
Class | public final class GreenThread
Inheritance | GreenThread flash.events.EventDispatcher

User-space thread emulator that manages a list of processes and considers requested frequencies and allocation constraints.

See also

http://en.wikipedia.org/wiki/Green_threads
IRunnable
GreenThreadDiagnostic

Public Properties

| Property | Defined By
--- | --- | ---
|  | diagnostic : GreenThreadDiagnostic [read-only] Gets this thread's diagnostic, if any | GreenThread
|  | isOpen : Boolean [read-only] Determines whether the thread is open based on the existence of runner and processes | GreenThread
|  | isRunning : Boolean [read-only] | GreenThread

Public Methods

| Method | Defined By
--- | --- | ---
|  | GreenThread(processes:Vector.<IRunnable>, hertz:int, share:Number = 0.5, isDiagnostic:Boolean = false) Constructor Creates a new GreenThread. | GreenThread
|  | close(terminateProcesses:Boolean = true):GreenThreadDiagnostic Closes the thread and readies itself for garbage collection | GreenThread
|  | open():void Opens the thread This is called to first open, and to reopen after forcing the thread to yield | GreenThread
|  | removeProcess(process:IRunnable):void Removes a process from the list, if actually in list | GreenThread
|  | yield():void Forces the thread to yield | GreenThread

Events

| Event | Summary | Defined By
--- | --- | --- | ---
|  | complete | Dispatched when the thread has successfully executed all requested processes | GreenThread
|  | cycle | Dispatched when the thread has completed a cycle | GreenThread
|  | processComplete | Dispatched whenever a process has completed executing | GreenThread
|  | processTimeout | Dispatched whenever a process has thrown a script timeout exception | GreenThread

Public Constants

| Constant | Defined By
--- | --- | ---
|  | CYCLE : String = cycle [static] | GreenThread
|  | EPSILON : int = 1 [static] Minimum contribution- will have to tweak this based on testing | GreenThread

Property Detail

diagnostic | property

`diagnostic:GreenThreadDiagnostic` [read-only]

Gets this thread's diagnostic, if any

Implementation
`public function get diagnostic():GreenThreadDiagnostic`

isOpen | property |

`isOpen:Boolean` [read-only]

Determines whether the thread is open based on the existence of runner and processes

Implementation
`public function get isOpen():Boolean`

isRunning | property |

`isRunning:Boolean` [read-only]

Implementation
`public function get isRunning():Boolean`
Constructor Detail

GreenThread | () | Constructor

`public function GreenThread(processes:Vector.<IRunnable>, hertz:int, share:Number = 0.5, isDiagnostic:Boolean = false)`

Constructor

Creates a new GreenThread. If `isDiagnostic` is set to true, a diagnostic is performed during thread execution.

Parameters

| `processes:Vector.<IRunnable>` — Sets `processes`
| `hertz:int` — Frequency at which thread is executed
| `share:Number` (default = `0.5`)`` — Percentage of VM processor that this thread should occupy
| `isDiagnostic:Boolean` (default = `false`)`` — Sets diagnostic mode

Throws

| `Error` — if no processes are passed

Method Detail

close | () | method

`public function close(terminateProcesses:Boolean = true):GreenThreadDiagnostic`

Closes the thread and readies itself for garbage collection

Parameters

| `terminateProcesses:Boolean` (default = `true`)`` — Flags whether to explicitly terminate all open processes

Returns

| `GreenThreadDiagnostic`

open | () | method |

`public function open():void`

Opens the thread

This is called to first open, and to reopen after forcing the thread to yield

See also

yield
close

removeProcess | () | method |

`public function removeProcess(process:IRunnable):void`

Removes a process from the list, if actually in list

Parameters

| `process:IRunnable`

yield | () | method |

`public function yield():void`

Forces the thread to yield

Event Detail

complete | Event

Event Object Type: `flash.events.Event`
Event.type property = `flash.event.Event.COMPLETE`

Dispatched when the thread has successfully executed all requested processes

cycle | Event |

Event Object Type: `GreenThread`
GreenThread.type property = `GreenThread.CYCLE`

Dispatched when the thread has completed a cycle

processComplete | Event |

Event Object Type: `org.generalrelativity.thread.event.GreenThreadEvent`
GreenThreadEvent.type property = `org.generalrelativity.thread.event.GreenThreadEvent.PROCESS_COMPLETE`

Dispatched whenever a process has completed executing

processTimeout | Event |

Event Object Type: `org.generalrelativity.thread.event.GreenThreadEvent`
GreenThreadEvent.type property = `org.generalrelativity.thread.event.GreenThreadEvent.PROCESS_TIMEOUT`

Dispatched whenever a process has thrown a script timeout exception

Constant Detail

CYCLE | Constant

`public static const CYCLE:String = cycle`

EPSILON | Constant |

`public static const EPSILON:int = 1`

Minimum contribution- will have to tweak this based on testing

Thu Jan 16 2014, 01:11 PM +08:00