1 // ============================================================================
8 // Michael Kircher (mk1@cs.wustl.edu)
11 // This is a Push Consumer which takes the data field of the
12 // event and updates with it a Data Handler.
15 // ============================================================================
18 public class PushConsumer extends RtecEventComm._PushConsumerImplBase
21 public static final int ACE_ES_EVENT_ANY = 0;
22 public static final int ACE_ES_EVENT_SHUTDOWN = 1;
23 public static final int ACE_ES_EVENT_ACT = 2;
24 public static final int ACE_ES_EVENT_NOTIFICATION = 3;
25 public static final int ACE_ES_EVENT_TIMEOUT = 4;
26 public static final int ACE_ES_EVENT_INTERVAL_TIMEOUT = 5;
27 public static final int ACE_ES_EVENT_DEADLINE_TIMEOUT = 6;
28 public static final int ACE_ES_GLOBAL_DESIGNATOR = 7;
29 public static final int ACE_ES_CONJUNCTION_DESIGNATOR = 8;
30 public static final int ACE_ES_DISJUNCTION_DESIGNATOR = 9;
31 public static final int ACE_ES_EVENT_UNDEFINED = 16;
32 public static final int TOTAL_MESSAGES = 30;
34 // Store the number of received events
35 private int total_received_ = 0;
36 private org.omg.CORBA.ORB orb_;
37 private DataHandler dataHandler_;
39 private RtecEventChannelAdmin.EventChannel channel_admin_;
40 private RtecEventChannelAdmin.ConsumerAdmin consumer_admin_;
41 private RtecEventChannelAdmin.ProxyPushSupplier suppliers_;
43 public PushConsumer (org.omg.CORBA.ORB orb, DataHandler dataHandler)
46 dataHandler_ = dataHandler;
50 public void push (RtecEventComm.Event[] events)
52 if (total_received_ < 5)
53 System.out.println ("Demo Consumer: Received an event! ->Number: " + total_received_);
54 else if (total_received_ == 5)
55 System.out.println ("Demo Consumer: Everything is fine. Going to be mute.");
58 if (events.length == 0)
60 System.err.println ("No events");
66 for (int i = 0; i < events.length; ++i)
68 if(events[i].type_ == ACE_ES_EVENT_NOTIFICATION)
72 dataHandler_.update (events[i].data_.any_value);
74 catch(org.omg.CORBA.SystemException e)
76 System.err.println(e);
83 public void disconnect_push_consumer()
85 System.out.println ("Demo Consumer: Have to disconnect!");
88 public void open_consumer (RtecEventChannelAdmin.EventChannel event_channel,
89 RtecScheduler.Scheduler scheduler,
96 // Define Real-time information
98 rt_info_ = scheduler.create (name);
100 scheduler.set (rt_info_,
101 RtecScheduler.Criticality.VERY_LOW_CRITICALITY,
102 new TimeBase.ulonglong (0,0),
103 new TimeBase.ulonglong (0,0),
104 new TimeBase.ulonglong (0,0),
106 RtecScheduler.Importance.VERY_LOW_IMPORTANCE,
107 new TimeBase.ulonglong (0,0),
109 RtecScheduler.Info_Type.OPERATION);
111 // Register for Notification and Shutdown events
112 RtecEventComm.Event notification_event =
113 new RtecEventComm.Event (ACE_ES_EVENT_NOTIFICATION, 0,
115 new TimeBase.ulonglong (0,0),
116 new TimeBase.ulonglong (0,0),
117 new TimeBase.ulonglong (0,0),
118 new RtecEventComm.EventData (orb_.create_any ()));
120 RtecEventChannelAdmin.Dependency dependencies[] = new RtecEventChannelAdmin.Dependency[1];
121 dependencies[0] = new RtecEventChannelAdmin.Dependency (notification_event, rt_info_);
123 RtecEventChannelAdmin.ConsumerQOS qos = new RtecEventChannelAdmin.ConsumerQOS (dependencies,
126 // The channel administrator is the event channel we got from the invocation
128 channel_admin_ = event_channel;
130 // Connect as a consumer
131 consumer_admin_ = channel_admin_.for_consumers ();
133 // Obtain a reference to the proxy push supplier
134 suppliers_ = consumer_admin_.obtain_push_supplier ();
136 suppliers_.connect_push_consumer (this, qos);
138 System.out.println ("Registered the consumer successfully.");
141 catch (RtecEventChannelAdmin.TypeError e)
143 System.err.println ("Demo_Consumer.open_consumer: Type error");
144 System.err.println (e);
146 catch (RtecEventChannelAdmin.AlreadyConnected e)
148 System.err.println ("Demo_Consumer.open_consumer: Already connected");
149 System.err.println (e);
152 catch (RtecScheduler.UNKNOWN_TASK e)
154 System.err.println ("Demo_Consumer.open_consumer: Unknown task");
155 System.err.println (e);
157 catch (RtecScheduler.DUPLICATE_NAME e)
159 System.err.println ("Demo_Consumer.open_consumer: Duplicate names");
160 System.err.println (e);
162 catch(org.omg.CORBA.SystemException e)
164 System.err.println(e);