1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
|
// $Id$
#include "AdminProperties.h"
#include "ace/Arg_Shifter.h"
#include "ace/Get_Opt.h"
#include "ace/OS_NS_unistd.h"
#include "tao/debug.h"
/***************************************************************************/
AdminProperties_Task::AdminProperties_Task (void)
: supplier_ (0)
, client_ (0)
{
}
void
AdminProperties_Task::init (TAO_Notify_Tests_StructuredPushSupplier *supplier, AdminProperties* client)
{
supplier_ = supplier;
client_ = client;
}
int
AdminProperties_Task::init (int argc, ACE_TCHAR *argv[])
{
return ACE_Task_Base::init (argc, argv);
}
int
AdminProperties_Task::svc (void)
{
// operations:
CosNotification::StructuredEvent event;
// EventHeader
// FixedEventHeader
// EventType
// string
event.header.fixed_header.event_type.domain_name = CORBA::string_dup("*");
// string
event.header.fixed_header.event_type.type_name = CORBA::string_dup("*");
// string
event.header.fixed_header.event_name = CORBA::string_dup("myevent");
// OptionalHeaderFields
// PropertySeq
// sequence<Property>: string name, any value
event.header.variable_header.length (0); // put nothing here
// FilterableEventBody
// PropertySeq
// sequence<Property>: string name, any value
event.filterable_data.length (3);
event.filterable_data[0].name = CORBA::string_dup("threshold");
event.filterable_data[1].name = CORBA::string_dup("temperature");
event.filterable_data[1].value <<= (CORBA::Long)70;
event.filterable_data[2].name = CORBA::string_dup("pressure");
event.filterable_data[2].value <<= (CORBA::Long)80;
// @@ CORBA::Short prio = CosNotification::LowestPriority;
int event_count = this->client_->event_count_;
ACE_DEBUG ((LM_DEBUG, "\n1 supplier sending %d events...\n", event_count));
ACE_DECLARE_NEW_CORBA_ENV;
for (int i = 0 ; i < event_count; ++i)
{
event.filterable_data[0].value <<= (CORBA::Long)i;
event.remainder_of_body <<= (CORBA::Long)i;
ACE_TRY
{
ACE_DEBUG((LM_DEBUG, "+"));
this->supplier_->send_event (event ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
}
ACE_CATCH (CORBA::IMP_LIMIT, impl_limit)
{
if (TAO_debug_level > 0)
ACE_DEBUG ((LM_DEBUG, "\nEvent %d was not send due to Impl Limit reached\n", i));
++ this->client_->rejections_;
}
ACE_CATCHANY
{
ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Error: Exception sending event\n");
return 1;
}
ACE_ENDTRY;
}
return 0;
}
/***************************************************************************/
AdminProperties_StructuredPushConsumer::AdminProperties_StructuredPushConsumer (AdminProperties* client)
: client_ (client)
, events_received_ (0)
{
client_->consumer_start(this);
}
void
AdminProperties_StructuredPushConsumer::push_structured_event (const CosNotification::StructuredEvent & /*notification*/
ACE_ENV_ARG_DECL_NOT_USED)
ACE_THROW_SPEC ((CORBA::SystemException,CosEventComm::Disconnected))
{
++events_received_;
if (events_received_ >= client_->max_queue_length_)
client_->consumer_done(this);
ACE_DEBUG((LM_DEBUG, "-"));
if (TAO_debug_level)
ACE_DEBUG ((LM_DEBUG, "\nConsumer %x received event %d\n", this, events_received_.value ()));
}
/***************************************************************************/
AdminProperties::AdminProperties (void)
: max_queue_length_ (10),
max_consumers_ (3),
max_suppliers_ (3),
reject_new_events_ (0),
consumers_ (4),
suppliers_ (4),
event_count_ (30),
suppliers_connected_count_ (0),
consumers_connected_count_ (0),
rejections_ (0)
{
}
AdminProperties::~AdminProperties (void)
{
}
int
AdminProperties::parse_args(int argc, char *argv[])
{
ACE_Arg_Shifter arg_shifter (argc, argv);
const char *current_arg = 0;
while (arg_shifter.is_anything_left ())
{
if ((current_arg = arg_shifter.get_the_parameter ("-max_queue_length")))
{
this->max_queue_length_ = ACE_OS::atoi (current_arg);
// Max. queue length.
arg_shifter.consume_arg ();
}
else if ((current_arg = arg_shifter.get_the_parameter ("-max_consumers")))
{
this->max_consumers_ = ACE_OS::atoi (current_arg);
// Max consumers allowed to connect.
arg_shifter.consume_arg ();
}
else if ((current_arg = arg_shifter.get_the_parameter ("-max_suppliers")))
{
this->max_suppliers_ = ACE_OS::atoi (current_arg);
// Max. number of suppliers allowed to connect.
arg_shifter.consume_arg ();
}
else if (arg_shifter.cur_arg_strncasecmp ("-reject_new_events") == 0)
{
this->reject_new_events_ = 1;
arg_shifter.consume_arg ();
}
else if ((current_arg = arg_shifter.get_the_parameter ("-consumers")))
{
this->consumers_ = ACE_OS::atoi (current_arg);
// Number of consumers to create.
arg_shifter.consume_arg ();
}
else if ((current_arg = arg_shifter.get_the_parameter ("-suppliers")))
{
this->suppliers_ = ACE_OS::atoi (current_arg);
// Number of suppliers to create.
arg_shifter.consume_arg ();
}
else if (arg_shifter.cur_arg_strncasecmp ("-?") == 0)
{
ACE_DEBUG((LM_DEBUG,
"usage: %s "
"-max_queue_length [max_queue_length] "
"-max_consumers [max_consumers] "
"-max_suppliers [max_suppliers] "
"-reject_new_events [reject_new_events] "
"-consumers [consumers] "
"-suppliers [suppliers] "
"-event_count [event_count] ",
argv[0],
argv[0]));
arg_shifter.consume_arg ();
return -1;
}
else
{
arg_shifter.ignore_arg ();
}
}
return 0;
}
void
AdminProperties::create_channel(bool reject ACE_ENV_ARG_DECL)
{
CosNotifyChannelAdmin::ChannelID id;
initial_admin_.length (4);
this->initial_admin_[0].name =
CORBA::string_dup (CosNotification::MaxQueueLength);
this->initial_admin_[0].value <<= this->max_queue_length_;
this->initial_admin_[1].name =
CORBA::string_dup (CosNotification::MaxSuppliers);
this->initial_admin_[1].value <<= this->max_suppliers_;
this->initial_admin_[2].name =
CORBA::string_dup (CosNotification::MaxConsumers);
this->initial_admin_[2].value <<= this->max_consumers_;
this->initial_admin_[3].name =
CORBA::string_dup (CosNotification::RejectNewEvents);
this->initial_admin_[3].value <<= CORBA::Any::from_boolean (reject);
this->ec_ = notify_factory_->create_channel (this->initial_qos_,
this->initial_admin_,
id
ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (-1);
ACE_ASSERT (!CORBA::is_nil (ec_.in ()));
CosNotifyChannelAdmin::AdminID adminid;
this->supplier_admin_ = ec_->new_for_suppliers (this->ifgop_,
adminid
ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (-1);
ACE_ASSERT (!CORBA::is_nil (supplier_admin_.in ()));
this->consumer_admin_ = ec_->new_for_consumers (this->ifgop_,
adminid
ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (-1);
ACE_ASSERT (!CORBA::is_nil (consumer_admin_.in ()));
}
void
AdminProperties::run_test (ACE_ENV_SINGLE_ARG_DECL)
{
bool reject = true;
this->create_channel(reject ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
this->test_max_queue_length (reject ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
this->ec_->destroy(ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
reject = false;
this->create_channel(reject ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
this->test_max_queue_length (reject ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
this->test_max_clients (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
this->ec_->destroy (ACE_ENV_SINGLE_ARG_PARAMETER);
}
void
AdminProperties::test_max_queue_length (bool reject ACE_ENV_ARG_DECL)
{
// Create the consumer
AdminProperties_StructuredPushConsumer *consumer;
ACE_NEW (consumer, AdminProperties_StructuredPushConsumer (this));
consumer->init (root_poa_.in () ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
consumer->connect (this->consumer_admin_.in () ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
// Create the supplier
TAO_Notify_Tests_StructuredPushSupplier *supplier = 0;
ACE_NEW (supplier, TAO_Notify_Tests_StructuredPushSupplier ());
supplier->init (root_poa_.in () ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
supplier->connect (this->supplier_admin_.in () ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
AdminProperties_Task supplier_task;
// Init the Task to send events;
supplier_task.init (supplier, this);
if (supplier_task.activate (THR_NEW_LWP | THR_JOINABLE, 1) != 0)
{
ACE_ERROR ((LM_ERROR, "\nCannot activate supplier task\n"));
}
// All supplier events should be sent before the first consumer event is
// received. This relies on our use of -ORBClientConnectionHandler RW.
supplier_task.wait ();
this->ORB_run(ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
// consumer is destroyed by consumer->disconnect()
CORBA::Long received_count = consumer->events_received_.value ();
// disconnect the participants.
consumer->disconnect (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
supplier->disconnect (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
// If the reject_new_events setting == true, then the supplier should
// have received an imp_limit exception for each event it tried to push
// after the maximum was reached.
// If the reject_new_events setting == false, then the events should
// have been discarded according to the DiscardPolicy, which for this
// test we leave as AnyOrder.
ACE_DEBUG ((LM_DEBUG, "\nSupplier sent %d events, consumer received %d events, max_queue_length = %d\n",
event_count_, received_count, max_queue_length_));
int expected_min = max_queue_length_;
int expected_max = max_queue_length_ + max_consumers_;
if (reject)
{
expected_max = event_count_ - rejections_;
expected_min = expected_max;
}
if (reject && rejections_ != event_count_ - received_count)
{
ACE_ERROR ((LM_ERROR, "\nError: Expected %d rejections, but got %d\n",
event_count_ - received_count, rejections_));
return;
}
if (received_count < expected_min || received_count > expected_max)
{
ACE_ERROR ((LM_ERROR, "\nError: Expected %d to %d events, but received %d\n",
expected_min, expected_max, received_count));
}
}
void
AdminProperties::test_max_clients (ACE_ENV_SINGLE_ARG_DECL)
{
this->create_suppliers (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
this->create_consumers (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK;
// check the results and print the assessment.
if (this->consumers_connected_count_ > this->max_consumers_)
ACE_DEBUG ((LM_ERROR, "\nConnected consumers %d, exceed MaxConsumers %d\n",
this->consumers_connected_count_ > this->max_consumers_));
if (this->suppliers_connected_count_ > this->max_suppliers_)
ACE_DEBUG ((LM_ERROR, "\nConnected suppliers %d, exceed MaxSuppliers %d\n",
this->suppliers_connected_count_ > this->max_suppliers_));
}
void
AdminProperties::create_suppliers (ACE_ENV_SINGLE_ARG_DECL)
{
// Create the requested number of suppliers.
// @@ CosNotifyChannelAdmin::AdminID adminid;
// @@ CosNotifyChannelAdmin::InterFilterGroupOperator ifgop =
// @@ CosNotifyChannelAdmin::OR_OP;
int index = 0;
ACE_TRY
{
TAO_Notify_Tests_StructuredPushSupplier *supplier;
for (index = 0; index < this->suppliers_; ++index)
{
ACE_NEW (supplier,
TAO_Notify_Tests_StructuredPushSupplier ());
supplier->init (root_poa_.in () ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
supplier->connect (this->supplier_admin_.in ()
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
this->suppliers_connected_count_++;
}
}
ACE_CATCH (CORBA::IMP_LIMIT, impl_limit)
{
if (TAO_debug_level)
ACE_DEBUG ((LM_DEBUG, "\nImpl Limit excpetion when connecting supplier\n"));
}
ACE_CATCHANY
{
ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
"\nError: Exception in connecting supplier\n");
}
ACE_ENDTRY;
}
void
AdminProperties::create_consumers (ACE_ENV_SINGLE_ARG_DECL)
{
// Create the requested number of suppliers.
// @@ CosNotifyChannelAdmin::AdminID adminid;
// @@ CosNotifyChannelAdmin::InterFilterGroupOperator ifgop =
// @@ CosNotifyChannelAdmin::OR_OP;
int index = 0;
ACE_TRY
{
TAO_Notify_Tests_StructuredPushConsumer *consumer;
for (index = 0; index < this->consumers_; ++index)
{
ACE_NEW (consumer, TAO_Notify_Tests_StructuredPushConsumer ());
consumer->init (root_poa_.in () ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
consumer->connect (this->consumer_admin_.in () ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
this->consumers_connected_count_++;
}
}
ACE_CATCH (CORBA::IMP_LIMIT, impl_limit)
{
if (TAO_debug_level)
ACE_DEBUG ((LM_DEBUG, "\nImpl Limit exception when connecting consumer\n"));
}
ACE_CATCHANY
{
ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
"\nError: Exception in connecting consumer \n");
}
ACE_ENDTRY;
}
/***************************************************************************/
int
main (int argc, char* argv[])
{
AdminProperties test;
ACE_TRY_NEW_ENV
{
test.init (argc, argv ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
test.run_test (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
}
ACE_CATCH (CORBA::Exception, se)
{
ACE_PRINT_EXCEPTION (se, "Error: ");
return 1;
}
ACE_ENDTRY;
return 0;
}
|