2 #include "ace/Get_Opt.h"
4 #include "ace/OS_NS_stdio.h"
6 #if TAO_HAS_INTERCEPTORS
8 #include "Server_ORBInitializer.h"
9 #include "Server_Request_Interceptor.h"
10 #include "tao/IORManipulation/IORManipulation.h"
11 #include "tao/ORBInitializer_Registry.h"
12 #include "orbsvcs/FaultTolerance/FT_Service_Activate.h"
13 #include "orbsvcs/FaultTolerance/FT_IOGR_Property.h"
14 #include "orbsvcs/FT_CORBA_ORBC.h"
16 const ACE_TCHAR
*ior_file
= 0;
19 parse_args (int argc
, ACE_TCHAR
*argv
[])
21 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
24 while ((c
= get_opts ()) != -1)
28 ior_file
= get_opts
.opt_arg ();
31 ACE_ERROR_RETURN ((LM_ERROR
,
42 add_ft_prop (CORBA::ORB_ptr o
,
43 CORBA::Object_ptr obj1
,
44 CORBA::Object_ptr obj2
)
46 // Get an object reference for the ORBs IORManipultion object!
47 CORBA::Object_var IORM
=
48 o
->resolve_initial_references (TAO_OBJID_IORMANIPULATION
,
51 TAO_IOP::TAO_IOR_Manipulation_var iorm
=
52 TAO_IOP::TAO_IOR_Manipulation::_narrow (IORM
.in());
54 FT::TagFTGroupTaggedComponent ft_tag_component
;
57 // Major and Minor revision numbers
58 ft_tag_component
.component_version
.major
= (CORBA::Octet
) 1;
59 ft_tag_component
.component_version
.minor
= (CORBA::Octet
) 0;
62 const char *id
= "version_testing";
63 ft_tag_component
.group_domain_id
= id
;
66 ft_tag_component
.object_group_id
=
67 (CORBA::ULongLong
) 10;
70 ft_tag_component
.object_group_ref_version
=
73 // Construct the IOGR Property class
74 TAO_FT_IOGR_Property
iogr_prop (ft_tag_component
);
76 // Set the property for object 1
77 CORBA::Boolean retval
= iorm
->set_property (&iogr_prop
,
82 retval
= iorm
->set_primary (&iogr_prop
,
88 // Set the property for object 2
89 // Change the version. That is the point of this test
91 ft_tag_component
.object_group_ref_version
= (CORBA::ULong
) 5;
93 retval
= iorm
->set_property (&iogr_prop
,
98 retval
= iorm
->set_primary (&iogr_prop
,
106 void test_colocal (ForwardRequestTest::test_ptr server
)
108 CORBA::ULong number
= 0;
109 for (int i
= 1; i
<= 25; ++i
)
112 "CLIENT: Issuing colocal request %d.\n",
114 CORBA::ULong retval
=
116 if (retval
!= 1 && retval
!= 317)
118 // Not a valid return value, forwarding went wrong and
119 // retval is in udefined state
120 ACE_ERROR ((LM_ERROR
,
121 "(%P|%t) ERROR: colocal invocation returned invalid"
122 " value, location-forwarding must have failed.\n"));
130 "CLIENT: Number %d .\n",
136 ACE_ERROR ((LM_ERROR
,
137 "(%P|%t) ERROR: Did not forward to new location\n"));
144 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
148 Server_ORBInitializer
*temp_initializer
= 0;
149 ACE_NEW_RETURN (temp_initializer
,
150 Server_ORBInitializer
,
151 -1); // No exceptions yet!
152 PortableInterceptor::ORBInitializer_var orb_initializer
=
155 PortableInterceptor::register_orb_initializer (orb_initializer
.in ());
158 CORBA::ORB_init (argc
, argv
, "Server ORB");
160 CORBA::Object_var poa_object
=
161 orb
->resolve_initial_references ("RootPOA");
163 if (CORBA::is_nil (poa_object
.in ()))
164 ACE_ERROR_RETURN ((LM_ERROR
,
165 " (%P|%t) Unable to initialize the POA.\n"),
168 PortableServer::POA_var root_poa
=
169 PortableServer::POA::_narrow (poa_object
.in ());
171 PortableServer::POAManager_var poa_manager
=
172 root_poa
->the_POAManager ();
174 if (::parse_args (argc
, argv
) != 0)
177 CORBA::PolicyList policies
; // Empty policy list.
180 test_i
servant1 (1, orb
.in ());
181 test_i
servant2 (317, orb
.in ());
183 PortableServer::POA_var first_poa
=
184 root_poa
->create_POA ("first POA",
190 PortableServer::ObjectId_var oid1
=
191 first_poa
->activate_object (&servant1
);
193 PortableServer::ObjectId_var oid2
=
194 first_poa
->activate_object (&servant2
);
196 CORBA::Object_var obj1
=
197 first_poa
->servant_to_reference (&servant1
);
199 CORBA::Object_var obj2
=
200 first_poa
->servant_to_reference (&servant2
);
202 (void) add_ft_prop (orb
.in (),
206 CORBA::String_var ior
=
207 orb
->object_to_string (obj1
.in ());
209 ACE_DEBUG ((LM_DEBUG
,
210 "ForwardRequestTest::test servant 1: <%s>\n",
213 poa_manager
->activate ();
215 // Set the forward references in the server request interceptor.
216 PortableInterceptor::ServerRequestInterceptor_var
217 server_interceptor
= temp_initializer
->server_interceptor ();
219 ForwardRequestTest::ServerRequestInterceptor_var interceptor
=
220 ForwardRequestTest::ServerRequestInterceptor::_narrow (
221 server_interceptor
.in ());
223 if (CORBA::is_nil (interceptor
.in ()))
224 ACE_ERROR_RETURN ((LM_ERROR
,
225 "(%P|%t) Could not obtain reference to "
226 "server request interceptor.\n"),
229 interceptor
->forward_references (obj1
.in (),
234 ForwardRequestTest::test_var server
=
235 ForwardRequestTest::test::_narrow (obj1
.in ());
236 test_colocal (server
.in());
238 // Reset interceptor for remote tests
239 interceptor
->reset ();
242 // Write each IOR to a file.
245 FILE *output_file
= ACE_OS::fopen (ior_file
, "w");
246 if (output_file
== 0)
247 ACE_ERROR_RETURN ((LM_ERROR
,
248 "Cannot open output file <%s> for writing "
252 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
253 ACE_OS::fclose (output_file
);
255 // Run the ORB event loop.
258 root_poa
->destroy (1, 1);
262 ACE_DEBUG ((LM_DEBUG
, "Event loop finished.\n"));
264 catch (const CORBA::Exception
& ex
)
266 ex
._tao_print_exception ("Caught exception:");
276 ACE_TMAIN(int, ACE_TCHAR
*[])
281 #endif /* TAO_HAS_INTERCEPTORS */