KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > examples > hello > SimpleAgent


1 /*
2 * ################################################################
3 *
4 * ProActive: The Java(TM) library for Parallel, Distributed,
5 * Concurrent computing with Security and Mobility
6 *
7 * Copyright (C) 1997-2002 INRIA/University of Nice-Sophia Antipolis
8 * Contact: proactive-support@inria.fr
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 * USA
24 *
25 * Initial developer(s): The ProActive Team
26 * http://www.inria.fr/oasis/ProActive/contacts.html
27 * Contributor(s):
28 *
29 * ################################################################
30 */

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 JavaDoc {
39     
40     static Logger logger = Logger.getLogger(SimpleAgent.class.getName());
41
42   public SimpleAgent() {
43   }
44
45   public void moveTo(String JavaDoc 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 JavaDoc e) {
51       e.printStackTrace();
52     }
53   }
54
55   public String JavaDoc whereAreYou() {
56     try {
57       return java.net.InetAddress.getLocalHost().getCanonicalHostName();
58     } catch (Exception JavaDoc e) {
59       return "Localhost lookup failed";
60     }
61   }
62
63   public static void main (String JavaDoc[] 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       // create the SimpleAgent in this JVM
73
t = (SimpleAgent) ProActive.newActive("org.objectweb.proactive.examples.hello.SimpleAgent",null);
74     } catch (Exception JavaDoc e) {
75       e.printStackTrace();
76     }
77     // migrate the SimpleAgent to the location identified by the given node URL
78
// we assume here that the node does already exist
79
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