root/as3/Thread/trunk/samples/flickrsphere/src/org/libspark/flickrsphere/threads/flickr/PhotoImageQueue.as

リビジョン 720, 3.0 kB (コミッタ: yossy, コミット時期: 4 年 前)

Thread: サンプル「FlickrSphere?

Line 
1 /*
2  * Flickr Sphere (Sample of the ActionScript Thread Library)
3  *
4  * Licensed under the MIT License
5  *
6  * Copyright (c) 2008 BeInteractive! (www.be-interactive.org) and
7  *                    Spark project  (www.libspark.org)
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a copy
10  * of this software and associated documentation files (the "Software"), to deal
11  * in the Software without restriction, including without limitation the rights
12  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13  * copies of the Software, and to permit persons to whom the Software is
14  * furnished to do so, subject to the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be included in
17  * all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25  * THE SOFTWARE.
26  *
27  */
28 package org.libspark.flickrsphere.threads.flickr
29 {
30         import flash.display.Loader;
31         import org.libspark.thread.IMonitor;
32         import org.libspark.thread.Monitor;
33        
34         /**
35          * PhotoImageQueue クラスは、ロードした写真イメージをストックするためのキューです.
36          */
37         public class PhotoImageQueue
38         {
39                 public function PhotoImageQueue()
40                 {
41                         _queue = [];
42                         _monitor = new Monitor();
43                 }
44                
45                 private var _queue:Array;
46                 private var _monitor:IMonitor;
47                
48                 /**
49                  * キューが空であれば true、そうでなければ false を返します.
50                  */
51                 public function get isEmpty():Boolean
52                 {
53                         return _queue.length == 0;
54                 }
55                
56                 /**
57                  * キューに指定されたイメージを追加します.
58                  *
59                  * @param       image   追加するイメージ
60                  */
61                 public function offer(image:Loader):void
62                 {
63                         // キューに追加
64                         _queue.push(image);
65                         // checkPoll でイメージを取得可能になるまで待機しているスレッドを起こす
66                         _monitor.notifyAll();
67                 }
68                
69                 /**
70                  * キューからイメージを取得可能かどうかをチェックし、可能でなければ取得可能になるまでスレッドを待機させます.
71                  *
72                  * @return      スレッドが待機する場合に true、そうでなければ false
73                  */
74                 public function checkPoll():Boolean
75                 {
76                         // キューが空であれば
77                         if (isEmpty) {
78                                 // スレッドを待機させる
79                                 _monitor.wait();
80                                 return true;
81                         }
82                         return false;
83                 }
84                
85                 /**
86                  * キューからイメージを取得します.
87                  *
88                  * @return      イメージ
89                  */
90                 public function poll():Loader
91                 {
92                         // キューから取得
93                         return _queue.shift();
94                 }
95         }
96 }
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。