KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > examples > garden > Flower


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.garden;
32
33 import org.apache.log4j.Logger;
34 import org.objectweb.proactive.core.config.ProActiveConfiguration;
35
36
37 /**
38  * <p>
39  * Simple example that creates flower objects in different nodes
40  * (virtual machines) and passes remote references between them. When
41  * one flower object receives a reference of another flower it
42  * displays its name and the name of the remote reference.
43  * </p>
44  *
45  * @author ProActive Team
46  * @version 1.0, 2001/10/23
47  * @since ProActive 0.9
48  *
49  */

50 public class Flower {
51     
52     static Logger logger = Logger.getLogger(Flower.class.getName());
53
54   private String JavaDoc myName;
55
56   public Flower() {
57     super();
58   }
59
60
61   public Flower(String JavaDoc name) {
62     this.myName = name;
63     logger.info("I am flower " + this.myName + " just been created");
64   }
65
66
67   public String JavaDoc getName() {
68     return this.myName;
69   }
70
71
72   public void acceptReference(Flower f) {
73     logger.info("I am flower " + this.myName + " and I received a reference on flower " + f.getName());
74   }
75   
76   public int bob() {
77     return 90;
78   }
79
80
81   public static void main(String JavaDoc[] args) {
82     ProActiveConfiguration.load();
83     try {
84       // It's springtime ! Let's create flowers everywhere !
85
String JavaDoc nodeName1 = "///vm1";
86       String JavaDoc nodeName2 = "///vm2";
87       if (args.length >= 1) nodeName1 = args[0];
88       if (args.length >= 2) nodeName2 = args[1];
89       logger.info("Node 1 : "+nodeName1);
90       logger.info("Node 2 : "+nodeName2);
91       Flower a = (Flower)org.objectweb.proactive.ProActive.newActive(Flower.class.getName(), new Object JavaDoc[]{"Amaryllis - LOCAL"});
92       Flower b = (Flower)org.objectweb.proactive.ProActive.newActive(Flower.class.getName(), new Object JavaDoc[]{"Bouton d'Or - LOCAL"});
93       Flower c = (Flower)org.objectweb.proactive.ProActive.newActive(Flower.class.getName(), new Object JavaDoc[]{"Coquelicot - vm1"}, nodeName1);
94       Flower d = (Flower)org.objectweb.proactive.ProActive.newActive(Flower.class.getName(), new Object JavaDoc[]{"Daliah - vm1"}, nodeName1);
95       Flower e = (Flower)org.objectweb.proactive.ProActive.newActive(Flower.class.getName(), new Object JavaDoc[]{"Eglantine - vm2"}, nodeName2);
96       Flower f = (Flower)org.objectweb.proactive.ProActive.newActive(Flower.class.getName(), new Object JavaDoc[]{"Rose - vm2"}, nodeName2);
97       // Now let's test all setups
98
// It is understood that all flowers are active objects
99

100       // Pass a local Flower to a local Flower
101
a.acceptReference(b);
102   
103       // Pass a local Flower to a remote Flower
104
d.acceptReference(b);
105   
106       // Pass a remote Flower to a local Flower
107
a.acceptReference(c);
108   
109       // Pass a remote Flower to a remote Flower
110
e.acceptReference(c);
111   
112       // Special case : pass a remote Flower to a remote Flower
113
// When both flowers actually sit on the same host, and this
114
// host is different from the local host
115
e.acceptReference(f);
116     } catch (Exception JavaDoc e) {
117       e.printStackTrace();
118     } finally {
119       try {
120         Thread.sleep(1000);
121       } catch (InterruptedException JavaDoc e) {
122       }
123       System.exit(0);
124     }
125   }
126 }
Popular Tags