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.core.body.future;
00032
00033 import java.util.ArrayList;
00034 import java.util.HashMap;
00035
00036 import org.objectweb.proactive.core.ProActiveRuntimeException;
00037 import org.objectweb.proactive.core.UniqueID;
00038 import org.objectweb.proactive.core.body.UniversalBody;
00039
00040
00048 public class FutureMap extends Object implements java.io.Serializable {
00049
00050 private java.util.HashMap<UniqueID, HashMap<Long, ArrayList[]>> indexedByBodyID;
00051
00052
00053
00054
00055 public FutureMap() {
00056 indexedByBodyID = new java.util.HashMap<UniqueID, HashMap<Long, ArrayList[]>>();
00057 }
00058
00066 public synchronized void addAutomaticContinuation(long id,
00067 UniqueID creatorID, UniversalBody bodyDest) {
00068 java.util.HashMap indexedByID = (indexedByBodyID.get(creatorID));
00069 if (indexedByID == null) {
00070 throw new ProActiveRuntimeException(
00071 "There is no map for creatorID " + creatorID);
00072 }
00073 java.util.ArrayList[] listes = (java.util.ArrayList[]) (indexedByID.get(new Long(
00074 id)));
00075
00076
00077 if (listes != null) {
00078 listes[1].add(bodyDest);
00079 } else {
00080 throw new ProActiveRuntimeException("There is no list for future " +
00081 id);
00082 }
00083 }
00084
00090 public synchronized void receiveFuture(Future futureObject) {
00091 long id = futureObject.getID();
00092 UniqueID creatorID = futureObject.getCreatorID();
00093 java.util.HashMap<Long, ArrayList[]> indexedByID = (indexedByBodyID.get(creatorID));
00094
00095
00096 if (indexedByID == null) {
00097
00098 java.util.HashMap<Long, ArrayList[]> newIndexedByID = new java.util.HashMap<Long, ArrayList[]>();
00099
00100
00101 java.util.ArrayList<Future> futures = new java.util.ArrayList<Future>();
00102 futures.add(futureObject);
00103
00104 java.util.ArrayList<Future> dests = new java.util.ArrayList<Future>();
00105
00106 java.util.ArrayList[] listes = new java.util.ArrayList[2];
00107 listes[0] = futures;
00108 listes[1] = dests;
00109 newIndexedByID.put(new Long(id), listes);
00110 indexedByBodyID.put(creatorID, newIndexedByID);
00111 }
00112
00113 else if (indexedByID.get(new Long(id)) == null) {
00114
00115 java.util.ArrayList<Future> futures = new java.util.ArrayList<Future>();
00116 futures.add(futureObject);
00117
00118 java.util.ArrayList<Future> dests = new java.util.ArrayList<Future>();
00119
00120 java.util.ArrayList[] listes = new java.util.ArrayList[2];
00121 listes[0] = futures;
00122 listes[1] = dests;
00123 indexedByID.put(new Long(id), listes);
00124 }
00125
00126 else {
00127 ((indexedByID.get(new Long(id)))[0]).add(futureObject);
00128 }
00129 }
00130
00136 public synchronized java.util.ArrayList getFuturesToUpdate(long id,
00137 UniqueID creatorID) {
00138 java.util.HashMap indexedByID = (indexedByBodyID.get(creatorID));
00139 java.util.ArrayList resultat = null;
00140
00141 if (indexedByID != null) {
00142 java.util.ArrayList[] listes = (java.util.ArrayList[]) (indexedByID.get(new Long(
00143 id)));
00144
00145 if (listes != null) {
00146 java.util.ArrayList futures = listes[0];
00147 resultat = futures;
00148 }
00149 }
00150
00151
00152
00153
00154 return resultat;
00155 }
00156
00162 public synchronized java.util.ArrayList getAutomaticContinuation(long id,
00163 UniqueID bodyID) {
00164 java.util.ArrayList resultat = null;
00165 java.util.HashMap indexedByID = (indexedByBodyID.get(bodyID));
00166 if (indexedByID != null) {
00167 java.util.ArrayList[] listes = (java.util.ArrayList[]) (indexedByID.get(new Long(
00168 id)));
00169 if (listes != null) {
00170 resultat = listes[1];
00171 }
00172 }
00173 return resultat;
00174 }
00175
00181 public synchronized void removeFutures(long id, UniqueID creatorID) {
00182 java.util.HashMap indexedByID = (indexedByBodyID.get(creatorID));
00183 if (indexedByID != null) {
00184 java.util.ArrayList[] listes = (java.util.ArrayList[]) (indexedByID.remove(new Long(
00185 id)));
00186 }
00187 }
00188
00189
00190
00191
00192
00193 public synchronized void unsetMigrationTag() {
00194 java.util.Collection<HashMap<Long, ArrayList[]>> c1 = indexedByBodyID.values();
00195 java.util.Iterator<HashMap<Long, ArrayList[]>> it1 = c1.iterator();
00196
00197 while (it1.hasNext()) {
00198 java.util.Collection c2 = (it1.next()).values();
00199 java.util.Iterator it2 = c2.iterator();
00200 while (it2.hasNext()) {
00201 java.util.ArrayList[] listes = (java.util.ArrayList[]) (it2.next());
00202 java.util.ArrayList futures = listes[0];
00203 java.util.Iterator itFutures = futures.iterator();
00204 while (itFutures.hasNext()) {
00205 FutureProxy p = (FutureProxy) itFutures.next();
00206 p.unsetMigrationTag();
00207 }
00208 }
00209 }
00210 }
00211
00216 public synchronized void setMigrationTag() {
00217 java.util.Collection<HashMap<Long, ArrayList[]>> c1 = indexedByBodyID.values();
00218 java.util.Iterator<HashMap<Long, ArrayList[]>> it1 = c1.iterator();
00219
00220 while (it1.hasNext()) {
00221 java.util.Collection c2 = (it1.next()).values();
00222 java.util.Iterator it2 = c2.iterator();
00223 while (it2.hasNext()) {
00224 java.util.ArrayList[] listes = (java.util.ArrayList[]) (it2.next());
00225 java.util.ArrayList futures = listes[0];
00226 java.util.Iterator itFutures = futures.iterator();
00227 while (itFutures.hasNext()) {
00228 FutureProxy p = (FutureProxy) itFutures.next();
00229 p.setMigrationTag();
00230 }
00231 }
00232 }
00233 }
00234 }