Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / examples / Simulator / DOVEBrowser / MTDataHandlerAdapter.java
blob3d784d2bbb73a4a4f27ad7022030e0768fba6d06
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;
14 // Constructor.
15 MTDataHandlerAdapter (DataHandler dh, boolean use_queueing)
17 dataHandler_ = dh;
18 use_queueing_ = use_queueing;
19 if (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");
30 if (use_queueing_)
32 // System.out.println ("MTDataHandlerAdapter.push queueing events");
33 queue_.enqueue_tail (events);
35 else
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.
50 public void run ()
52 // Loop forever, handling events.
53 for (;;)
55 try
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);