KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > examples > binarytree > Main


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.binarytree;
32
33 import org.apache.log4j.Logger;
34 import org.objectweb.proactive.core.config.ProActiveConfiguration;
35
36 public class Main {
37     
38     static Logger logger = Logger.getLogger(Main.class.getName());
39     
40     public static void main(String JavaDoc[] args) {
41         Main theMainActiveObject = null;
42         // Creates an active instance of this class
43
ProActiveConfiguration.load();
44         try {
45             theMainActiveObject = (Main)org.objectweb.proactive.ProActive.newActive(Main.class.getName(),
46                                                                                     null);
47         } catch (Exception JavaDoc e) {
48             logger.error(e);
49             System.exit(1);
50         }
51         // Asks it to perform the test
52
theMainActiveObject.doStuff();
53         return;
54     }
55
56     public void doStuff() {
57         BinaryTree myTree = null;
58         // This is the code for instanciating a passive version of the binary tree
59
// myTree = new BinaryTree ();
60
// This is the code for instanciating an active version of the binary tree
61
// If you want to test the pasive version of this test program, simply comment out
62
// the next line and comment in the line of code above
63
//
64
// * The first parameter means that we want to get an active instance of class org.objectweb.proactive.examples.binarytree.ActiveBinaryTree
65
// * The second parameter ('null') means we instancate this object through its empty (no-arg) constructor
66
// 'null' is actually a convenience for 'new Object [0]'
67
// * The last parameter 'null' means we want to instanciate this object in the current virtual machine
68
try {
69             // Object o = new org.objectweb.proactive.examples.binarytree.ActiveBinaryTree ();
70
myTree = (BinaryTree)org.objectweb.proactive.ProActive.newActive(ActiveBinaryTree.class.getName(),
71                                                                              null);
72         } catch (Exception JavaDoc e) {
73             logger.error(e);
74             e.printStackTrace();
75         }
76         // Now we insert 4 elements in the tree
77
// Note that this code is the same for the passive or active version of the tree
78
myTree.put(1, "one");
79         myTree.put(2, "two");
80         myTree.put(3, "three");
81         myTree.put(4, "four");
82         // Now we get all these 4 elements out of the tree
83
// method get in class BinaryTree returns a future object if
84
// myTree is an active object, but as System.out actually calls toString()
85
// on the future, the execution of each of the following 4 calls to System.out
86
// blocks until the future object is available.
87
ObjectWrapper tmp1 = myTree.get(3);
88         ObjectWrapper tmp2 = myTree.get(4);
89         ObjectWrapper tmp3 = myTree.get(2);
90         ObjectWrapper tmp4 = myTree.get(1);
91         logger.info("Value associated to key 1 is " + tmp4);
92         logger.info("Value associated to key 2 is " + tmp3);
93         logger.info("Value associated to key 3 is " + tmp1);
94         logger.info("Value associated to key 4 is " + tmp2);
95         logger.info("Use CTRL+C to stop the program");
96     }
97 }
Popular Tags