1 31 package org.objectweb.proactive.ext.mixedlocation; 32 33 import org.apache.log4j.Logger; 34 35 import org.objectweb.proactive.ProActive; 36 import org.objectweb.proactive.core.UniqueID; 37 import org.objectweb.proactive.core.body.LocalBodyStore; 38 import org.objectweb.proactive.core.body.UniversalBody; 39 import org.objectweb.proactive.core.body.future.FutureProxy; 40 import org.objectweb.proactive.core.body.request.RequestImpl; 41 import org.objectweb.proactive.core.mop.MethodCall; 42 import org.objectweb.proactive.core.mop.StubObject; 43 import org.objectweb.proactive.ext.locationserver.LocationServer; 44 import org.objectweb.proactive.ext.locationserver.LocationServerFactory; 45 46 47 public class RequestWithMixedLocation extends RequestImpl 48 implements java.io.Serializable { 49 static Logger logger = Logger.getLogger(RequestWithMixedLocation.class.getName()); 50 private static final int MAX_TRIES = 15; 51 private static int counter = 0; 52 private int tries; 53 transient protected LocationServer server; 54 55 public RequestWithMixedLocation(MethodCall methodCall, 56 UniversalBody sender, boolean isOneWay, long nextSequenceID, 57 LocationServer server) { 58 super(methodCall, sender, isOneWay, nextSequenceID); 59 if (logger.isDebugEnabled()) { 60 logger.debug("RequestWithMixedLocation.RequestWithMixedLocation " + 61 ++counter); 62 } 63 this.server = server; 64 } 65 66 protected void sendRequest(UniversalBody destinationBody) 67 throws java.io.IOException { 68 if (logger.isDebugEnabled()) { 69 logger.debug("RequestWithMixedLocation: sending to universal " + 70 counter); 71 } 72 try { 73 destinationBody.receiveRequest(this); 74 } catch (Exception e) { 75 this.backupSolution(destinationBody); 76 } 77 } 78 79 82 protected void backupSolution(UniversalBody destinationBody) 83 throws java.io.IOException { 84 boolean ok = false; 85 tries = 0; 86 UniqueID bodyID = destinationBody.getID(); 88 while (!ok && (tries < MAX_TRIES)) { 89 UniversalBody remoteBody = null; 90 UniversalBody mobile = queryServer(bodyID); 91 92 remoteBody = (UniversalBody) ((FutureProxy) ((StubObject) mobile).getProxy()).getResult(); 94 95 try { 96 remoteBody.receiveRequest(this); 97 98 if (sender != null) { 101 sender.updateLocation(bodyID, remoteBody); 102 } else { 103 LocalBodyStore.getInstance().getLocalBody(getSourceBodyID()) 104 .updateLocation(bodyID, remoteBody); 105 } 106 ok = true; 107 } catch (Exception e) { 108 logger.error("FAILED = " + " for method " + methodName); 109 tries++; 110 } 111 } 112 } 113 114 protected UniversalBody queryServer(UniqueID bodyID) { 115 if (server == null) { 116 server = LocationServerFactory.getLocationServer(); 117 } 118 UniversalBody mobile = (UniversalBody) server.searchObject(bodyID); 119 logger.debug("backupSolution() server has sent an answer"); 120 ProActive.waitFor(mobile); 121 return mobile; 122 } 123 } 124 | Popular Tags |