1 package org.objectweb.proactive.ext.mixedlocation; 2 3 4 import org.objectweb.proactive.ext.locationserver.TimedRequestWithLocationServer; 5 6 import org.objectweb.proactive.core.body.UniversalBody; 7 import org.objectweb.proactive.core.body.future.FutureProxy; 8 import org.objectweb.proactive.core.mop.MethodCall; 9 import org.objectweb.proactive.core.mop.StubObject; 10 import org.objectweb.proactive.ext.locationserver.LocationServer; 11 12 13 public class TimedRequestWithMixedLocation 14 extends TimedRequestWithLocationServer { 15 16 private static final int MAX_TRIES = 30; 17 private static int counter = 0; 18 private int tries; 19 transient protected LocationServer server; 20 protected long startTime; 21 22 public TimedRequestWithMixedLocation(MethodCall methodCall, 23 UniversalBody sender, boolean isOneWay, 24 long nextSequenceID, 25 LocationServer server) { 26 super(methodCall, sender, isOneWay, nextSequenceID, server); 27 } 28 29 protected void sendRequest(UniversalBody destinationBody) 30 throws java.io.IOException { 31 System.out.println( 32 "RequestWithMixedLocation: sending to universal " + counter); 33 try { 34 destinationBody.receiveRequest(this); 35 } catch (Exception e) { 36 this.backupSolution(destinationBody); 38 } 39 } 40 41 44 protected void backupSolution(UniversalBody destinationBody) 45 throws java.io.IOException { 46 47 boolean ok = false; 48 tries = 0; 49 System.out.println( 50 "RequestWithMixedLocationr: backupSolution() contacting server " + 51 server); 52 System.out.println( 53 "RequestWithMixedLocation.backupSolution() : looking for " + 54 destinationBody); 55 while (!ok && (tries < MAX_TRIES)) { 57 58 UniversalBody mobile = (UniversalBody)server.searchObject(destinationBody.getID()); 59 System.out.println( 60 "RequestWithMixedLocation: backupSolution() server has sent an answer"); 61 62 UniversalBody newDestinationBody = (UniversalBody)((FutureProxy)((StubObject)mobile).getProxy()).getResult(); 64 try { 68 newDestinationBody.receiveRequest(this); 70 System.out.println( 73 "RequestWithMixedLocation: backupSolution() updating location"); 74 if (sender != null) { 75 sender.updateLocation(newDestinationBody.getID(), 76 newDestinationBody.getRemoteAdapter()); 77 } 78 ok = true; 79 } catch (Exception e) { 80 System.out.println( 81 "RequestWithMixedLocation: backupSolution() failed"); 82 tries++; 83 try { 84 Thread.sleep(500); 85 } catch (Exception e2) { 86 e2.printStackTrace(); 87 } 88 } 89 } 90 } 91 } | Popular Tags |