1 31 package org.objectweb.proactive.examples.migration; 32 33 34 35 import org.apache.log4j.Logger; 36 import org.objectweb.proactive.Body; 37 import org.objectweb.proactive.EndActive; 38 import org.objectweb.proactive.InitActive; 39 import org.objectweb.proactive.ProActive; 40 import org.objectweb.proactive.RunActive; 41 42 45 public class Agent implements InitActive, RunActive, EndActive, java.io.Serializable { 46 47 static Logger logger = Logger.getLogger(Agent.class.getName()); 48 private String name; 49 private String nodename; 50 private String hostname; 51 52 public Agent() { 53 } 54 55 public Agent(String name) { 56 this.name = name; 57 } 58 59 public String getName() { 60 try { 61 return java.net.InetAddress.getLocalHost().getCanonicalHostName().toUpperCase(); 64 } catch (Exception e) { 65 e.printStackTrace(); 66 return "getName failed"; 67 } 68 69 } 70 71 public String getNodeName() { 72 try { 73 return ProActive.getBodyOnThis().getNodeURL().toUpperCase(); 76 } catch (Exception e) { 77 e.printStackTrace(); 78 return "getNodeName failed"; 79 } 80 } 81 82 public void moveTo(String nodeURL) throws Exception { 83 logger.info(" I am going to migate"); 85 ProActive.migrateTo(nodeURL); 86 } 91 92 public void endBodyActivity() { 93 ProActive.getBodyOnThis().terminate(); 94 } 95 96 public void initActivity(Body body) { 97 logger.info("Initialization of the Activity"); 98 } 99 100 public void runActivity(Body body) { 101 org.objectweb.proactive.Service service = new org.objectweb.proactive.Service(body); 102 while (body.isActive()) { 103 service.blockingServeOldest(); 105 } 111 } 112 113 public void endActivity(Body body) { 114 logger.info("End of the activity of this Active Object"); 115 } 116 } 117 | Popular Tags |