2 #include "tao/RTCORBA/RTCORBA.h"
3 #include "tao/Policy_ManagerC.h"
4 #include "tao/Policy_CurrentC.h"
5 #include "ace/Get_Opt.h"
7 const ACE_TCHAR
*ior1
= ACE_TEXT("file://test1.ior");
8 const ACE_TCHAR
*ior2
= ACE_TEXT("file://test2.ior");
11 parse_args (int argc
, ACE_TCHAR
*argv
[])
13 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:p:"));
16 while ((c
= get_opts ()) != -1)
20 ior1
= get_opts
.opt_arg ();
23 ior2
= get_opts
.opt_arg ();
27 ACE_ERROR_RETURN ((LM_ERROR
,
40 check_for_nil (CORBA::Object_ptr obj
, const char *msg
)
42 if (CORBA::is_nil (obj
))
43 ACE_ERROR_RETURN ((LM_ERROR
,
44 "ERROR: Object reference <%C> is nil\n",
52 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
56 // Initialize the ORB, resolve references and parse arguments.
60 CORBA::ORB_init (argc
, argv
);
63 if (parse_args (argc
, argv
) != 0)
67 CORBA::Object_var object
=
68 orb
->resolve_initial_references ("RTORB");
69 RTCORBA::RTORB_var rt_orb
= RTCORBA::RTORB::_narrow (object
.in ());
70 if (check_for_nil (rt_orb
.in (), "RTORB") == -1)
74 object
= orb
->resolve_initial_references ("PolicyCurrent");
75 CORBA::PolicyCurrent_var policy_current
=
76 CORBA::PolicyCurrent::_narrow (object
.in ());
77 if (check_for_nil (policy_current
.in (), "PolicyCurrent")
82 object
= orb
->string_to_object (ior1
);
83 Test_var server1
= Test::_narrow (object
.in ());
84 if (check_for_nil (server1
.in (), "server1") == -1)
88 object
= orb
->string_to_object (ior2
);
89 Test_var server2
= Test::_narrow (object
.in ());
90 if (check_for_nil (server2
.in (), "server2") == -1)
93 // Make four invocations on test objects. Expected: connection
94 // established on the first invocation, and reused in the
97 "\n Invocation 1 --> new connection\n"));
98 server1
->test_method ();
100 ACE_DEBUG ((LM_DEBUG
,
101 "\n Invocation 2 --> use connection from invocation 1\n"));
102 server2
->test_method ();
104 ACE_DEBUG ((LM_DEBUG
,
105 "\n Invocation 3 --> use connection from invocation 1\n"));
106 server1
->test_method ();
108 ACE_DEBUG ((LM_DEBUG
,
109 "\n Invocation 4 --> use connection from invocation 1\n"));
110 server2
->test_method ();
112 // Set RTCORBA::PrivateConnectionPolicy on PolicyCurrent.
113 CORBA::PolicyList policy_list
;
114 policy_list
.length (1);
116 rt_orb
->create_private_connection_policy ();
118 policy_current
->set_policy_overrides (policy_list
,
119 CORBA::SET_OVERRIDE
);
121 // Make four invocations on test objects again. This time,
122 // since RTCORBA::PrivateConnectionPolicy is set, we expect a
123 // connection to be established for <server1> during the first
124 // invocation, a connection to be established for <server2> during
125 // the second invocation, <server1>'s connection reused on
126 // third, and <server2>'s reused on fourth.
127 ACE_DEBUG ((LM_DEBUG
,
128 "\n Invocation 5 --> new connection\n"));
129 server1
->test_method ();
131 ACE_DEBUG ((LM_DEBUG
,
132 "\n Invocation 6 --> new connection\n"));
133 server2
->test_method ();
135 ACE_DEBUG ((LM_DEBUG
,
136 "\n Invocation 7 --> use connection from invocation 5\n"));
137 server1
->test_method ();
139 ACE_DEBUG ((LM_DEBUG
,
140 "\n Invocation 8 --> use connection from invocation 6\n"));
141 server2
->test_method ();
143 // Testing over. Shut down Server ORB.
144 ACE_DEBUG ((LM_DEBUG
,
145 "\n Testing over - shutting down\n"));
146 server1
->shutdown ();
148 catch (const CORBA::Exception
& ex
)
150 ex
._tao_print_exception (
151 "Unexpected exception caught in Private_Connection test client:");