1 31 32 package org.objectweb.proactive.ext.util; 33 34 50 import org.objectweb.proactive.ProActive; 51 52 public class FutureList { 53 private java.util.Vector futureList; 54 55 56 public FutureList() { 57 futureList = new java.util.Vector (); 58 } 59 60 61 65 public boolean add(Object o) { 66 return this.futureList.add(o); 68 } 69 70 71 75 public boolean remove(Object o) { 76 return this.futureList.remove(o); 78 } 79 80 81 84 public int size() { 85 return this.futureList.size(); 86 } 87 88 89 92 public Object get(int index) { 93 return this.futureList.elementAt(index); 94 } 95 96 97 100 public boolean allAwaited() { 101 boolean value = true; 102 for (int i = 0; i < futureList.size(); i++) { 103 value = value && ProActive.isAwaited(futureList.elementAt(i)); 104 } 105 return value; 106 } 107 108 109 112 public boolean noneAwaited() { 113 for (int i = 0; i < futureList.size(); i++) { 114 if (ProActive.isAwaited(futureList.elementAt(i))) { 115 return false; 116 } 117 } 118 return true; 119 } 120 121 122 123 126 public int countAwaited() { 127 int count = 0; 128 for (int i = 0; i < futureList.size(); i++) { 129 if (ProActive.isAwaited(futureList.elementAt(i))) { 130 count++; 131 } 132 } 133 return count; 134 } 135 136 137 141 public Object getOne() { 142 if (this.countAwaited() == this.size()) { 143 return null; 146 } else { 147 Object temp; 148 for (int i = 0; i < futureList.size(); i++) { 149 temp = futureList.elementAt(i); 150 if (! ProActive.isAwaited(temp)) { 151 return temp; 152 } 153 } 154 return null; 155 } 156 } 157 158 159 163 public Object removeOne() { 164 Object tmp; 165 tmp = this.getOne(); 166 if (tmp != null) { 167 this.remove(tmp); 170 } 171 return tmp; 172 } 173 174 175 public Object waitAndGetOne() { 176 this.waitOne(); 177 return this.getOne(); 178 } 179 180 181 public Object waitAndRemoveOne() { 182 this.waitOne(); 183 return this.removeOne(); 184 } 185 186 187 public void waitAll() { 188 ProActive.waitForAll(futureList); 189 } 190 191 192 public void waitOne() { 193 ProActive.waitForAny(futureList); 194 } 195 196 public void waitN(int n) { 197 java.util.Vector temp = new java.util.Vector (futureList); 198 for (int i = 0; i < n ; i++) { 199 int index = ProActive.waitForAny(temp); 200 temp.remove(index); 201 } 202 } 203 204 public void waitTheNth (int n) { 205 ProActive.waitForTheNth(futureList,n); 206 } 207 208 public Object waitAndGetTheNth(int n) { 209 ProActive.waitForTheNth(futureList,n); 210 return this.futureList.elementAt(n); 211 } 212 213 } 214 | Popular Tags |