3 #include "Client_ORBInitializer.h"
5 #include "tao/ORBInitializer_Registry.h"
6 #include "tao/PI_Server/PI_Server.h"
9 #include "ace/Get_Opt.h"
10 #include "ace/OS_NS_unistd.h"
13 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("client.ior");
14 const ACE_TCHAR
*server1_ior
= ACE_TEXT("file://server1.ior");
15 const ACE_TCHAR
*server2_ior
= ACE_TEXT("file://server2.ior");
16 const ACE_TCHAR
*server1_shutdown_ior
= ACE_TEXT("file://server1_shutdown.ior");
17 const ACE_TCHAR
*server2_shutdown_ior
= ACE_TEXT("file://server2_shutdown.ior");
20 Demo::HelloWorld_var server1_shutdownObj
;
21 Demo::HelloWorld_var server2_shutdownObj
;
22 int test_duration
= 30;
23 bool reconnected
= false;
24 bool caught_exception
= false;
26 class ClientTask
: public ACE_Task_Base
29 ClientTask () = default;
30 ~ ClientTask () = default;
34 CORBA::Object_var helloObj
= orb
->string_to_object(server1_ior
);
36 Demo::HelloWorld_var hello
= Demo::HelloWorld::_narrow(helloObj
.in ());
38 if (CORBA::is_nil(hello
.in ()))
40 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("hello reference is nil\n")));
45 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("ClientTask start.\n")));
47 ACE_Time_Value due
= ACE_OS::gettimeofday () + ACE_Time_Value (test_duration
);
49 while (ACE_OS::gettimeofday () < due
)
54 ACE_DEBUG((LM_DEBUG
, ACE_TEXT("(%P|%t)======client calling server1 sayHello %d\n"), i
));
55 const char* pMsg
= " server1 say Hello";
56 hello
->sayHello(pMsg
);
59 if (caught_exception
) {
60 // Reconncted to server 1
61 ACE_DEBUG((LM_DEBUG
, ACE_TEXT("(%P|%t) client reconnected to server 1\n")));
65 catch (const CORBA::TRANSIENT
&)
67 caught_exception
= true;
68 if (TAO_debug_level
> 0) {
69 ACE_DEBUG((LM_DEBUG
, ACE_TEXT ("sayHello() expected TRANSIENT exceptions.\n")));
73 ACE_ERROR((LM_ERROR
, ACE_TEXT ("sayHello() caught unknown exception\n")));
83 parse_args (int argc
, ACE_TCHAR
*argv
[])
85 ACE_Get_Opt
get_opts (argc
, argv
, "t:");
88 while ((c
= get_opts ()) != -1)
92 test_duration
= ACE_OS::atoi(get_opts
.opt_arg());
97 ACE_ERROR_RETURN ((LM_ERROR
,
104 // Indicates successful parsing of the command line
110 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
114 PortableInterceptor::ORBInitializer_ptr temp_initializer
;
116 ACE_NEW_RETURN (temp_initializer
,
117 Client_ORBInitializer(),
119 PortableInterceptor::ORBInitializer_var initializer
=
122 PortableInterceptor::register_orb_initializer (initializer
.in ());
124 orb
= CORBA::ORB_init (argc
, argv
);
126 // Initialize options based on command-line arguments.
127 if (parse_args (argc
, argv
))
132 CORBA::Object_var shutdownObj
= orb
->string_to_object(server1_shutdown_ior
);
134 server1_shutdownObj
= Demo::HelloWorld::_narrow(shutdownObj
.in ());
136 if (CORBA::is_nil(server1_shutdownObj
.in ()))
138 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("server1 shutdown object reference is nil\n")));
142 shutdownObj
= orb
->string_to_object(server2_shutdown_ior
);
144 server2_shutdownObj
= Demo::HelloWorld::_narrow(shutdownObj
.in ());
146 if (CORBA::is_nil(server2_shutdownObj
.in ()))
148 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("server2 shutdown object reference is nil\n")));
153 if (task
.activate(THR_NEW_LWP
| THR_JOINABLE
, 1) != 0)
155 ACE_ERROR_RETURN ((LM_ERROR
,
156 "Cannot activate client threads\n"),
162 server1_shutdownObj
->shutdown ();
163 server2_shutdownObj
->shutdown ();
165 server1_shutdownObj
= Demo::HelloWorld::_nil ();
166 server2_shutdownObj
= Demo::HelloWorld::_nil ();
170 orb
= CORBA::ORB::_nil ();
173 ACE_ERROR_RETURN ((LM_ERROR
,
174 "Client was not able to reconnect to server 1.\n"),
179 catch (const CORBA::Exception
&e
)
181 std::cerr
<< "Unexpected exception: " << e
<< std::endl
;