KickJava   Java API By Example, From Geeks To Geeks.

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


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 public class TestBT {
34
35   public static void main(String JavaDoc[] args) {
36     BinaryTree myTree = new BinaryTree(); // Instantiating a standard version
37
// To get an active version, just comment the line above,
38
// and comment out the line below
39
// myTree = (BinaryTree) Proactive.newActive("ActiveBinaryTree", null, null);
40
// * First parameter: get an active instance of class ActiveBTree
41
// * Second ('null'): instantiates with empty (no-arg) constructor
42
// 'null' is a convenience for 'new Object [0]'
43
// * Last ('null'): instantiates this object on the current host,
44
// within the current virtual machine
45
// Use either standard or active versions through polymorphism
46
TestBT.useBTree(myTree);
47   }
48   // Note that this code is the same for the passive or active version of the tree
49

50   protected static void useBTree(BinaryTree bt) {
51     ObjectWrapper s1;
52     ObjectWrapper s2;
53     bt.put(1, "one"); // We insert 4 elements in the tree, non-blocking
54
bt.put(2, "two");
55     bt.put(3, "three");
56     bt.put(4, "four");
57     // Now we get all these 4 elements out of the tree
58
// method get in class BinaryTree returns a future object if
59
// bt is an active object, but as System.out actually calls toString()
60
// on the future, the execution of each of the following 4 calls
61
// to System.out blocks until the future object is available.
62
System.out.println("Value associated to key 2 is " + bt.get(2));
63     System.out.println("Value associated to key 1 is " + bt.get(1));
64     System.out.println("Value associated to key 3 is " + bt.get(3));
65     System.out.println("Value associated to key 4 is " + bt.get(4));
66     // When using variables, all the instructions are non-blocking
67
bt.put(2, "twoBis");
68     s2 = bt.get(2); // non-blocking
69
bt.put(2, "twoTer");
70     s2 = bt.get(2); // non-blocking
71
s1 = bt.get(1); // non-blocking
72
// Blocking operations
73
System.out.println("Value associated to key 2 is " + s2); // prints "twoTer"
74
System.out.println("Value associated to key 1 is " + s1); // prints "one"
75
}
76 }
Popular Tags