00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 package org.objectweb.proactive.ext.util;
00032
00033
00050 import org.objectweb.proactive.ProActive;
00051
00052
00053 public class FutureList {
00054 private java.util.Vector<Object> futureList;
00055
00056 public FutureList() {
00057 futureList = new java.util.Vector<Object>();
00058 }
00059
00064 public boolean add(Object o) {
00065
00066 return this.futureList.add(o);
00067 }
00068
00073 public boolean remove(Object o) {
00074
00075 return this.futureList.remove(o);
00076 }
00077
00081 public int size() {
00082 return this.futureList.size();
00083 }
00084
00088 public Object get(int index) {
00089 return this.futureList.elementAt(index);
00090 }
00091
00095 public boolean allAwaited() {
00096 boolean value = true;
00097 for (int i = 0; i < futureList.size(); i++) {
00098 value = value && ProActive.isAwaited(futureList.elementAt(i));
00099 }
00100 return value;
00101 }
00102
00106 public boolean noneAwaited() {
00107 for (int i = 0; i < futureList.size(); i++) {
00108 if (ProActive.isAwaited(futureList.elementAt(i))) {
00109 return false;
00110 }
00111 }
00112 return true;
00113 }
00114
00118 public int countAwaited() {
00119 int count = 0;
00120 for (int i = 0; i < futureList.size(); i++) {
00121 if (ProActive.isAwaited(futureList.elementAt(i))) {
00122 count++;
00123 }
00124 }
00125 return count;
00126 }
00127
00132 public Object getOne() {
00133 if (this.countAwaited() == this.size()) {
00134
00135
00136 return null;
00137 } else {
00138 Object temp;
00139 for (int i = 0; i < futureList.size(); i++) {
00140 temp = futureList.elementAt(i);
00141 if (!ProActive.isAwaited(temp)) {
00142 return temp;
00143 }
00144 }
00145 return null;
00146 }
00147 }
00148
00153 public Object removeOne() {
00154 Object tmp;
00155 tmp = this.getOne();
00156 if (tmp != null) {
00157
00158
00159 this.remove(tmp);
00160 }
00161 return tmp;
00162 }
00163
00164 public Object waitAndGetOne() {
00165 this.waitOne();
00166 return this.getOne();
00167 }
00168
00169 public Object waitAndRemoveOne() {
00170 this.waitOne();
00171 return this.removeOne();
00172 }
00173
00174 public void waitAll() {
00175 ProActive.waitForAll(futureList);
00176 }
00177
00178 public void waitOne() {
00179 ProActive.waitForAny(futureList);
00180 }
00181
00182 public void waitN(int n) {
00183 java.util.Vector<Object> temp = new java.util.Vector<Object>(futureList);
00184 for (int i = 0; i < n; i++) {
00185 int index = ProActive.waitForAny(temp);
00186 temp.remove(index);
00187 }
00188 }
00189
00190 public void waitTheNth(int n) {
00191 ProActive.waitForTheNth(futureList, n);
00192 }
00193
00194 public Object waitAndGetTheNth(int n) {
00195 ProActive.waitForTheNth(futureList, n);
00196 return this.futureList.elementAt(n);
00197 }
00198 }