1 21 package ist.coach.itut_q816Components; 22 23 import ist.coach.coachEmfCommon.HeartbeatImpl; 24 27 public class HeartbeatProviderMonolithicImpl 28 extends org.omg.CORBA.LocalObject 29 implements CCM_HeartbeatProvider, 30 intt.itu.itut_q816.CCM_Heartbeat, 31 org.omg.Components.SessionComponent, 32 Runnable 33 { 34 42 private Thread publisherThread; 43 private String _label; 44 private short _period = 100; 45 48 private CCM_HeartbeatProvider_Context the_context_; 49 57 public 58 HeartbeatProviderMonolithicImpl() 59 { 60 the_context_ = null; 61 } 62 68 private void publisher_init() { 69 if (publisherThread == null) { 70 publisherThread = new Thread (this, "Publisher"); 71 publisherThread.start(); 72 } 73 } 74 75 private void publisher_stop() { 76 77 publisherThread = null; 78 83 } 84 95 public CCM_HeartbeatProvider_Context 96 getContext() 97 { 98 return the_context_; 99 } 100 114 public void 115 configuration_complete() 116 throws org.omg.Components.InvalidConfiguration 117 { 118 publisher_init(); 122 System.err.println("HeartbeatProvider configuration completed..."); 123 } 124 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 156 public void 157 ccm_activate() 158 throws org.omg.Components.CCMException 159 { 160 } 164 174 public void 175 ccm_passivate() 176 throws org.omg.Components.CCMException 177 { 178 } 182 192 public void 193 ccm_remove() 194 throws org.omg.Components.CCMException 195 { 196 publisher_stop(); 200 } 201 212 public intt.itu.itut_q816.CCM_Heartbeat 213 get_admin() 214 { 215 return this; 216 } 217 223 public java.lang.String 224 label() 225 { 226 return _label; 230 } 231 232 235 public void 236 label(java.lang.String val) 237 { 238 if (val != null) 242 _label = new String (val); 243 else 244 _label = new String (); 245 System.err.println("Heartbeat Label is set to " + _label); 246 } 247 258 public short 259 periodGet() 260 throws intt.itu.itut_x780.ApplicationError 261 { 262 return _period; 266 } 267 273 public void 274 periodSet(short period) 275 throws intt.itu.itut_x780.ApplicationError 276 { 277 System.err.println("HeartbeatProvider: periodSet> to " + period + " secs"); 281 _period = period; 282 } 283 284 public void run() { 290 291 Thread 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 the_context_.push_heartbeat(new HeartbeatImpl( 304 _label, 305 new String (), 306 _period, 307 eventTime) 308 ); 309 310 311 if (_period == 0) 312 exitCondition = true; 313 } 314 catch (InterruptedException ie) { 315 System.err.println("Heartbeat Publisher Exiting"); 316 } 317 catch (Exception e) { 318 System.err.println("HeartbeatPublisher>Exception in run(): " + e); 319 e.printStackTrace(); 320 } 321 } 322 } 323 324 } 325 | Popular Tags |