1 26 27 28 import org.objectweb.mobilitools.smi.api.*; 29 import org.objectweb.mobilitools.smi.api.Agency; 30 import org.objectweb.mobilitools.smi.goodies.*; 31 32 33 41 public class EscapeAgent extends BasicMobileObject 42 { 43 Name my_name; 44 45 46 public EscapeAgent() 47 { 48 } 49 50 51 public void afterBirth(AgentSystem agency, AgentInfo entry, Object argument) 52 throws BadOperation 53 { 54 super.afterBirth(agency, entry, argument); 55 my_name = entry.getName(); 56 } 57 58 59 62 public synchronized void beforeShutdown() 63 { 64 try 65 { 66 Location[] locations = (new RegionManager(my_agency.getORB())).listAgencies(my_agency.getRegion(), null); 67 if (locations.length > 0) 68 { 69 System.out.println(my_name + " is escaping to agency " + locations[0]); 70 try 71 { 72 my_agency.moveLocalAgent(this, locations[0], "anyplace"); 73 } 74 catch (BadOperation e) 75 { 76 System.err.println(e.getMessage()); 77 } 78 } 79 else 80 { 81 System.out.println("No agency available - " + my_name + " giving up."); 82 } 83 } 84 catch (Exception e) 85 { 86 System.err.println("Can't get another agency - " + my_name + " giving up on exception:\n" + e.toString()); 87 } 88 } 89 90 91 public void beforeDeath() 92 { 93 System.out.println(my_name + " is dead."); 94 } 95 } 96 | Popular Tags |