KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > examples > futurelist > TestFutureList


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.futurelist;
32
33 import org.objectweb.proactive.core.config.ProActiveConfiguration;
34
35 public class TestFutureList {
36
37   public TestFutureList() {
38     super();
39   }
40
41
42   public static void main(String JavaDoc[] args) {
43     BlockedObject blockedO = null;
44     FutureReceiver tf = null;
45
46     if (args.length < 2) {
47       System.err.println("Usage: TestFutureList hostName1/nodeName1 hostName2/nodeName2");
48       System.exit(-1);
49     }
50     ProActiveConfiguration.load();
51
52     System.out.println("This is designed to test the use of the future list");
53
54     try {
55       blockedO = (BlockedObject)org.objectweb.proactive.ProActive.newActive(BlockedObject.class.getName(), null, args[0]);
56       tf = (FutureReceiver)org.objectweb.proactive.ProActive.newActive(FutureReceiver.class.getName(), null, args[1]);
57     } catch (Exception JavaDoc e) {
58       e.printStackTrace();
59     }
60
61
62     //we pass the reference to our blocked object
63
tf.setBlockedObject(blockedO);
64
65     //and ask the creation of a future list
66
tf.createFutureList();
67
68     //now we start the future request
69
//thus creating futures un tf
70
tf.getFutureAndAddToFutureList();
71     tf.getFutureAndAddToFutureList();
72     tf.getFutureAndAddToFutureList();
73     tf.getFutureAndAddToFutureList();
74
75     System.out.println("*** Sleeping for 5 seconds");
76
77     try {
78       Thread.sleep(5000);
79     } catch (Exception JavaDoc e) {
80       e.printStackTrace();
81     }
82
83     tf.displayAwaited();
84     tf.displayAllAwaited();
85     tf.displayNoneAwaited();
86
87     System.out.println("*** Sleeping for 1 seconds");
88     try {
89       Thread.sleep(1000);
90     } catch (Exception JavaDoc e) {
91       e.printStackTrace();
92     }
93
94     System.out.println("*** Asking the reply to the futures");
95     //tf.unblockOtherObjectAndWaitAll();
96

97     //tf.unblockOtherObjectAndWaitOne();
98
tf.unblockOtherObject();
99     tf.waitAndDisplayAllFuture();
100     // tf.waitAndDisplayOneFuture();
101
// tf.waitAndDisplayOneFuture();
102
// tf.waitAndDisplayOneFuture();
103
// tf.waitAndDisplayOneFuture();
104
//tf.waitAllFuture();
105
System.out.println("*** Sleeping for 5 seconds");
106     try {
107       Thread.sleep(5000);
108     } catch (Exception JavaDoc e) {
109       e.printStackTrace();
110     }
111
112     tf.displayAwaited();
113     tf.displayAllAwaited();
114     tf.displayNoneAwaited();
115     tf.displayAllFutures();
116     // //now we ask for the display of the futures
117
try {
118       Thread.sleep(5000);
119     } catch (Exception JavaDoc e) {
120       e.printStackTrace();
121     }
122
123     System.out.println("*** Test over");
124   }
125 }
126
Popular Tags