1
// Sequence_Consumer.cpp,v 1.8 2003/11/02 23:27:22 dhinton Exp
3
// ******************************************************************
5
// ******************************************************************
7
#include "ace/Get_Opt.h"
9
#include "orbsvcs/CosNotifyCommC.h"
10
#include "orbsvcs/CosNamingC.h"
11
#include "Notify_Sequence_Push_Consumer.h"
13
#include "tao/debug.h"
14
#include "ace/OS_NS_sys_time.h"
16
#include "Notify_Test_Client.h"
18
// ******************************************************************
20
// ******************************************************************
22
static const char* ior = "file://supplier.ior";
23
static CORBA::Boolean done = 0;
24
static CORBA::Boolean dummy = 0;
25
static CORBA::Boolean filter = 0;
26
static unsigned int consumers = 2;
27
static unsigned int batch_size = 10;
28
static unsigned int expected = 50; // 50 sets of 10
30
#define GRAMMAR "EXTENDED_TCL"
32
// ******************************************************************
34
// ******************************************************************
36
class Consumer_Client : public Notify_Test_Client
39
virtual int parse_args (int argc, char* argv[]);
44
Consumer_Client::parse_args (int argc, char *argv[])
46
ACE_Get_Opt get_opts (argc, argv, "k:c:e:f");
49
while ((c = get_opts ()) != -1)
53
ior = get_opts.optarg;
57
consumers = ACE_OS::atoi (get_opts.optarg);
61
expected = ACE_OS::atoi (get_opts.optarg);
69
ACE_ERROR_RETURN ((LM_ERROR,
72
"-c <# of consumers> "
73
"-e <expected events> "
79
// Indicates sucessful parsing of the command line
84
static CosNotifyChannelAdmin::ConsumerAdmin_ptr
85
create_consumeradmin (CosNotifyChannelAdmin::EventChannel_ptr ec
88
CosNotifyChannelAdmin::AdminID adminid = 0;
89
CosNotifyChannelAdmin::ConsumerAdmin_var admin =
90
ec->new_for_consumers (CosNotifyChannelAdmin::OR_OP,
92
ACE_ENV_ARG_PARAMETER);
99
CosNotifyFilter::FilterFactory_var ffact =
100
ec->default_filter_factory (ACE_ENV_SINGLE_ARG_PARAMETER);
101
ACE_CHECK_RETURN (0);
104
CosNotifyFilter::Filter_var filter =
105
ffact->create_filter (GRAMMAR ACE_ENV_ARG_PARAMETER);
106
ACE_CHECK_RETURN (0);
108
CosNotifyFilter::ConstraintExpSeq constraint_list (1);
109
constraint_list.length (1);
111
constraint_list[0].event_types.length (0);
112
constraint_list[0].constraint_expr =
113
CORBA::string_dup ("type == 'even'");
115
filter->add_constraints (constraint_list ACE_ENV_ARG_PARAMETER);
116
ACE_CHECK_RETURN (0);
118
admin->add_filter (filter.in () ACE_ENV_ARG_PARAMETER);
119
ACE_CHECK_RETURN (0);
123
return CosNotifyChannelAdmin::ConsumerAdmin::_duplicate (admin.in ());
128
create_consumers (CosNotifyChannelAdmin::ConsumerAdmin_ptr admin,
129
Notify_Test_Client* client
132
for(unsigned int i = 0; i < consumers; i++)
134
// startup the first consumer
136
ACE_OS::sprintf(name, "consumer%u", i);
137
Notify_Sequence_Push_Consumer* consumer;
138
ACE_NEW_THROW_EX (consumer,
139
Notify_Sequence_Push_Consumer (
142
(i + 1 == consumers ? done : dummy)),
143
CORBA::NO_MEMORY ());
145
consumer->init (client->root_poa () ACE_ENV_ARG_PARAMETER);
148
consumer->_connect (admin ACE_ENV_ARG_PARAMETER);
153
// ******************************************************************
155
// ******************************************************************
157
int main (int argc, char* argv[])
162
Consumer_Client client;
164
status = client.init (argc, argv ACE_ENV_ARG_PARAMETER);
169
// If we are filtering, we will get half as many as originally
176
CosNotifyChannelAdmin::EventChannel_var ec =
177
client.create_event_channel ("MyEventChannel", 1
178
ACE_ENV_ARG_PARAMETER);
181
CORBA::ORB_ptr orb = client.orb ();
182
CORBA::Object_var object =
183
orb->string_to_object (ior ACE_ENV_ARG_PARAMETER);
186
sig_var sig = sig::_narrow (object.in () ACE_ENV_ARG_PARAMETER);
189
if (CORBA::is_nil (sig.in ()))
191
ACE_ERROR_RETURN ((LM_ERROR,
192
"Object reference <%s> is nil\n",
197
CosNotifyChannelAdmin::ConsumerAdmin_var admin =
198
create_consumeradmin (ec.in () ACE_ENV_ARG_PARAMETER);
201
if (!CORBA::is_nil (admin.in ()))
203
create_consumers(admin.in (), &client ACE_ENV_ARG_PARAMETER);
206
// Tell the supplier to go
207
sig->go (ACE_ENV_SINGLE_ARG_PARAMETER);
210
ACE_Time_Value now = ACE_OS::gettimeofday ();
213
if (orb->work_pending ())
215
orb->perform_work ();
218
ACE_Time_Value then = ACE_OS::gettimeofday ();
220
static const unsigned int per = 100;
221
ACE_Time_Value difference = then - now;
222
double denominator = per / ((double)expected *
224
difference *= denominator;
228
"Average of %ds %dus for %u events\n",
229
difference.sec (), difference.usec (), per));
233
ACE_CATCH (CORBA::Exception, e)
235
ACE_PRINT_EXCEPTION (e,
236
"Consumer exception: ");