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