KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > DiningPhilosophers > monolithic > ObserverImpl


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2002 USTL - LIFL - GOAL
5 Contact: openccm-team@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Philippe Merle, Sylvain Leblanc.
23 Contributor(s): Christophe Demarey.
24
25 ====================================================================*/

26
27 package DiningPhilosophers.monolithic;
28
29 import DiningPhilosophers.*;
30
31 /**
32  * This is the implementation of the OMG IDL3 DiningPhilosophers::Observer
33  * component type.
34  *
35  * The info event sink is directly implemented
36  * by the component class by implementing the
37  * DiningPhilosophers::StatusInfoConsumer interface.
38  *
39  * This class inherits from the local CCM_Observer interface
40  * generated by the OpenCCM's IDL3 to IDL2 mapping generator.
41  *
42  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
43  * @author <a HREF="mailto:Sylvain.Leblanc@lifl.fr">Sylvain Leblanc</a>
44  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
45  *
46  * @version 2.0
47  */

48
49 public class ObserverImpl
50      extends org.omg.CORBA.LocalObject JavaDoc
51   implements CCM_Observer,
52              CCM_StatusInfoConsumer,
53              org.omg.Components.SessionComponent
54 {
55     // ==================================================================
56
//
57
// Internal state.
58
//
59
// ==================================================================
60

61     /** The CCM Observer context. */
62     private CCM_Observer_Context the_context_;
63
64     /** Stores philosopher's states. */
65     private java.util.Hashtable JavaDoc philosopherStates_;
66
67     /** The main GUI. */
68     private javax.swing.JFrame JavaDoc frame_;
69
70     /** The philosopher's panels. */
71     private java.util.Hashtable JavaDoc philosopherPanels_;
72
73     /** The box panel used to store philosopher's panel GUI. */
74     private javax.swing.Box JavaDoc box_;
75
76     // ==================================================================
77
//
78
// Constructor.
79
//
80
// ==================================================================
81

82     /** The default constructor. */
83     public
84     ObserverImpl()
85     {
86         philosopherStates_ = new java.util.Hashtable JavaDoc();
87         philosopherPanels_ = new java.util.Hashtable JavaDoc();
88     }
89
90     // ==================================================================
91
//
92
// Internal methods.
93
//
94
// ==================================================================
95

96     // ==================================================================
97
//
98
// Public methods.
99
//
100
// ==================================================================
101

102     // ==================================================================
103
//
104
// Methods for OMG IDL Components::EnterpriseComponent
105
//
106
// ==================================================================
107

108     /**
109      * Complete the component configuration and launch the
110      * observer GUI.
111      *
112      * @exception org.omg.Components.InvalidConfiguration
113      * Thrown if the configuration is invalid.
114      */

115     public void
116     configuration_complete()
117     throws org.omg.Components.InvalidConfiguration
118     {
119         // Instantiating the GUI.
120

121         // Creates a Swing Frame.
122
frame_ = new javax.swing.JFrame JavaDoc("The Observer's GUI");
123         // Sets its size.
124
frame_.setSize(400, 300);
125
126         // Constructs and shows the GUI.
127
box_ = javax.swing.Box.createVerticalBox();
128         frame_.getContentPane().add(box_);
129         frame_.pack();
130         frame_.show();
131     }
132
133     // ==================================================================
134
//
135
// Methods for the OMG IDL org.omg.Components.SessionComponent
136
//
137
// ==================================================================
138

139     /**
140      * Setting the session component context.
141      *
142      * @param context The session component context.
143      */

144     public void
145     set_session_context(org.omg.Components.SessionContext context)
146     throws org.omg.Components.CCMException
147     {
148         the_context_ = (CCM_Observer_Context)context;
149     }
150
151     /**
152      * Container callback to signal that the component is activated.
153      *
154      * @throw org.omg.Components.CCMException For any problems.
155      */

156     public void
157     ccm_activate()
158     throws org.omg.Components.CCMException
159     {
160         // Nothing to do currently.
161
}
162
163     /**
164      * Container callback to signal that the component is activated.
165      *
166      * @throw org.omg.Components.CCMException For any problems.
167      */

168     public void
169     ccm_passivate()
170     throws org.omg.Components.CCMException
171     {
172         // Nothing to do currently.
173
}
174
175     /**
176      * Container callback to signal that the component is removed.
177      *
178      * @throw org.omg.Components.CCMException For any problems.
179      */

180     public void
181     ccm_remove()
182     throws org.omg.Components.CCMException
183     {
184         // Release the associated frame.
185
frame_.dispose();
186         frame_ = null;
187     }
188
189     // ==================================================================
190
//
191
// Methods for OMG IDL CCM_Observer
192
//
193
// ==================================================================
194

195     /**
196      * To receive dinner::StatusInfo events published
197      * by Philosopher components.
198      */

199     public void
200     push_info(StatusInfo event)
201     {
202         push(event);
203     }
204
205     // ==================================================================
206
//
207
// Methods for OMG IDL dinner::StatusInfoConsumer
208
//
209
// ==================================================================
210

211     /**
212      * To receive DiningPhilosophers::StatusInfo events.
213      *
214      * Update the observer GUI with received status informations.
215      */

216     public synchronized void
217     push(StatusInfo event)
218     {
219         if (! philosopherPanels_.containsKey(event.name)) {
220             PhilosopherPanel panel = new PhilosopherPanel(event);
221             box_.add(panel);
222             philosopherPanels_.put(event.name, panel);
223             frame_.pack();
224             frame_.show();
225         } else {
226             PhilosopherPanel panel;
227             panel = (PhilosopherPanel)philosopherPanels_.get(event.name);
228             panel.updatePanel(event);
229         }
230     }
231 }
232
Popular Tags