| | 7 | private static var _executor:IThreadExecutor; |
|---|
| | 8 | private static var _threadIndex:uint = 0; |
|---|
| | 9 | private static var _currentThread:Thread = null; |
|---|
| | 10 | |
|---|
| | 11 | /** |
|---|
| | 12 | * スレッドライブラリを初期化します。このメソッドは、最初に一度だけ呼び出してください。 |
|---|
| | 13 | * スレッドの実行は、指定された IThreadExecutor インスタンスによって行われます。 |
|---|
| | 14 | * (このメソッド内で、IThreadExectuor#startが呼び出されます) |
|---|
| | 15 | * |
|---|
| | 16 | * @param executor スレッドの実行を行う IThreadExecutor |
|---|
| | 17 | */ |
|---|
| | 18 | public static function initialize(executor:IThreadExecutor):void |
|---|
| | 19 | { |
|---|
| | 20 | _threadIndex = 0; |
|---|
| | 21 | _currentThread = null; |
|---|
| | 22 | |
|---|
| | 23 | // 古い IThreadExecutor の実行を止める |
|---|
| | 24 | if (_executor != null) { |
|---|
| | 25 | _executor.stop(); |
|---|
| | 26 | } |
|---|
| | 27 | |
|---|
| | 28 | _executor = executor; |
|---|
| | 29 | |
|---|
| | 30 | // 新しい IThreadExecutor の実行を開始 |
|---|
| | 31 | if (_executor != null) { |
|---|
| | 32 | _executor.start(); |
|---|
| | 33 | } |
|---|
| | 34 | } |
|---|
| | 35 | |
|---|
| | 36 | /** |
|---|
| | 37 | * 現在実行中のスレッドを返します |
|---|
| | 38 | */ |
|---|
| | 39 | public static function get currentThread():Thread |
|---|
| | 40 | { |
|---|
| | 41 | return _currentThread; |
|---|
| | 42 | } |
|---|
| | 43 | |
|---|
| | 44 | /** |
|---|
| | 45 | * 全てのスレッドを実行します。通常、このメソッドは IThreadExector インターフェイスの実装クラスによって呼び出されます。 |
|---|
| | 46 | */ |
|---|
| | 47 | public static function executeAllThreads():void |
|---|
| | 48 | { |
|---|
| | 49 | |
|---|
| | 50 | } |
|---|
| | 51 | |
|---|
| | 52 | /** |
|---|
| | 53 | * 現在実行中のスレッドの実行関数を、指定された関数に切り替えます |
|---|
| | 54 | * |
|---|
| | 55 | * @param func |
|---|
| | 56 | */ |
|---|
| | 57 | public static function next(func:Function):void |
|---|
| | 58 | { |
|---|
| | 59 | |
|---|
| | 60 | } |
|---|
| | 61 | |
|---|
| | 62 | /** |
|---|
| | 63 | * 現在実行中のスレッドに対して、エラーハンドラを設定します |
|---|
| | 64 | * |
|---|
| | 65 | * @param klass |
|---|
| | 66 | * @param func |
|---|
| | 67 | * @param reset |
|---|
| | 68 | */ |
|---|
| | 69 | public static function error(klass:Class, func:Function, reset:Boolean = true):void |
|---|
| | 70 | { |
|---|
| | 71 | |
|---|
| | 72 | } |
|---|
| | 73 | |
|---|
| | 74 | /** |
|---|
| | 75 | * 現在実行中のスレッドに対して、イベントハンドラを設定します |
|---|
| | 76 | * |
|---|
| | 77 | * @param dispatcher |
|---|
| | 78 | * @param type |
|---|
| | 79 | * @param reset |
|---|
| | 80 | * @param func |
|---|
| | 81 | * @param useCapture |
|---|
| | 82 | * @param priority |
|---|
| | 83 | * @param useWeakReference |
|---|
| | 84 | */ |
|---|
| | 85 | public static function event(dispatcher:IEventDispatcher, type:String, func:Function, reset:Boolean = true, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void |
|---|
| | 86 | { |
|---|
| | 87 | |
|---|
| | 88 | } |
|---|
| | 89 | |
|---|
| | 90 | public static function sleep(time:uint):void |
|---|
| | 91 | { |
|---|
| | 92 | |
|---|
| | 93 | } |
|---|
| | 94 | |
|---|
| | 95 | public static function interrupted():Boolean |
|---|
| | 96 | { |
|---|
| | 97 | return false; |
|---|
| | 98 | } |
|---|
| | 99 | |
|---|
| | 100 | public function Thread() |
|---|
| | 101 | { |
|---|
| | 102 | _id = ++_threadIndex; |
|---|
| | 103 | _name = 'Thread' + _id; |
|---|
| | 104 | _state = ThreadState.NEW; |
|---|
| | 105 | } |
|---|
| | 106 | |
|---|
| | 107 | private var _id:uint; |
|---|
| | 108 | private var _name:String; |
|---|
| | 109 | private var _state:uint; |
|---|
| | 110 | |
|---|
| | 111 | public function get id():uint |
|---|
| | 112 | { |
|---|
| | 113 | return _id; |
|---|
| | 114 | } |
|---|
| | 115 | |
|---|
| | 116 | public function get name():String |
|---|
| | 117 | { |
|---|
| | 118 | return _name; |
|---|
| | 119 | } |
|---|
| | 120 | |
|---|
| | 121 | public function set name(value:String):void |
|---|
| | 122 | { |
|---|
| | 123 | _name = value; |
|---|
| | 124 | } |
|---|
| | 125 | |
|---|
| | 126 | public function get state():uint |
|---|
| | 127 | { |
|---|
| | 128 | return _state; |
|---|
| | 129 | } |
|---|
| | 130 | |
|---|
| | 131 | public function get isInterrupted():Boolean |
|---|
| | 132 | { |
|---|
| | 133 | return false; |
|---|
| | 134 | } |
|---|
| | 135 | |
|---|
| | 136 | public function start():void |
|---|
| | 137 | { |
|---|
| | 138 | |
|---|
| | 139 | } |
|---|
| | 140 | |
|---|
| | 141 | public function join(time:uint = 0):Boolean |
|---|
| | 142 | { |
|---|
| | 143 | return false; |
|---|
| | 144 | } |
|---|
| | 145 | |
|---|
| | 146 | public function interrupt():void |
|---|
| | 147 | { |
|---|
| | 148 | |
|---|
| | 149 | } |
|---|
| | 150 | |
|---|
| | 151 | protected function run():void |
|---|
| | 152 | { |
|---|
| | 153 | |
|---|
| | 154 | } |
|---|
| | 155 | |
|---|
| | 156 | protected function finalize():void |
|---|
| | 157 | { |
|---|
| | 158 | |
|---|
| | 159 | } |
|---|
| | 160 | |
|---|
| | 161 | protected function formatName(name:String):String |
|---|
| | 162 | { |
|---|
| | 163 | return '[Thread ' + name + ']'; |
|---|
| | 164 | } |
|---|
| | 165 | |
|---|
| | 166 | public function toString():String |
|---|
| | 167 | { |
|---|
| | 168 | return formatName(name); |
|---|
| | 169 | } |
|---|
| | 170 | |
|---|
| | 171 | /* |
|---|