KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > examples > readers > ReaderDisplay


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.readers;
32
33 public class ReaderDisplay implements org.objectweb.proactive.InitActive {
34
35   private AppletReader applet;
36   private ReaderWriter rw;
37   private Reader readers[];
38   private Writer writers[];
39
40
41   public ReaderDisplay() {
42   }
43
44
45   public ReaderDisplay(AppletReader applet) {
46     this.applet = applet;
47   }
48
49
50   public void initActivity(org.objectweb.proactive.Body body) {
51     readers = new Reader[3];
52     writers = new Writer[3];
53
54     Object JavaDoc param[] = new Object JavaDoc[] {
55           org.objectweb.proactive.ProActive.getStubOnThis(),
56           new Integer JavaDoc(ReaderWriter.DEFAULT_POLICY)
57         };
58     try {
59       rw = (ReaderWriter)org.objectweb.proactive.ProActive.newActive(ReaderWriter.class.getName(), param);
60     } catch (Exception JavaDoc e) {
61       e.printStackTrace();
62     }
63
64     param = new Object JavaDoc[3];
65     param[0] = org.objectweb.proactive.ProActive.getStubOnThis();
66     param[1] = rw;
67     for (int i = 0; i < 3; i++) {
68       param[2] = new Integer JavaDoc(i);
69       try {
70         // Readers
71
readers[i] = (Reader)org.objectweb.proactive.ProActive.newActive(Reader.class.getName(), param);
72         // Writers
73
writers[i] = (Writer)org.objectweb.proactive.ProActive.newActive(Writer.class.getName(), param);
74       } catch (Exception JavaDoc e) {
75         e.printStackTrace();
76       }
77     }
78   }
79
80
81   public void setRead(int id, boolean state) {
82     applet.readerPanel.setRead(id, state);
83   }
84
85
86   public void setWait(int id, boolean isReader) {
87     applet.readerPanel.setWait(id, isReader);
88   }
89
90
91   public void setWrite(int id, boolean state) {
92     applet.readerPanel.setWrite(id, state);
93   }
94
95
96   public void setPolicy(int policy) {
97     if (policy < 3 && policy > -1)
98       rw.setPolicy(policy);
99   }
100 }
Popular Tags