KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ist > coach > itut_q816Components > HeartbeatProviderMonolithicImpl


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

21 package ist.coach.itut_q816Components;
22
23 import ist.coach.coachEmfCommon.HeartbeatImpl;
24 /**
25  ** Implementation skeleton class for the ::itut_q816Components::HeartbeatProvider component.
26  **/

27 public class HeartbeatProviderMonolithicImpl
28        extends org.omg.CORBA.LocalObject JavaDoc
29        implements CCM_HeartbeatProvider,
30                   intt.itu.itut_q816.CCM_Heartbeat,
31                   org.omg.Components.SessionComponent,
32                   Runnable JavaDoc
33 {
34     // ==================================================================
35
//
36
// Internal State.
37
//
38
// ===================================================================
39
/**
40      ** HeartbeatEmitter Thread
41      **/

42     private Thread JavaDoc publisherThread;
43     private String JavaDoc _label;
44     private short _period = 100;
45     /**
46      ** Context reference.
47      **/

48     private CCM_HeartbeatProvider_Context the_context_;
49     // ==================================================================
50
//
51
// Constructor.
52
//
53
// ===================================================================
54
/**
55      ** The default constructor.
56      **/

57     public
58     HeartbeatProviderMonolithicImpl()
59     {
60         the_context_ = null;
61     }
62     // ==================================================================
63
//
64
// Internal methods.
65
//
66
// ===================================================================
67

68     private void publisher_init() {
69         if (publisherThread == null) {
70             publisherThread = new Thread JavaDoc(this, "Publisher");
71             publisherThread.start();
72         }
73     }
74
75     private void publisher_stop() {
76
77       publisherThread = null;
78 /***
79         Thread dummyThread = publisherThread;
80         publisherThread = null;
81         dummyThread.interrupt();
82 *****/

83     }
84     // ==================================================================
85
//
86
// Public methods.
87
//
88
// ===================================================================
89
/**
90      ** To obtain the context.
91      **
92      ** @return The context that has been previously set by
93      ** the set_session_context operation.
94      **/

95     public CCM_HeartbeatProvider_Context
96     getContext()
97     {
98         return the_context_;
99     }
100     // ==================================================================
101
//
102
// Methods for the OMG IDL Components::EnterpriseComponent local interface.
103
//
104
// ==================================================================
105
//
106
// IDL:omg.org/Components/EnterpriseComponent/configuration_complete:1.0
107
//
108
/**
109      ** Completes the component configuration.
110      **
111      ** @throws org.omg.Components.InvalidConfiguration
112      ** Thrown if the configuration is invalid.
113      **/

114     public void
115     configuration_complete()
116     throws org.omg.Components.InvalidConfiguration
117     {
118         //
119
// DONE : implement !!!
120
//
121
publisher_init();
122         System.err.println("HeartbeatProvider configuration completed...");
123     }
124     // ==================================================================
125
//
126
// Methods for the OMG IDL Components::SessionComponent local interface.
127
//
128
// ==================================================================
129
//
130
// IDL:omg.org/Components/SessionComponent/set_session_context:1.0
131
//
132
/**
133      * Called by the container when the component session context will be fixed.
134      *
135      * @param context The session context.
136      *
137      * @throws org.omg.Components.CCMException
138      * Thrown if a system level error occured.
139      */

140     public void
141     set_session_context(org.omg.Components.SessionContext context)
142     throws org.omg.Components.CCMException
143     {
144         the_context_ = (CCM_HeartbeatProvider_Context)context;
145     }
146     //
147
// IDL:omg.org/Components/SessionComponent/ccm_activate:1.0
148
//
149
/**
150      *
151      * Called by the container when the component will be activated.
152      *
153      * @throws org.omg.Components.CCMException
154      * Thrown if a system level error occured.
155      */

156     public void
157     ccm_activate()
158     throws org.omg.Components.CCMException
159     {
160         //
161
// Unused by actual OpenCCM containers
162
//
163
}
164     //
165
// IDL:omg.org/Components/SessionComponent/ccm_passivate:1.0
166
//
167
/**
168      *
169      * Called by the container when the component will be passivated.
170      *
171      * @throws org.omg.Components.CCMException
172      * Thrown if a system level error occured.
173      */

174     public void
175     ccm_passivate()
176     throws org.omg.Components.CCMException
177     {
178         //
179
// Unused by actual OpenCCM containers
180
//
181
}
182     //
183
// IDL:omg.org/Components/SessionComponent/ccm_remove:1.0
184
//
185
/**
186      *
187      * Called by the container when the component will be removed.
188      *
189      * @throws org.omg.Components.CCMException
190      * Thrown if a system level error occured.
191      */

192     public void
193     ccm_remove()
194     throws org.omg.Components.CCMException
195     {
196         //
197
// DONE: implement !!!
198
//
199
publisher_stop();
200     }
201     // ==================================================================
202
//
203
// Public methods for the CCM_HeartbeatProvider local interface.
204
//
205
// ==================================================================
206
//
207
// IDL:coach.ist/itut_q816Components/CCM_HeartbeatProvider/get_admin:1.0
208
//
209
/**
210      ** Implementation of the ::itut_q816Components::CCM_HeartbeatProvider::get_admin operation.
211      **/

212     public intt.itu.itut_q816.CCM_Heartbeat
213     get_admin()
214     {
215         return this;
216     }
217     //
218
// IDL:coach.ist/itut_q816Components/CCM_HeartbeatProvider_Executor/label:1.0
219
//
220
/**
221      ** Implementation of the ::itut_q816Components::CCM_HeartbeatProvider_Executor::label attribute as accessor operation.
222      **/

223     public java.lang.String JavaDoc
224     label()
225     {
226         //
227
// DONE : implement
228
//
229
return _label;
230     }
231
232     /**
233      ** Implementation of the ::itut_q816Components::CCM_HeartbeatProvider_Executor::label attribute as mutator operation.
234      **/

235     public void
236     label(java.lang.String JavaDoc val)
237     {
238         //
239
// DONE : implement
240
//
241
if (val != null)
242             _label = new String JavaDoc(val);
243         else
244             _label = new String JavaDoc();
245         System.err.println("Heartbeat Label is set to " + _label);
246     }
247     // ==================================================================
248
//
249
// Public methods for the ::itut_q816::CCM_Heartbeat local interface.
250
//
251
// ==================================================================
252
//
253
// IDL:itu.intt/itut_q816/Heartbeat/periodGet:1.0
254
//
255
/**
256      ** Implementation of the ::itut_q816::Heartbeat::periodGet operation.
257      **/

258     public short
259     periodGet()
260     throws intt.itu.itut_x780.ApplicationError
261     {
262         //
263
// TODO : implement
264
//
265
return _period;
266     }
267     //
268
// IDL:itu.intt/itut_q816/Heartbeat/periodSet:1.0
269
//
270
/**
271      ** Implementation of the ::itut_q816::Heartbeat::periodSet operation.
272      **/

273     public void
274     periodSet(short period)
275     throws intt.itu.itut_x780.ApplicationError
276     {
277         //
278
// DONE : implement
279
//
280
System.err.println("HeartbeatProvider: periodSet> to " + period + " secs");
281         _period = period;
282     }
283
284         // ==================================================================
285
//
286
// Runnable Interface methods.
287
//
288
// ===================================================================
289
public void run() {
290
291         Thread JavaDoc myThread = Thread.currentThread();
292
293         boolean exitCondition = false;
294         org.omg.TimeBase.UtcT eventTime;
295         System.err.println("Heartbeat Publisher started...");
296         while (publisherThread == myThread && !exitCondition) {
297
298                 try {
299                       Thread.sleep(_period * 1000);
300                       eventTime = new org.omg.TimeBase.UtcT(System.currentTimeMillis(),
301                             0,(short) 0,(short) 0);
302                       //System.err.println("Heartbeat Publisher attempts to emit event!");
303
the_context_.push_heartbeat(new HeartbeatImpl(
304                                                  _label,
305                                                   new String JavaDoc(),
306                                                  _period,
307                                                   eventTime)
308                                                   );
309
310
311                       if (_period == 0)
312                           exitCondition = true;
313             }
314             catch (InterruptedException JavaDoc ie) {
315                 System.err.println("Heartbeat Publisher Exiting");
316             }
317             catch (Exception JavaDoc e) {
318                 System.err.println("HeartbeatPublisher>Exception in run(): " + e);
319                 e.printStackTrace();
320             }
321         }
322      }
323
324 }
325
Popular Tags