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
|
// $Id$
//========================================================================
//
// = LIBRARY
// TAO/tests/Connection_Purging
//
// = FILENAME
// Connection_Purging.cpp
//
// = DESCRIPTION
// This program tests automatic purging in TAO. Collocation is off
// which helps us test the usage and purging of handles from the
// connection cache.
//
// = AUTHOR
// Kirthika Parameswaran <kirthika@cs.wustl.edu>
// Irfan Pyarali <irfan@cs.wustl.edu>
//
//=========================================================================
#include "ace/Task.h"
#include "ace/Get_Opt.h"
#include "ace/Handle_Gobbler.h"
#include "testS.h"
struct arguments
{
int argc;
char **argv;
};
struct Info
{
CORBA::ORB_var orb;
PortableServer::POA_var root_poa;
CORBA::String_var ior;
};
// Note: The handles available may seem more than the iterations but
// bear in mind that the server and client are in the same process and
// that per RMI uses up two handles atleast and also that the ORB creation
// uses up a descriptor atleast.
static size_t keep_handles_available = 35;
static size_t iterations = 30;
static size_t remote_calls = 1;
static Info *info = 0;
static int debug = 0;
static int go_to_next_orb = 0;
class test_i : public POA_test
{
public:
test_i (void);
void method (CORBA::Environment &ACE_TRY_ENV)
ACE_THROW_SPEC ((CORBA::SystemException));
private:
size_t counter_;
};
test_i::test_i (void)
: counter_ (0)
{
}
void
test_i::method (CORBA::Environment &)
ACE_THROW_SPEC ((CORBA::SystemException))
{
go_to_next_orb = 1;
if (debug)
ACE_DEBUG ((LM_DEBUG,
"test_i::method() iteration = %d\n",
++this->counter_));
}
class Server_Task : public ACE_Task_Base
{
public:
Server_Task (Info *info);
int svc (void);
private:
Info *info_;
};
Server_Task::Server_Task (Info *info)
: info_ (info)
{
}
int
Server_Task::svc (void)
{
for (size_t j = 0;
j < remote_calls;
++j)
{
for (size_t i = 0;
i < iterations;
++i)
{
while (!go_to_next_orb)
this->info_[i].orb->perform_work ();
go_to_next_orb = 0;
}
}
return 0;
}
static int
parse_args (int argc,
char **argv)
{
ACE_Get_Opt get_opts (argc, argv, "i:a:r:d");
int c;
while ((c = get_opts ()) != -1)
switch (c)
{
case 'i':
iterations = ACE_OS::atoi (get_opts.optarg);
break;
case 'd':
debug = 1;
break;
case 'a':
keep_handles_available = atoi (get_opts.optarg);
break;
case 'r':
remote_calls = atoi (get_opts.optarg);
break;
case '?':
default:
ACE_ERROR_RETURN ((LM_ERROR,
"usage: %s \n"
"[-i iterations] \n"
"[-d (debug)] \n"
"[-a (keep handles available)] \n",
"[-r (remote calls per server)] \n",
"\n",
argv [0]),
-1);
}
// Indicates successful parsing of command line.
return 0;
}
void
setup_server_orbs (test_i &servant,
int argc,
char **argv)
{
ACE_NEW (info,
Info[iterations]);
for (size_t i = 0;
i < iterations;
++i)
{
int argc_copy = argc;
char **argv_copy = 0;
ACE_NEW (argv_copy,
char *[argc]);
int j = 0;
for (j = 0;
j < argc;
++j)
argv_copy[j] = ACE_OS::strdup (argv[j]);
ACE_DECLARE_NEW_CORBA_ENV;
ACE_TRY
{
char orb_name[BUFSIZ];
ACE_OS::sprintf (orb_name,
"%d",
i);
// Initialize the ORB first.
info[i].orb = CORBA::ORB_init (argc_copy,
argv_copy,
orb_name,
ACE_TRY_ENV);
ACE_TRY_CHECK;
for (j = 0;
j < argc;
++j)
ACE_OS::free (argv_copy[j]);
delete[] argv_copy;
// Obtain the RootPOA.
CORBA::Object_var object = info[i].orb->resolve_initial_references ("RootPOA",
ACE_TRY_ENV);
// Get the POA_var object from Object_var.
info[i].root_poa =
PortableServer::POA::_narrow (object.in (),
ACE_TRY_ENV);
ACE_TRY_CHECK;
// Get the POAManager of the RootPOA.
PortableServer::POAManager_var poa_manager =
info[i].root_poa->the_POAManager (ACE_TRY_ENV);
ACE_TRY_CHECK;
poa_manager->activate (ACE_TRY_ENV);
ACE_TRY_CHECK;
PortableServer::ObjectId_var id =
info[i].root_poa->activate_object (&servant,
ACE_TRY_ENV);
ACE_TRY_CHECK;
object = info[i].root_poa->id_to_reference (id.in (),
ACE_TRY_ENV);
ACE_TRY_CHECK;
info[i].ior =
info[i].orb->object_to_string (object.in (),
ACE_TRY_ENV);
ACE_TRY_CHECK;
}
ACE_CATCHANY
{
ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Exception in setting up servers");
ACE_ASSERT (0);
}
ACE_ENDTRY;
}
}
void
setup_client_orb (CORBA::ORB_out client_orb,
int argc,
char **argv)
{
ACE_DECLARE_NEW_CORBA_ENV;
ACE_TRY
{
// Initialize the client ORB first.
client_orb = CORBA::ORB_init (argc,
argv,
0,
ACE_TRY_ENV);
ACE_TRY_CHECK;
}
ACE_CATCHANY
{
ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Exception in initializing client ORB");
ACE_ASSERT (0);
}
ACE_ENDTRY;
}
//void
int
invoke_remote_calls (CORBA::ORB_ptr client_orb)
{
ACE_DECLARE_NEW_CORBA_ENV;
ACE_TRY
{
for (size_t j = 0;
j < remote_calls;
++j)
{
if (debug)
ACE_DEBUG ((LM_DEBUG, "remote_call %d\n", j));
for (size_t i = 0;
i < iterations;
++i)
{
if (debug)
ACE_DEBUG ((LM_DEBUG, "invoke_remote_calls::iteration %d\n", i));
CORBA::Object_var object =
client_orb->string_to_object (info[i].ior.in (),
ACE_TRY_ENV);
ACE_TRY_CHECK;
test_var test_object =
test::_narrow (object.in (),
ACE_TRY_ENV);
ACE_TRY_CHECK;
size_t invoke_exception = 0;
for (int try_invoke = 0; try_invoke < 3; ++try_invoke)
{
ACE_TRY_EX (try_again_block)
{
invoke_exception = 0;
test_object->method (ACE_TRY_ENV);
ACE_TRY_CHECK_EX (try_again_block);
}
ACE_CATCHANY
{
if (debug)
ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "invoke_remote_calls::Expected Exception!");
if (debug)
ACE_DEBUG ((LM_DEBUG, "Trying again...invoke_remote_calls::iteration %d\n", i));
invoke_exception = 1;
}
ACE_ENDTRY;
if (invoke_exception != 0)
continue;
else
break;
}
if (invoke_exception == 1)
return -1;
}
}
}
ACE_CATCHANY
{
ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Exception in invoke_remote_calls on client side");
ACE_ASSERT (0);
}
ACE_ENDTRY;
return 0;
}
void
orbs_shutdown (void)
{
ACE_DECLARE_NEW_CORBA_ENV;
ACE_TRY
{
for (size_t i = 0;
i < iterations;
++i)
{
info[i].orb->shutdown (1,
ACE_TRY_ENV);
ACE_TRY_CHECK;
info[i].root_poa->destroy (1,
1,
ACE_TRY_ENV);
ACE_TRY_CHECK;
}
}
ACE_CATCHANY
{
ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Exception in shutting orbs");
ACE_ASSERT (0);
}
ACE_ENDTRY;
delete[] info;
}
int
main (int argc,
char *argv [])
{
int argc_copy = argc;
char **argv_copy = 0;
ACE_NEW_RETURN (argv_copy,
char *[argc],
-1);
int j = 0;
for (j = 0;
j < argc;
++j)
argv_copy[j] = ACE_OS::strdup (argv[j]);
CORBA::ORB_var client_orb;
setup_client_orb (client_orb.out (),
argc,
argv);
int result = parse_args (argc,
argv);
if (result != 0)
return result;
test_i servant;
setup_server_orbs (servant,
argc_copy,
argv_copy);
for (j = 0;
j < argc;
++j)
ACE_OS::free (argv_copy[j]);
delete[] argv_copy;
Server_Task server_task (info);
result = server_task.activate (THR_BOUND);
ACE_ASSERT (result == 0);
// Consume all handles in the process, leaving us
// <keep_handles_available> to play with.
ACE_Handle_Gobbler handle_gobbler;
result = handle_gobbler.consume_handles (keep_handles_available);
ACE_ASSERT (result == 0);
result = invoke_remote_calls (client_orb.in ());
if (result == 0)
ACE_DEBUG ((LM_DEBUG, "Test succeeds!\n"));
else
{
ACE_DEBUG ((LM_DEBUG, "Test failure!\n"));
ACE_ASSERT (0);
}
//orbs_shutdown ();
go_to_next_orb = 1;
server_task.wait ();
return 0;
}
#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
// = Handle Gobbler
template class ACE_Unbounded_Set<ACE_HANDLE>;
template class ACE_Unbounded_Set_Iterator<ACE_HANDLE>;
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
// = Handle Gobbler
#pragma instantiate ACE_Unbounded_Set<ACE_HANDLE>
#pragma instantiate ACE_Unbounded_Set_Iterator<ACE_HANDLE>
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
|