2 #include "ace/Get_Opt.h"
3 #include "ace/Time_Value.h"
4 #include "orbsvcs/Naming/Naming_Client.h"
5 #include "orbsvcs/FT_NamingManagerC.h"
6 #include "orbsvcs/Naming/FaultTolerant/nsgroup_svc.h"
10 const ACE_TCHAR
*group_names
[] =
11 {ACE_TEXT("C++ Group"), ACE_TEXT("FORTRAN Group"), ACE_TEXT("Groovy Group"), ACE_TEXT("Basic Group"),
12 ACE_TEXT("Java Group"), ACE_TEXT("Forth Group"), ACE_TEXT("COBOL Group"), ACE_TEXT("Ruby Group"),
13 ACE_TEXT("wrong answer dude"), ACE_TEXT("Scala Group"), ACE_TEXT("R Group"), 0};
15 class Hammer
: public ACE_Task_Base
17 NS_group_svc group_svc
;
24 int setup (CORBA::ORB_ptr orb
, FT_Naming::NamingManager_ptr nm
)
26 if (group_svc
.set_orb (orb
) != 0 || group_svc
.set_naming_manager (nm
))
28 ACE_DEBUG ((LM_DEBUG
, "Hammer setup failed\n"));
36 for (int g
= 0, i
= 0; i
< 100; i
++)
39 group_svc
.member_list (group_names
[g
]);
41 catch (PortableGroup::ObjectGroupNotFound
&) {
43 catch (CORBA::Exception
&ex
) {
45 ACE_TEXT ("Hammer thread %t caught %C accessing %C\n"),
46 ex
._name(), group_names
[g
]));
48 if (group_names
[++g
] == 0)
56 const ACE_TCHAR
*ior
= ACE_TEXT("file://obj.ior");
60 parse_args (int argc
, ACE_TCHAR
*argv
[])
62 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:n:"));
65 while ((c
= get_opts ()) != -1)
69 ior
= get_opts
.opt_arg ();
72 hammers
= ACE_OS::atoi (get_opts
.opt_arg ());
76 ACE_ERROR_RETURN ((LM_ERROR
,
77 ACE_TEXT ("usage: %s ")
78 ACE_TEXT ("-k <ior> ")
83 // Indicates successful parsing of the command line
88 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
93 CORBA::ORB_init (argc
, argv
);
95 if (parse_args (argc
, argv
) != 0)
99 ACE_TEXT ("(%P|%t) - Acquiring Name Service\n")));
102 CORBA::Object_var nmobj
= orb
->resolve_initial_references ("NameManager");
103 FT_Naming::NamingManager_var naming_manager
=
104 FT_Naming::NamingManager::_narrow (nmobj
.in());
106 TAO_Naming_Client name_svc
;
108 ACE_Time_Value
timeout (10); // Wait up to 10 seconds for the naming service
109 if (name_svc
.init (orb
.in (), &timeout
) != 0)
110 ACE_ERROR_RETURN ((LM_DEBUG
,
111 ACE_TEXT ("client: Could not connect to ")
112 ACE_TEXT ("naming service.\n")),
115 catch (const CORBA::Exception
& ex
)
117 ex
._tao_print_exception (
118 ACE_TEXT ("Exception caught while initializing name ")
119 ACE_TEXT ("service facade:"));
126 if (hammer
.setup(orb
.in(), naming_manager
.in()) == -1)
131 CosNaming::Name
name (1);
133 name
[0].id
= CORBA::string_dup ("basic_name");
135 CORBA::Object_var tmp
;
136 Test::Basic_var basic
;
138 // Iterate enough so we get a few wrap-arounds
139 for (int i
= 0; i
< 15; i
++)
142 hammer
.activate (THR_NEW_LWP
| THR_JOINABLE
, hammers
);
146 // Each time we invoke resolve, we get a different member
148 name_svc
->resolve (name
);
150 // Narrow it to a Basic object
152 Test::Basic::_narrow (tmp
.in ());
154 catch (CORBA::Exception
& ex
)
156 ex
._tao_print_exception (ACE_TEXT ("Error resolving name.\n"));
159 if (CORBA::is_nil (basic
.in ()))
161 ACE_ERROR_RETURN ((LM_DEBUG
,
162 ACE_TEXT ("Server obj ref not obtained ")
163 ACE_TEXT ("from Load Balancing Name Service\n"),
169 CORBA::String_var the_string
=
170 basic
->get_string ();
172 ACE_DEBUG ((LM_DEBUG
,
173 ACE_TEXT ("(%P|%t) - Client request handled ")
174 ACE_TEXT ("by object at <%C>\n"),
177 catch (CORBA::Exception
& ex
)
179 ex
._tao_print_exception (
180 ACE_TEXT ("Error invoking get_string on Basic object.\n"));
184 // Remove one member after we wrapped around to make sure naming manager can
185 // handle it successufully
189 // Try removing a member
190 basic
->remove_member ();
192 catch (CORBA::Exception
& ex
)
194 ex
._tao_print_exception (
195 ACE_TEXT ("Error invoking get_string on Basic object.\n"));
206 ACE_DEBUG ((LM_DEBUG
,
207 ACE_TEXT ("(%P|%t) - Shutting down server\n")));
209 catch (CORBA::Exception
& ex
)
211 ex
._tao_print_exception (
212 ACE_TEXT ("Error invoking get_string on Basic object.\n"));
217 catch (const CORBA::Exception
& ex
)
219 ex
._tao_print_exception (
220 ACE_TEXT ("Exception caught in client.cpp:"));