2 #include "tao/RTCORBA/RTCORBA.h"
3 #include "tao/Policy_Current.h"
4 #include "tao/Policy_Current.h"
5 #include "ace/Get_Opt.h"
11 parse_args (int argc
, ACE_TCHAR
*argv
[])
13 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("c:p:"));
16 while ((c
= get_opts ()) != -1)
20 cache_size
= ACE_OS::atoi (get_opts
.opt_arg ());
24 port_nr
= ACE_OS::atoi (get_opts
.opt_arg ());
29 ACE_ERROR_RETURN ((LM_ERROR
,
31 "-c <transport_cache_size>\n"
32 "-p <server_port_nr>\n",
36 // Indicates successful parsing of the command line
41 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
45 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
47 if (parse_args(argc
, argv
) != 0)
51 CORBA::Object_var obj
= orb
->resolve_initial_references ("RTORB");
52 RTCORBA::RTORB_var rtorb
= RTCORBA::RTORB::_narrow (obj
.in());
53 //create the private connections policy. This means that every connection
54 // to the server uses his own socket.
55 CORBA::PolicyList
policies (1);
57 policies
[0] = rtorb
->create_private_connection_policy ();
59 CORBA::Object_var pol_current_object
= orb
->resolve_initial_references ("PolicyCurrent");
61 CORBA::PolicyCurrent_var policy_current
=
62 CORBA::PolicyCurrent::_narrow (pol_current_object
.in ());
64 if (CORBA::is_nil (policy_current
.in ()))
66 ACE_ERROR ((LM_ERROR
, "ERROR: Nil policy current\n"));
69 policy_current
->set_policy_overrides (policies
, CORBA::ADD_OVERRIDE
);
71 Test::Hello_var
*hello_array
= 0;
72 ACE_NEW_RETURN (hello_array
, Test::Hello_var
[cache_size
], -1);
75 for (iter
= 1; iter
<= cache_size
; ++iter
)
77 char object_string
[256];
78 char reference_string
[256];
79 ACE_OS::sprintf (reference_string
, "TransportCacheTest%d", iter
);
80 ACE_OS::sprintf (object_string
, "corbaloc:iiop:localhost:%d/", port_nr
);
81 ACE_OS::strcat (object_string
, reference_string
);
83 CORBA::Object_var hello_obj
= orb
->string_to_object (object_string
);
84 orb
->register_initial_reference (reference_string
, hello_obj
.in ());
86 CORBA::String_var ior_string
= orb
->object_to_string (hello_obj
.in());
87 ACE_DEBUG((LM_DEBUG
, ACE_TEXT("IOR string for reference %d : %C\n"),
88 iter
, ior_string
.in ()));
89 hello_array
[iter
-1] = Test::Hello::_narrow(hello_obj
.in ());
91 //now we've got the references -> call each and everyone of them
92 for (iter
= 0; iter
< cache_size
; ++iter
)
94 Test::Hello_var hello
= hello_array
[iter
];
95 if (CORBA::is_nil (hello
.in ()))
97 ACE_ERROR_RETURN ((LM_DEBUG
,
98 ACE_TEXT ("Nil Test::Hello reference\n")),
102 CORBA::String_var the_string
= hello
->get_string ();
104 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) - string returned <%C> from reference %d\n",
105 the_string
.in (), iter
+ 1));
107 //shutdown the server
109 hello_array
[0]->shutdown ();
113 catch (const CORBA::Exception
& ex
)
115 ex
._tao_print_exception ("Exception caught:");