1 31 32 package org.objectweb.proactive.core.body.future; 33 34 import org.objectweb.proactive.core.ProActiveRuntimeException; 35 import org.objectweb.proactive.core.UniqueID; 36 import org.objectweb.proactive.core.body.UniversalBody; 37 38 45 public class FutureMap extends Object implements java.io.Serializable { 46 47 private java.util.HashMap indexedByBodyID; 49 50 54 public FutureMap() { 55 indexedByBodyID = new java.util.HashMap (); 56 } 57 58 65 public synchronized void addAutomaticContinuation(long id, UniqueID creatorID, UniversalBody bodyDest) { 66 java.util.HashMap indexedByID = (java.util.HashMap ) (indexedByBodyID.get(creatorID)); 67 if (indexedByID == null) 68 throw new ProActiveRuntimeException("There is no map for creatorID " + creatorID); 69 java.util.ArrayList [] listes = (java.util.ArrayList []) (indexedByID.get(new Long (id))); 70 if (listes != null) 72 listes[1].add(bodyDest); 73 else 74 throw new ProActiveRuntimeException("There is no list for future " + id); 75 } 76 77 84 public synchronized void receiveFuture(Future futureObject) { 85 long id = futureObject.getID(); 86 UniqueID creatorID = futureObject.getCreatorID(); 87 java.util.HashMap indexedByID = (java.util.HashMap ) (indexedByBodyID.get(creatorID)); 88 89 if (indexedByID == null) { 91 92 java.util.HashMap newIndexedByID = new java.util.HashMap (); 94 java.util.ArrayList futures = new java.util.ArrayList (); 96 futures.add(futureObject); 97 java.util.ArrayList dests = new java.util.ArrayList (); 99 100 java.util.ArrayList [] listes = new java.util.ArrayList [2]; 101 listes[0] = futures; 102 listes[1] = dests; 103 newIndexedByID.put(new Long (id), listes); 104 indexedByBodyID.put(creatorID, newIndexedByID); 105 } 106 else if (indexedByID.get(new Long (id)) == null) { 108 109 java.util.ArrayList futures = new java.util.ArrayList (); 111 futures.add(futureObject); 112 java.util.ArrayList dests = new java.util.ArrayList (); 114 115 java.util.ArrayList [] listes = new java.util.ArrayList [2]; 116 listes[0] = futures; 117 listes[1] = dests; 118 indexedByID.put(new Long (id), listes); 119 } 120 else { 122 (((java.util.ArrayList []) (indexedByID.get(new Long (id))))[0]).add(futureObject); 123 } 124 } 125 126 131 public synchronized java.util.ArrayList getFuturesToUpdate(long id, UniqueID creatorID) { 132 java.util.HashMap indexedByID = (java.util.HashMap ) (indexedByBodyID.get(creatorID)); 133 java.util.ArrayList resultat = null; 134 135 if (indexedByID != null) { 136 java.util.ArrayList [] listes = (java.util.ArrayList []) (indexedByID.get(new Long (id))); 137 138 if (listes != null) { 139 java.util.ArrayList futures = listes[0]; 140 resultat = futures; 141 } 142 } 143 return resultat; 147 148 } 149 150 155 public synchronized java.util.ArrayList getAutomaticContinuation(long id, UniqueID bodyID) { 156 java.util.ArrayList resultat = null; 157 java.util.HashMap indexedByID = (java.util.HashMap ) (indexedByBodyID.get(bodyID)); 158 if (indexedByID != null) { 159 java.util.ArrayList [] listes = (java.util.ArrayList []) (indexedByID.get(new Long (id))); 160 if (listes != null) { 161 resultat = listes[1]; 162 } 163 } 164 return resultat; 165 166 } 167 168 173 public synchronized void removeFutures(long id, UniqueID creatorID) { 174 java.util.HashMap indexedByID = (java.util.HashMap ) (indexedByBodyID.get(creatorID)); 175 if (indexedByID != null) { 176 java.util.ArrayList [] listes = (java.util.ArrayList []) (indexedByID.remove(new Long (id))); 177 } 178 } 179 180 181 182 186 public synchronized void unsetMigrationTag() { 187 java.util.Collection c1 = indexedByBodyID.values(); 188 java.util.Iterator it1 = c1.iterator(); 189 190 while (it1.hasNext()) { 191 java.util.Collection c2 = ((java.util.HashMap ) (it1.next())).values(); 192 java.util.Iterator it2 = c2.iterator(); 193 while (it2.hasNext()) { 194 java.util.ArrayList [] listes = (java.util.ArrayList []) (it2.next()); 195 java.util.ArrayList futures = listes[0]; 196 java.util.Iterator itFutures = futures.iterator(); 197 while (itFutures.hasNext()) { 198 FutureProxy p = (FutureProxy) itFutures.next(); 199 p.unsetMigrationTag(); 200 } 201 } 202 } 203 } 204 205 209 public synchronized void setMigrationTag() { 210 java.util.Collection c1 = indexedByBodyID.values(); 211 java.util.Iterator it1 = c1.iterator(); 212 213 while (it1.hasNext()) { 214 java.util.Collection c2 = ((java.util.HashMap ) (it1.next())).values(); 215 java.util.Iterator it2 = c2.iterator(); 216 while (it2.hasNext()) { 217 java.util.ArrayList [] listes = (java.util.ArrayList []) (it2.next()); 218 java.util.ArrayList futures = listes[0]; 219 java.util.Iterator itFutures = futures.iterator(); 220 while (itFutures.hasNext()) { 221 FutureProxy p = (FutureProxy) itFutures.next(); 222 p.setMigrationTag(); 223 } 224 } 225 } 226 } 227 228 229 } 230 | Popular Tags |