1 <!DOCTYPE HTML PUBLIC
"-//IETF//DTD HTML//EN">
4 <title>TAO's RT Event Service
</title>
13 <h3>TAO's RT Event Service
</h3>
15 <P>We have already explored how to use
16 <A HREF=
"../Event_Service/index.html">
17 TAO's COS Event Service
19 to receive updated stock prices,
20 but what if we are not interested in all the stocks?
21 One approach is to use multiple event channels, each one
22 carrying different traffic.
24 each event channel could carry only a subset of the stocks.
25 In this section we will explore another solution,
26 using TAO's real-time Event Service to perform filtering for us.
27 TAO's real-time Event Service can do many other things,
28 like preserving priority end-to-end,
29 using multicast to conserve network resources,
30 generating timeout and interval events,
31 and it can collaborate with TAO's Scheduling Service to
32 analyze the schedulability of your system.
35 <H3>Getting the Price Changes
</H3>
37 <P>For this example we will use the same data structures that we
38 used in the previous example,
39 i.e., the events will be identical.
40 TAO's RT Event Service can be configured to carry your events in
42 or you can use custom marshaling to send non-IDL structures in
44 but it is easier to use it like the COS Event Service first.
47 <H3>Connecting as a consumer
</H3>
49 <P>Connecting as a consumer is very similar. Some of the base
50 classes and signatures change, but it is basically the same
52 First let us define the consumer object:
55 class Stock_Consumer : public POA_RtecEventComm::PushConsumer {
59 void push (const RtecEventComm::EventSet& data);
60 void disconnect_push_consumer (void);
65 <P>Notice that we receive an event set instead of a single event.
66 The event channel can use this feature to queue multiple events
67 and push them in a single operation.
68 First we need to extract the event data from the any:
72 Stock_Consumer::push (const RtecEventComm::EventSet &data)
74 for (CORBA::ULong i =
0; i != data.length (); ++i) {
75 RtecEventComm::Event &e = data[i];
78 if ((e.data.any_value
>>= event) ==
0)
79 continue; // Invalid event
81 <P>Notice that the events have more structure,
82 they have a clearly separated header and data,
83 and the data has more than just an any.
84 The header is used to provide filtering, and
85 the event data field can be configured at compile time to carry
86 whatever IDL structures you want.
87 Now we can print out the new stock price:
90 std::cout <<
"The new price for one stock in \""
91 << event->full_name.in ()
92 << "\
" (" << event-
>symbol.in ()
93 <<
") is " << event-
>price << std::endl;
97 <P>We also need to implement the disconnect callback:
101 Stock_Consumer::disconnect_push_consumer (void)
103 this-
>supplier_proxy_ = CosEventChannelAdmin::ProxyPushSupplier::_nil ();
106 <P>As with the COS Event Channel we can voluntarily disconnect,
111 Stock_Consumer::disconnect ()
113 // Do not receive any more events...
114 this-
>supplier_proxy_-
>disconnect_push_supplier ();
118 <H4>How to connect to the RT event channel
</H4>
120 <P>Connecting to the RT event channel is very similar to
121 connecting to the regular event channel.
122 The only difference is that we must specify the events that we
123 want to receive. This is described using a fairly complex IDL
124 structure, but TAO provides a helper class to generate it.
125 We will assume that we are using the naming service or
126 something similar to obtain a reference to the event service:
129 CORBA::Object_var tmp = naming_context-
>resolve (name);
130 RtecEventChannelAdmin::EventChannel_var event_channel =
131 RtecEventChannelAdmin::EventChannel::_narrow (tmp);
133 <P>Now we use the event channel to obtain the factory used for
134 consumer connections:
137 RtecEventChannelAdmin::ConsumerAdmin_var consumer_admin =
138 event_channel-
>for_consumers ();
140 <P>And use the factory to obtain a proxy:
144 Stock_Consumer::connect (RtecEventChannelAdmin::ConsumerAdmin_ptr consumer_admin)
146 this-
>supplier_proxy_ =
147 consumer_admin-
>obtain_push_supplier ();
149 <P>Now we list the events that we want to receive.
150 We use a simple algorithm to assign an event type to each stock
154 CORBA::ULong rhat_event_type =
155 (int('R') <<
24) | (int('H') <<
16) | (int('A') <<
8) | int('T');
156 CORBA::ULong aaaa_event_type =
157 (int('A') <<
24) | (int('A') <<
16) | (int('A') <<
8) | int('A');
159 <P>Now we create the subscription:
162 ACE_ConsumerQOS_Factory subscriptions;
163 subscriptions.insert_type (rhat_event_type,
0);
164 subscriptions.insert_type (aaaa_event_type,
0);
166 <P>And connect to the proxy:
169 RtecEventComm::PushConsumer_var myself = this-
>_this ();
170 this-
>supplier_proxy_-
>connect_push_consumer (
172 subscriptions.get_ConsumerQOS ());
176 <H3>Notifying the Price Changes
</H3>
178 <P>As with the COS Event Channel example we will make our
179 implementation of the
<CODE>Modify_Stock
</CODE> interface
180 generate events whenever the price changes:
183 class Quoter_Modify_Stock_i : public POA_Quoter::Modify_Stock {
185 Quoter_Modify_Stock_i (const char *symbol,
186 const char *full_name,
187 CORBA::Double price);
189 void set_price (CORBA::Double new_price);
191 void disconnect_push_supplier (void);
196 RtecEventChannelAdmin::ProxyPushConsumer_var consumer_proxy_;
198 POA_RtecEventComm::PushSupplier_tie < Quoter_Stock_i
> supplier_personality_;
201 <P>The implementation of the
<CODE>set_price()
</CODE> method is
203 First we store the new price:
207 Quoter_Stock_i::set_price (CORBA::Double new_price)
209 this-
>data_.price = new_price;
211 <P>Next we prepare the event.
212 This time we must create a sequence, but we just have one
216 RtecEventComm::EventSet event (
1);
219 <P>We set the event type based on the stock symbol:
222 RtecEventComm::Event &e = event[
0];
223 const char *symbol = this-
>data_.symbol;
225 ((int(symbol[
0]) <<
24)
226 | (int(symbol[
1]) <<
16)
227 | (int(symbol[
2]) <<
8)
231 <P>The event source is not used in this example, but it must be
232 non-zero. Now we can set the data:
235 e.data.any_value <<= this-
>data_;
237 <P>and send the event to the event channel:
240 this-
>consumer_proxy_-
>push (event);
244 <H3>Connecting to the Event Service as a Supplier
</H3>
246 <P>As in the COS Event Channel case we need a supplier personality
248 We gain access to the Event Service, for example using the
252 CORBA::Object_var tmp = naming_context-
>resolve (name);
253 RtecEventChannelAdmin::EventChannel_var event_channel =
254 RtecEventChannelAdmin::EventChannel::_narrow (tmp);
256 <P>Now we use the event channel to obtain the factory used for
257 supplier connections:
260 RtecEventChannelAdmin::SupplierAdmin_var supplier_admin =
261 event_channel-
>for_suppliers ();
263 <P>And use the factory to obtain a proxy:
266 this-
>consumer_proxy_ =
267 supplier_admin-
>obtain_push_consumer ();
269 <P>We build our publications so the event channel can match
270 consumers and suppliers based on their common events:
273 const char *symbol = this-
>data_.symbol;
275 ((int(symbol[
0]) <<
24)
276 | (int(symbol[
1]) <<
16)
277 | (int(symbol[
2]) <<
8)
279 CORBA::ULong source =
1;
280 ACE_SupplierQOS_Factory publications;
281 publications.insert_type (type, source,
0,
1);
283 <P>Finally we connect to the consumer proxy:
286 RtecEventComm::PushSupplier_var supplier =
287 this-
>supplier_personality_._this ();
288 this-
>consumer_proxy_-
>connect_push_supplier (supplier);
291 <P>The implementation of the disconnect callback is as before:
295 Quoter_Stock_i::disconnect_push_supplier (void)
297 // Forget about the consumer it is not there anymore
298 this-
>consumer_proxy_ =
299 RtecEventChannelAdmin::ProxyPushConsumer::_nil ();
305 <P>Implement a consumer that receives the price update events,
308 <A HREF=
"Stock_Consumer.h">header file
</A>
311 <A HREF=
"client.cpp">client.cpp
</A>.
312 And other support files
313 <A HREF=
"../Event_Service/Quoter.idl">Quoter.idl
</A>,
314 <A HREF=
"GNUMakefile">Makefile
</A>,
315 <A HREF=
"Stock_i.h">Stock_i.h
</A>,
316 <A HREF=
"Stock_i.cpp">Stock_i.cpp
</A>,
317 <A HREF=
"Stock_Factory_i.h">Stock_Factory_i.h
</A>,
318 <A HREF=
"Stock_Factory_i.cpp">Stock_Factory_i.cpp
</A>,
319 and
<A HREF=
"server.cpp">server.cpp
</A>.
324 <P>Compare your solution with
325 <A HREF=
"Stock_Consumer.cpp">Stock_Consumer.cpp
</A>.
330 <P>To test your changes you need to run three programs,
331 first TAO's Naming Service:
333 $ $TAO_ROOT/orbsvcs/Naming_Service/tao_cosnaming
335 <P>then run TAO's Real-time Event Service
338 $ $TAO_ROOT/orbsvcs/Event_Service/tao_rtevent
341 <P>Now you can run your client:
345 <P>and finally the server:
348 $ server MSFT BBBB CCCC < stock_list.txt
351 <A HREF=
"../Event_Service/stock_list.txt">stock_list.txt file
</A>.
356 <P>Run the same configuration as above,
357 but this time run multiple clients and servers:
362 $ server AAAA < stock_list1.txt
363 $ server QQQQ < stock_list2.txt
365 <P>Do the clients receive all the events from both servers?
368 <A HREF=
"../Event_Service/stock_list1.txt">stock_list1.txt
</A>
370 <A HREF=
"../Event_Service/stock_list2.txt">stock_list2.txt
</A>
375 <address><a href=
"mailto:coryan@cs.wustl.edu">Carlos O'Ryan
</a></address>
376 <!-- Created: Sat Nov 27 15:47:01 CST 1999 -->
378 Last modified: Wed May
16 10:
13:
34 PDT
2001