1 // This is an adapter class for a data handler to be used in a separate
2 // thread. The adapter provides a push method that places an event
3 // set into its synchronized internal MTQueue. It runs a separate thread
4 // which blocks until there is an event in the queue, then dequeues the
5 // event and then unpacks it and updates the underlying data handler.
7 public class MTDataHandlerAdapter
extends Thread
9 // Both the queue and the underlying data handler are private
10 private MTQueue queue_
= null;
11 private DataHandler dataHandler_
= null;
12 private boolean use_queueing_
= false;
15 MTDataHandlerAdapter (DataHandler dh
, boolean use_queueing
)
18 use_queueing_
= use_queueing
;
21 queue_
= new MTQueue ();
25 // Enqueue an event set for the handler thread.
26 public void push (RtecEventComm
.Event
[] events
)
28 // System.out.println ("in MTDataHandlerAdapter.push");
32 // System.out.println ("MTDataHandlerAdapter.push queueing events");
33 queue_
.enqueue_tail (events
);
37 for (int i
= 0; i
< events
.length
; ++i
)
39 if(events
[i
].header
.type
==
40 PushConsumer
.ACE_ES_EVENT_NOTIFICATION
)
42 // System.out.println ("MTDataHandlerAdapter.push updating data handler");
43 dataHandler_
.update (events
[i
]);
49 // Process enqueued event sets in a separate thread.
52 // Loop forever, handling events.
57 // Pull an event set from the head of the queue
58 RtecEventComm
.Event
[] events
=
59 (RtecEventComm
.Event
[]) queue_
.dequeue_head ();
61 for (int i
= 0; i
< events
.length
; ++i
)
63 if(events
[i
].header
.type
==
64 PushConsumer
.ACE_ES_EVENT_NOTIFICATION
)
66 dataHandler_
.update (events
[i
]);
70 catch(org
.omg
.CORBA
.SystemException e
)
72 System
.err
.println(e
);