1 28 29 package ist.coach.itut_q816Components.HeartbeatProviderComposition; 30 31 import ist.coach.coachEmfCommon.HeartbeatImpl; 32 38 public class HeartbeatProviderImpl 39 extends ist.coach.itut_q816Components.HeartbeatProviderComposition.HeartbeatProvider_impl 40 implements Runnable 41 { 42 50 private Thread publisherThread; 51 private String _label; 52 protected static short _period = 100; 53 59 public HeartbeatProviderImpl() 60 { 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 98 public void 99 configuration_complete() 100 throws org.omg.Components.InvalidConfiguration 101 { 102 publisher_init(); 106 System.err.println("HeartbeatProvider configuration completed..."); 107 } 108 118 public void 119 ccm_remove() 120 throws org.omg.Components.CCMException 121 { 122 publisher_stop(); 126 } 127 133 136 public String 137 label() 138 { 139 return _label; 143 } 144 145 148 public void 149 label(String label) 150 { 151 if (label != null) 154 _label = new String (label); 155 else 156 _label = new String (); 157 System.err.println("Heartbeat Label is set to " + _label); 158 } 159 160 public void run() { 166 167 Thread 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 get_context().push_heartbeat(new HeartbeatImpl( 180 _label, 181 new String (), 182 _period, 183 eventTime) 184 ); 185 186 187 if (_period == 0) 188 exitCondition = true; 189 } 190 catch (InterruptedException ie) { 191 System.err.println("Heartbeat Publisher Exiting"); 192 } 193 catch (Exception e) { 194 System.err.println("HeartbeatPublisher>Exception in run(): " + e); 195 e.printStackTrace(); 196 } 197 } 198 } 199 200 } 201 | Popular Tags |