KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > examples > boundedbuffer > ActiveDisplay


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.boundedbuffer;
32
33 public class ActiveDisplay implements ConsumerProducerListener {
34
35   transient private AppletBuffer applet;
36   transient private BoundedBuffer buffer;
37   transient private Consumer consumer;
38   transient private Producer producer;
39   transient private int size;
40
41
42   public ActiveDisplay() {
43   }
44
45  
46   public ActiveDisplay(int size, AppletBuffer applet) {
47     //System.out.println("applet = " + applet);
48
this.applet = applet;
49     this.size = size;
50     displayMessage("Active display created");
51   }
52
53
54   public void start() {
55     displayMessage("ActiveDisplay start : Creating active objects");
56     
57     // Active objects creation
58
Object JavaDoc o = org.objectweb.proactive.ProActive.getStubOnThis();
59
60     // Active Buffer creation
61
try {
62       buffer = (BoundedBuffer)org.objectweb.proactive.ProActive.newActive(BoundedBuffer.class.getName(), new Object JavaDoc[]{new Integer JavaDoc(size), o});
63     } catch (Exception JavaDoc e) {
64     }
65
66     if (buffer == null) {
67       displayMessage("Error while creating active objects");
68       applet.kill();
69     }
70
71     // Producer
72
displayMessage("Creating producer...");
73     try {
74       producer = (Producer)org.objectweb.proactive.ProActive.newActive(Producer.class.getName(), new Object JavaDoc[]{o, buffer});
75     } catch (Exception JavaDoc e) {
76     }
77
78     // Consumer
79
displayMessage("Creating Consumer...");
80     try {
81       consumer = (Consumer)org.objectweb.proactive.ProActive.newActive(Consumer.class.getName(), new Object JavaDoc[]{o, buffer});
82     } catch (Exception JavaDoc e) {
83     }
84     displayMessage("Remote objects created...");
85   }
86
87
88   public void done() {
89     producer.done();
90     consumer.done();
91     producer = null;
92     consumer = null;
93     buffer = null;
94   }
95
96
97   public void update(int pos, String JavaDoc str) {
98     if (str == null) {
99       applet.setOut(pos, false);
100     } else {
101       applet.setIn(pos, false);
102     }
103     applet.setCell(pos, str);
104   }
105
106
107   public void toggleCons() {
108     applet.receiveMessage("toggle Consumer");
109     consumer.toggle();
110   }
111
112
113   public void toggleProd() {
114     displayMessage("toggle Producer");
115     producer.toggle();
116   }
117
118
119   public void setOut(int pos) {
120     applet.setOut(pos, true);
121   }
122
123
124   public void setIn(int pos) {
125     applet.setIn(pos, true);
126   }
127
128
129   //
130
// -- implements ConsumerProducerListener ----------------------------------------------------------------------
131
//
132
public void displayMessage(String JavaDoc msg) {
133     applet.receiveMessage(msg);
134   }
135
136
137   public void consumerStartRunning() {
138     applet.consumerStartRunning();
139   }
140
141
142   public void consumerStopRunning() {
143     applet.consumerStopRunning();
144   }
145
146
147   public void producerStartRunning() {
148     applet.producerStartRunning();
149   }
150
151
152   public void producerStopRunning() {
153     applet.producerStopRunning();
154   }
155 }
Popular Tags