3 // NavWeapDataHandler.java
6 // Michael Kircher (mk1@cs.wustl.edu)
9 // This is an implementation of the interface Data Handler,
10 // it handles Navigation and Weapons data, where statistic data is
11 // part of it. Several Observables are declared, they can be accessed by
12 // any number of Observers, which could reside in a Java Bean for example.
14 // ============================================================================
16 import org
.omg
.CORBA
.*;
18 public class NavWeapDataHandler
implements DataHandler
{
20 java
.util
.Hashtable ObservablesTable
;
24 // Observable for Persian Recursion data
25 class PersianObservable
extends DemoObservable
{
27 // to ask which kind of viewer is needed to display data
28 public int getProperty () {
29 return Properties
.PERSIAN
;
32 public void updatePersianData (PersianRecursion
.Data data
) {
34 // System.out.println ("in PersianObservable.updatePersianData");
37 notifyObservers (data
);
42 // Observable for Navigation data
43 class NavigationObservable
extends DemoObservable
{
45 // to ask which kind of viewer is needed to display data
46 public int getProperty () {
47 return Properties
.NAVIGATION
;
50 public void updateNavigation (Navigation navigation
) {
52 notifyObservers (navigation
);
56 class WeaponsObservable
extends DemoObservable
{
58 // to ask which kind of viewer is needed to display data
59 public int getProperty () {
60 return Properties
.WEAPONS
;
63 public void updateWeapons (Weapons weapons
) {
65 notifyObservers (weapons
);
69 class Cpu_UsageObservable
extends DemoObservable
{
71 public int getProperty () {
72 return Properties
.DOUBLE
;
75 public void updateCpu_Usage (double utilization
) {
77 Double temp_
= new Double (utilization
);
78 notifyObservers (temp_
);
82 class OverheadObservable
extends DemoObservable
{
84 public int getProperty () {
85 return Properties
.DOUBLE
;
88 public void updateOverhead (double overhead
) {
90 Double temp_
= new Double (overhead
);
91 notifyObservers (temp_
);
95 class JitterObservable
extends DemoObservable
{
97 double avg_latency
= 0.0;
98 double sample_count
= 0.0;
100 public int getProperty () {
101 return Properties
.DOUBLE
;
104 public void updateJitter (long completion_time
,
105 long computation_time
,
108 latency
= (double)(completion_time
) -
109 (double)(computation_time
) -
110 (double)(arrival_time
);
111 latency
= latency
> 0 ? latency
: 0;
113 sample_count
= sample_count
+ 1.0;
114 avg_latency
= (avg_latency
* (sample_count
- 1.0) + latency
) /
117 double jitter_
= (double)Math
.abs(latency
- avg_latency
);
120 Double temp_
= new Double (jitter_
);
121 notifyObservers (temp_
);
125 class DeadlinesObservable
extends DemoObservable
{
127 public int getProperty () {
128 return Properties
.DOUBLE
;
131 public void updateDeadlines (long deadline_time
,
132 long completion_time
) {
134 double missed_
= (deadline_time
< completion_time
) ?
1.0 : 0.0;
135 Double temp_
= new Double (missed_
);
137 notifyObservers (temp_
);
141 class CriticalDeadlinesObservable
extends DeadlinesObservable
{
143 public int getProperty () {
144 return Properties
.DOUBLE
;
147 public void updateDeadlines (long deadline_time
,
148 long completion_time
,
151 double missed_
= ((criticality
> 0) &&
152 (deadline_time
< completion_time
)) ?
1.0 : 0.0;
153 Double temp_
= new Double (missed_
);
155 notifyObservers (temp_
);
159 class LatencyObservable
extends DemoObservable
{
160 double latency
= 0.0;
161 double last_latency
= 0.0;
163 public int getProperty () {
164 return Properties
.DOUBLE
;
167 public void updateLatency (long computation_time
) {
168 last_latency
= latency
;
169 latency
= (double)(computation_time
);
170 latency
= latency
> 0 ? latency
: 0;
173 Double temp_
= new Double(latency
);
174 notifyObservers (temp_
);
177 public void updateLatency (long completion_time
,
178 long computation_time
,
180 last_latency
= latency
;
181 latency
= (double)(completion_time
) -
182 (double)(computation_time
) -
183 (double)(arrival_time
);
184 latency
= latency
> 0 ? latency
: 0;
187 Double temp_
= new Double(latency
);
188 notifyObservers (temp_
);
193 public synchronized void update (RtecEventComm
.Event event
) {
195 // System.out.println ("in NavWeapDataHandler.update");
198 PersianRecursion
.Data persian_recursion_data
;
200 any_value
= event
.data
.any_value
;
202 if (any_value
.type().equal (PersianRecursion
.DataHelper
.type()))
204 // System.out.println ("type matched PersianRecursion.Data");
208 persian_recursion_data
=
209 PersianRecursion
.DataHelper
.extract (any_value
);
213 System
.err
.println (e
.getMessage () +
214 "\nThe stack trace is:\n");
215 e
.printStackTrace ();
219 // System.out.println ("extracted any");
221 if (persian_recursion_data
.criticality_level
.equals (RtecScheduler
.Criticality_t
.HIGH_CRITICALITY
)
222 || persian_recursion_data
.criticality_level
.equals (RtecScheduler
.Criticality_t
.VERY_HIGH_CRITICALITY
))
224 // System.out.println ("obtaining high priority persian recursion observable");
226 PersianObservable pobs_hi
=
227 (PersianObservable
) ObservablesTable
.get ("High Consumer Persian Recursion");
229 // System.out.println ("updating high priority persian recursion observable");
231 pobs_hi
.updatePersianData (persian_recursion_data
);
233 // LatencyObservable lobs_hi =
234 // (LatencyObservable) ObservablesTable.get ("High Consumer Execution Time (100 ns)");
236 // lobs_hi.updateLatency (persian_recursion_data.computation_time);
240 // System.out.println ("obtaining low priority persian recursion observable");
241 PersianObservable pobs_lo
=
242 (PersianObservable
) ObservablesTable
.get ("Low Consumer Persian Recursion");
244 // System.out.println ("obtained low priority persian recursion observable");
245 // System.out.println ("updating low priority persian recursion observable");
247 pobs_lo
.updatePersianData (persian_recursion_data
);
249 // System.out.println ("updated low priority persian recursion observable");
251 // LatencyObservable lobs_lo =
252 // (LatencyObservable) ObservablesTable.get ("Low Consumer Execution Time (100 ns)");
254 // lobs_lo.updateLatency (persian_recursion_data.computation_time);
257 // System.out.println ("done updating PersianObservables");
261 // System.out.println ("total events received: " + received_events_);
263 else if (any_value
.type().equal (NavigationHelper
.type()))
265 Navigation navigation_
= NavigationHelper
.extract (any_value
);
267 // if the navigation data structure's update data flag is set,
268 // update its scheduling data with actual values from the EC
269 if (navigation_
.update_data
> 0)
271 navigation_
.arrival_time
= event
.header
.creation_time
;
272 navigation_
.completion_time
= event
.header
.ec_send_time
;
273 navigation_
.deadline_time
+= event
.header
.creation_time
;
276 NavigationObservable nobs
= (NavigationObservable
)ObservablesTable
.get ("Navigation");
277 nobs
.updateNavigation (navigation_
);
278 Cpu_UsageObservable cobs
= (Cpu_UsageObservable
)ObservablesTable
.get ("CPU Usage");
279 cobs
.updateCpu_Usage (navigation_
.utilization
);
280 OverheadObservable oobs
= (OverheadObservable
)ObservablesTable
.get ("Overhead");
281 oobs
.updateOverhead (navigation_
.overhead
);
282 JitterObservable jobs
= (JitterObservable
)ObservablesTable
.get ("Latency Jitter (100 ns)");
283 jobs
.updateJitter (navigation_
.completion_time
,
284 navigation_
.computation_time
,
285 navigation_
.arrival_time
);
286 JitterObservable njobs
= (JitterObservable
)ObservablesTable
.get ("Navigation Latency Jitter (100 ns)");
287 njobs
.updateJitter (navigation_
.completion_time
,
288 navigation_
.computation_time
,
289 navigation_
.arrival_time
);
290 DeadlinesObservable dobs
= (DeadlinesObservable
)ObservablesTable
.get ("Missed Deadlines");
291 dobs
.updateDeadlines (navigation_
.deadline_time
,
292 navigation_
.completion_time
);
293 CriticalDeadlinesObservable cdobs
=
294 (CriticalDeadlinesObservable
)ObservablesTable
.get ("Missed Critical Deadlines");
295 cdobs
.updateDeadlines (navigation_
.deadline_time
,
296 navigation_
.completion_time
,
297 navigation_
.criticality
);
298 LatencyObservable lobs
= (LatencyObservable
)ObservablesTable
.get ("Latency (100 ns)");
299 lobs
.updateLatency (navigation_
.completion_time
,
300 navigation_
.computation_time
,
301 navigation_
.arrival_time
);
302 LatencyObservable nlobs
= (LatencyObservable
)ObservablesTable
.get ("Navigation Latency (100 ns)");
303 nlobs
.updateLatency (navigation_
.completion_time
,
304 navigation_
.computation_time
,
305 navigation_
.arrival_time
);
308 else if (any_value
.type().equal (WeaponsHelper
.type()))
310 Weapons weapons_
= WeaponsHelper
.extract (any_value
);
312 // if the weapons structure's update data flag is set, update
313 // itss scheduling data with actual values from the EC
314 if (weapons_
.update_data
> 0)
316 weapons_
.arrival_time
= event
.header
.creation_time
;
317 weapons_
.completion_time
= event
.header
.ec_send_time
;
318 weapons_
.deadline_time
+= event
.header
.creation_time
;
321 WeaponsObservable wobs
= (WeaponsObservable
)ObservablesTable
.get ("Weapons");;
322 wobs
.updateWeapons (weapons_
);
323 Cpu_UsageObservable cobs
= (Cpu_UsageObservable
)ObservablesTable
.get ("CPU Usage");
324 cobs
.updateCpu_Usage (weapons_
.utilization
);
325 OverheadObservable oobs
= (OverheadObservable
)ObservablesTable
.get ("Overhead");
326 oobs
.updateOverhead (weapons_
.overhead
);
327 JitterObservable jobs
= (JitterObservable
)ObservablesTable
.get ("Latency Jitter (100 ns)");
328 jobs
.updateJitter (weapons_
.completion_time
,
329 weapons_
.computation_time
,
330 weapons_
.arrival_time
);
331 JitterObservable wjobs
= (JitterObservable
)ObservablesTable
.get ("Weapons Latency Jitter (100 ns)");
332 wjobs
.updateJitter (weapons_
.completion_time
,
333 weapons_
.computation_time
,
334 weapons_
.arrival_time
);
335 DeadlinesObservable dobs
= (DeadlinesObservable
)ObservablesTable
.get ("Missed Deadlines");
336 dobs
.updateDeadlines (weapons_
.deadline_time
,
337 weapons_
.completion_time
);
338 CriticalDeadlinesObservable cdobs
= (CriticalDeadlinesObservable
)ObservablesTable
.get ("Missed Critical Deadlines");
339 cdobs
.updateDeadlines (weapons_
.deadline_time
,
340 weapons_
.completion_time
,
341 weapons_
.criticality
);
342 LatencyObservable lobs
= (LatencyObservable
)ObservablesTable
.get ("Latency (100 ns)");
343 lobs
.updateLatency (weapons_
.completion_time
,
344 weapons_
.computation_time
,
345 weapons_
.arrival_time
);
346 LatencyObservable wlobs
= (LatencyObservable
)ObservablesTable
.get ("Weapons Latency (100 ns)");
347 wlobs
.updateLatency (weapons_
.completion_time
,
348 weapons_
.computation_time
,
349 weapons_
.arrival_time
);
354 System
.out
.println ("Received wrong type information");
356 System
.out
.println ("Received any_value.type (): [" +
357 any_value
.type() + "]");
359 System
.out
.println ("Expected NavigationHelper.type (): [" +
360 NavigationHelper
.type() + "]");
362 System
.out
.println ("OR WeaponsHelper.type (): [" +
363 WeaponsHelper
.type() + "]");
365 System
.out
.println ("OR PersianRecursion.DataHelper.type (): [" +
366 PersianRecursion
.DataHelper
.type() + "]");
370 NavWeapDataHandler () {
371 ObservablesTable
= new java
.util
.Hashtable();
373 ObservablesTable
.put ("Navigation", new NavigationObservable());
374 ObservablesTable
.put ("Weapons", new WeaponsObservable());
375 ObservablesTable
.put ("CPU Usage", new Cpu_UsageObservable());
376 ObservablesTable
.put ("Overhead", new OverheadObservable());
377 ObservablesTable
.put ("Latency Jitter (100 ns)", new JitterObservable());
378 ObservablesTable
.put ("Navigation Latency Jitter (100 ns)", new JitterObservable());
379 ObservablesTable
.put ("Weapons Latency Jitter (100 ns)", new JitterObservable());
380 ObservablesTable
.put ("Missed Deadlines", new DeadlinesObservable());
381 ObservablesTable
.put ("Missed Critical Deadlines", new CriticalDeadlinesObservable());
382 ObservablesTable
.put ("Latency (100 ns)", new LatencyObservable());
383 ObservablesTable
.put ("Weapons Latency (100 ns)", new LatencyObservable());
384 ObservablesTable
.put ("Navigation Latency (100 ns)", new LatencyObservable());
385 ObservablesTable
.put ("High Consumer Persian Recursion", new PersianObservable());
386 ObservablesTable
.put ("Low Consumer Persian Recursion", new PersianObservable());
387 ObservablesTable
.put ("High Consumer Execution Time (100 ns)", new LatencyObservable());
388 ObservablesTable
.put ("Low Consumer Execution Time (100 ns)", new LatencyObservable());
391 public java
.util
.Enumeration
getObservablesList () {
392 return ObservablesTable
.keys ();
395 public DemoObservable
getObservable(String name
) {
396 return (DemoObservable
)ObservablesTable
.get (name
);
399 public int getObservableProperty (String name
) {
400 DemoObservable obs
= (DemoObservable
)ObservablesTable
.get (name
);
401 return obs
.getProperty ();