1 31 package org.objectweb.proactive.examples.hello; 32 33 34 import org.apache.log4j.Logger; 35 import org.objectweb.proactive.ProActive; 36 import org.objectweb.proactive.core.config.ProActiveConfiguration; 37 38 public class SimpleAgent implements java.io.Serializable { 39 40 static Logger logger = Logger.getLogger(SimpleAgent.class.getName()); 41 42 public SimpleAgent() { 43 } 44 45 public void moveTo(String t) { 46 try { 47 logger.info("Avant la migration "); 48 ProActive.migrateTo(t); 49 logger.info("Apres la migration je suis sur "+whereAreYou()); 50 } catch (Exception e) { 51 e.printStackTrace(); 52 } 53 } 54 55 public String whereAreYou() { 56 try { 57 return java.net.InetAddress.getLocalHost().getCanonicalHostName(); 58 } catch (Exception e) { 59 return "Localhost lookup failed"; 60 } 61 } 62 63 public static void main (String [] args) { 64 if (!(args.length>0)) { 65 logger.info("Usage: java org.objectweb.proactive.examples.hello.SimpleAgent hostname/NodeName "); 66 System.exit(-1); 67 } 68 69 ProActiveConfiguration.load(); 70 SimpleAgent t = null; 71 try { 72 t = (SimpleAgent) ProActive.newActive("org.objectweb.proactive.examples.hello.SimpleAgent",null); 74 } catch (Exception e) { 75 e.printStackTrace(); 76 } 77 logger.info("Je migre depuis " + t.whereAreYou()); 80 t.moveTo(args[0]); 81 logger.info("The Active Object is now on host (j'suis ici) : " + t.whereAreYou()); 82 } 83 } 84 | Popular Tags |