1 31 package org.objectweb.proactive.examples.futurelist; 32 33 import org.apache.log4j.Logger; 34 import org.objectweb.proactive.ext.util.FutureList; 35 36 37 public class FutureReceiver implements java.io.Serializable { 38 39 static Logger logger = Logger.getLogger(FutureReceiver.class.getName()); 40 41 int etape = 0; BlockedObject blocked; 43 java.util.Vector waitingFutures = new java.util.Vector (); 44 FutureList futureList; 45 46 47 public FutureReceiver() { 48 } 49 50 51 public void getFuture() { 52 waitingFutures.add(blocked.createFuture()); 55 } 56 57 58 public void getFutureAndAddToFutureList() { 59 EmptyFuture f = blocked.createFuture(); 61 waitingFutures.add(f); 62 this.addToFutureList(f); 63 } 64 65 66 public void displayAllFutures() { 67 EmptyFuture temp; 68 69 for (java.util.Enumeration e = waitingFutures.elements(); e.hasMoreElements();) { 70 temp = (EmptyFuture)e.nextElement(); 71 logger.info("Result: " + temp.getName()); 72 } 73 } 74 75 public void unblockOtherObject() { 77 blocked.go(); 78 } 79 80 81 public void setBlockedObject(BlockedObject t) { 82 blocked = t; 83 } 84 85 86 89 public void createFutureList() { 90 org.objectweb.proactive.core.body.ActiveBody b = (org.objectweb.proactive.core.body.ActiveBody) org.objectweb.proactive.ProActive.getBodyOnThis(); 91 this.futureList = new FutureList(); 92 } 93 94 95 public void addToFutureList(Object o) { 96 this.futureList.add(o); 97 } 98 99 100 public void displayAwaited() { 101 if (futureList != null) { 102 logger.info("FutureReceiver: I am still waiting " + futureList.countAwaited() + " futures"); 103 } 104 } 105 106 107 public void displayAllAwaited() { 108 if (futureList != null) { 109 logger.info("FutureReceiver: I am waiting for all my futures: " + futureList.allAwaited()); 110 } 111 } 112 113 114 public void displayNoneAwaited() { 115 if (futureList != null) { 116 logger.info("FutureReceiver: I don't have any pending future: " + futureList.noneAwaited()); 117 } 118 } 119 120 121 public void waitAllFuture() { 122 if (futureList != null) { 123 logger.info("FutureReceiver: waiting all futures "); 124 futureList.waitAll(); 125 } 126 } 127 128 129 public void waitOneFuture() { 130 if (futureList != null) { 131 logger.info("FutureReceiver: waiting one future "); 132 futureList.waitOne(); 133 } 134 } 135 136 137 public void waitAndDisplayOneFuture() { 138 Object tmp; 139 if (futureList != null) { 140 tmp = futureList.waitAndRemoveOne(); 141 logger.info("I got this future: " + tmp); 142 } 143 } 144 145 146 public void waitAndDisplayAllFuture() { 147 if (futureList != null) { 148 this.waitAllFuture(); 149 this.displayAllFutures(); 150 } 152 } 153 154 public void unblockOtherObjectAndWaitAll() { 156 blocked.go(); 157 this.waitAllFuture(); 158 } 159 160 161 public void unblockOtherObjectAndWaitOne() { 162 blocked.go(); 163 this.waitOneFuture(); 164 } 165 } 166 | Popular Tags |