Merge pull request #2316 from jwillemsen/jwi-taskcommenttypo
[ACE_TAO.git] / TAO / orbsvcs / tests / Notify / performance-tests / RedGreen / RedGreen_Test.h
blob44f32fc002891c6cecee4f3370651d5eb33a12f6
1 /* -*- C++ -*- */
2 //=============================================================================
3 /**
4 * @file RedGreen_Test.h
6 * Performance test to show improvement in Notify performance by picking the
7 * correcting configuration.
9 * @author Pradeep Gore <pradeep@cs.wustl.edu>
11 //=============================================================================
14 #ifndef NOTIFY_RedGreen_Test_CLIENT_H
15 #define NOTIFY_RedGreen_Test_CLIENT_H
17 #include "orbsvcs/CosNotifyChannelAdminS.h"
18 #include "orbsvcs/CosNotifyCommC.h"
19 #include "orbsvcs/CosNamingC.h"
20 #include "ace/Task.h"
21 #include "ace/Stats.h"
22 #include "ace/Throughput_Stats.h"
23 #include "ace/High_Res_Timer.h"
24 #include "ace/Sched_Params.h"
26 #if defined(_MSC_VER)
27 #pragma warning(push)
28 #pragma warning(disable:4250)
29 #endif /* _MSC_VER */
31 class RedGreen_Test_StructuredPushConsumer;
32 class RedGreen_Test_StructuredPushSupplier;
34 /**
35 * @class Worker
37 * @brief Run a server thread
39 * Use the ACE_Task_Base class to run server threads
41 class Worker : public ACE_Task_Base
43 public:
44 /// Constructor.
45 Worker ();
47 void orb (CORBA::ORB_ptr orb);
49 /// The thread entry point.
50 virtual int svc ();
52 // Shutdown ORB
53 void done ();
55 private:
56 /// The orb
57 CORBA::ORB_var orb_;
60 /**
61 * @class RedGreen_Test
63 * @brief RedGreen_Test
65 * Shows how consumers RedGreen_Test for events.
67 class RedGreen_Test
69 public:
70 // = Initialization
71 RedGreen_Test ();
73 int parse_args (int argc,
74 ACE_TCHAR *argv[]);
76 void dump_results ();
78 /// Initialize the Client.
79 void init (int argc,
80 ACE_TCHAR *argv []);
82 /// Run the demo.
83 void run ();
85 /// Called when all events we are waiting for have occurred.
86 void done ();
88 /// Destroy from the EC
89 void destroy_ec ();
91 int burst_size_;
92 Worker worker_;
93 int nthreads_;
95 protected:
96 /// Initializes the ORB.
97 void init_ORB (int argc,
98 ACE_TCHAR *argv []);
100 /// Try to get hold of a running naming service.
101 void resolve_naming_service ();
103 /// Try to resolve the Notify factory from the Naming service.
104 void resolve_Notify_factory ();
106 /// Create an EC.
107 void create_EC ();
109 /// Create the Supplier Admin.
110 void create_supplieradmin();
112 /// Create the Consumer Admin.
113 void create_consumeradmin ();
115 /// Create and initialize the consumers.
116 void create_consumers ();
118 /// create and initialize the suppliers.
119 void create_suppliers ();
121 /// send the events.
122 void send_events ();
124 // = Data Members.
125 /// Reference to the root poa.
126 PortableServer::POA_var root_poa_;
128 /// The ORB that we use.
129 CORBA::ORB_var orb_;
131 /// Handle to the name service.
132 CosNaming::NamingContext_var naming_context_;
134 /// Channel factory.
135 CosNotifyChannelAdmin::EventChannelFactory_var notify_factory_;
137 /// The one channel that we create using the factory.
138 CosNotifyChannelAdmin::EventChannel_var ec_;
140 /// The group operator between admin-proxy's.
141 CosNotifyChannelAdmin::InterFilterGroupOperator ifgop_;
143 /// Initial qos specified to the factory when creating the EC.
144 CosNotification::QoSProperties initial_qos_;
146 /// Initial admin props specified to the factory when creating the EC.
147 CosNotification::AdminProperties initial_admin_;
149 /// The consumer admin used by consumers.
150 CosNotifyChannelAdmin::ConsumerAdmin_var consumer_admin_;
152 /// The supplier admin used by suppliers.
153 CosNotifyChannelAdmin::SupplierAdmin_var supplier_admin_;
155 RedGreen_Test_StructuredPushConsumer* normal_consumer_;
156 RedGreen_Test_StructuredPushConsumer* slow_consumer_;
158 RedGreen_Test_StructuredPushSupplier* supplier_;
161 /*****************************************************************/
162 class RedGreen_Test_StructuredPushConsumer
163 : public POA_CosNotifyComm::StructuredPushConsumer
165 // = TITLE
166 // RedGreen_Test_StructuredPushConsumer
168 // = DESCRIPTION
169 // Consumer for the RedGreen_Test example.
171 public:
172 /// Constructor.
173 RedGreen_Test_StructuredPushConsumer (RedGreen_Test* RedGreen_Test);
175 /// Connect the Consumer to the EventChannel.
176 /// Creates a new proxy supplier and connects to it.
177 void connect (CosNotifyChannelAdmin::ConsumerAdmin_ptr consumer_admin);
179 /// Disconnect from the supplier.
180 virtual void disconnect ();
182 /// Accessor for the Proxy that we're connected to.
183 CosNotifyChannelAdmin::StructuredProxyPushSupplier_ptr get_proxy_supplier ();
185 /// Accumulate the throughput statistics into <throughput>
186 void accumulate_into (ACE_Throughput_Stats &throughput) const;
188 /// Accumulate the throughput statistics into <throughput>
189 void dump_stats (const ACE_TCHAR* msg,
190 ACE_High_Res_Timer::global_scale_factor_type gsf);
192 protected:
193 // = Data members
194 /// The proxy that we are connected to.
195 CosNotifyChannelAdmin::StructuredProxyPushSupplier_var proxy_supplier_;
197 /// The proxy_supplier id.
198 CosNotifyChannelAdmin::ProxyID proxy_supplier_id_;
200 /// callback <done>
201 RedGreen_Test* RedGreen_Test_;
203 /// Protect internal state
204 TAO_SYNCH_MUTEX lock_;
206 int push_count_;
208 /// Used for reporting stats
209 ACE_Throughput_Stats throughput_;
211 // = Methods
212 /// Destructor
213 virtual ~RedGreen_Test_StructuredPushConsumer ();
215 // = NotifyPublish method
216 virtual void offer_change (
217 const CosNotification::EventTypeSeq & added,
218 const CosNotification::EventTypeSeq & removed);
220 // = StructuredPushSupplier methods
221 virtual void push_structured_event (
222 const CosNotification::StructuredEvent & notification);
224 virtual void disconnect_structured_push_consumer ();
227 /*****************************************************************/
229 class SlowConsumer : public RedGreen_Test_StructuredPushConsumer
231 public:
232 SlowConsumer (RedGreen_Test* RedGreen_Test);
234 virtual void push_structured_event (
235 const CosNotification::StructuredEvent & notification);
238 /*****************************************************************/
239 class RedGreen_Test_StructuredPushSupplier
240 : public POA_CosNotifyComm::StructuredPushSupplier
242 // = TITLE
243 // RedGreen_Test_StructuredPushSupplier
245 // = DESCRIPTION
246 // Supplier for the RedGreen_Test example.
248 public:
249 /// Constructor.
250 RedGreen_Test_StructuredPushSupplier ();
252 /// Connect the Supplier to the EventChannel.
253 /// Creates a new proxy supplier and connects to it.
254 void connect (CosNotifyChannelAdmin::SupplierAdmin_ptr supplier_admin);
256 /// Disconnect from the supplier.
257 void disconnect ();
259 /// Send one event.
260 virtual void send_event (CosNotification::StructuredEvent& event);
262 /// Accumulate the throughput statistics into <throughput>
263 void accumulate_into (ACE_Throughput_Stats &throughput) const;
265 /// Accumulate the throughput statistics into <throughput>
266 void dump_stats (const ACE_TCHAR* msg,
267 ACE_High_Res_Timer::global_scale_factor_type gsf);
269 protected:
270 // = Data members
271 /// The proxy that we are connected to.
272 CosNotifyChannelAdmin::StructuredProxyPushConsumer_var proxy_consumer_;
274 /// This supplier's id.
275 CosNotifyChannelAdmin::ProxyID proxy_consumer_id_;
277 /// Measure the elapsed time spent while sending the events.
278 ACE_Throughput_Stats throughput_;
280 // = Protected Methods
281 /// Destructor
282 virtual ~RedGreen_Test_StructuredPushSupplier ();
284 // = NotifyRedGreen_Test
285 virtual void subscription_change (
286 const CosNotification::EventTypeSeq & added,
287 const CosNotification::EventTypeSeq & removed);
289 // = StructuredPushSupplier method
290 virtual void disconnect_structured_push_supplier ();
293 /*****************************************************************/
295 #if defined(_MSC_VER)
296 #pragma warning(pop)
297 #endif /* _MSC_VER */
299 #endif /* NOTIFY_RedGreen_Test_CLIENT_H */