KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ist > coach > itut_q816Components > HeartbeatProviderComposition > HeartbeatProviderImpl


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

28
29 package ist.coach.itut_q816Components.HeartbeatProviderComposition;
30
31 import ist.coach.coachEmfCommon.HeartbeatImpl;
32 /**
33  * This is the CIDL-based implementation of the
34  * OMG IDL3 IDL:coach.ist/itut_q816Components/HeartbeatProvider:1.0 component type.
35  *
36  * @author OpenCCM CIF_Jimpl Compiler.
37  */

38 public class HeartbeatProviderImpl
39      extends ist.coach.itut_q816Components.HeartbeatProviderComposition.HeartbeatProvider_impl
40      implements Runnable JavaDoc
41 {
42     // ==================================================================
43
//
44
// Internal states.
45
//
46
// ==================================================================
47
/**
48      ** HeartbeatEmitter Thread
49      **/

50     private Thread JavaDoc publisherThread;
51     private String JavaDoc _label;
52     protected static short _period = 100;
53     // ==================================================================
54
//
55
// Constructors.
56
//
57
// ==================================================================
58

59     public HeartbeatProviderImpl()
60     {
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
// Methods for the OMG IDL Components::EnterpriseComponent local interface.
87
//
88
// ==================================================================
89
//
90
// IDL:omg.org/Components/EnterpriseComponent/configuration_complete:1.0
91
//
92
/**
93      ** Completes the component configuration.
94      **
95      ** @throws org.omg.Components.InvalidConfiguration
96      ** Thrown if the configuration is invalid.
97      **/

98     public void
99     configuration_complete()
100     throws org.omg.Components.InvalidConfiguration
101     {
102         //
103
// DONE : implement !!!
104
//
105
publisher_init();
106         System.err.println("HeartbeatProvider configuration completed...");
107     }
108     //
109
// IDL:omg.org/Components/SessionComponent/ccm_remove:1.0
110
//
111
/**
112      *
113      * Called by the container when the component will be removed.
114      *
115      * @throws org.omg.Components.CCMException
116      * Thrown if a system level error occured.
117      */

118     public void
119     ccm_remove()
120     throws org.omg.Components.CCMException
121     {
122         //
123
// DONE: implement !!!
124
//
125
publisher_stop();
126     }
127     // ==================================================================
128
//
129
// Methods.
130
//
131
// ==================================================================
132

133     /**
134      * Implementation of the ::itut_q816Components::CCM_HeartbeatProvider_Executor::label attribute as accessor operation.
135      */

136     public String JavaDoc
137     label()
138     {
139        //
140
// DONE : implement
141
//
142
return _label;
143     }
144
145     /**
146      * Implementation of the ::itut_q816Components::CCM_HeartbeatProvider_Executor::label attribute as mutator operation.
147      */

148     public void
149     label(String JavaDoc label)
150     {
151         // DONE : implement
152
//
153
if (label != null)
154             _label = new String JavaDoc(label);
155         else
156             _label = new String JavaDoc();
157         System.err.println("Heartbeat Label is set to " + _label);
158     }
159
160         // ==================================================================
161
//
162
// Runnable Interface methods.
163
//
164
// ===================================================================
165
public void run() {
166
167         Thread JavaDoc myThread = Thread.currentThread();
168
169         boolean exitCondition = false;
170         org.omg.TimeBase.UtcT eventTime;
171         System.err.println("Heartbeat Publisher started...");
172         while (publisherThread == myThread && !exitCondition) {
173
174                 try {
175                       Thread.sleep(_period * 1000);
176                       eventTime = new org.omg.TimeBase.UtcT(System.currentTimeMillis(),
177                             0,(short) 0,(short) 0);
178                       //System.err.println("Heartbeat Publisher attempts to emit event!");
179
get_context().push_heartbeat(new HeartbeatImpl(
180                                                  _label,
181                                                   new String JavaDoc(),
182                                                  _period,
183                                                   eventTime)
184                                                   );
185
186
187                       if (_period == 0)
188                           exitCondition = true;
189             }
190             catch (InterruptedException JavaDoc ie) {
191                 System.err.println("Heartbeat Publisher Exiting");
192             }
193             catch (Exception JavaDoc e) {
194                 System.err.println("HeartbeatPublisher>Exception in run(): " + e);
195                 e.printStackTrace();
196             }
197         }
198      }
199
200 }
201
Popular Tags