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"
13 const CORBA::ULong passes_before_forward
= 6;
15 bool direct_collocation
= false;
18 parse_args (int argc
, ACE_TCHAR
*argv
[])
20 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("d"));
23 while ((c
= get_opts ()) != -1)
27 direct_collocation
= true;
30 ACE_ERROR_RETURN ((LM_ERROR
,
40 void test_colocal (Collocated_ForwardRequestTest::test_ptr server
)
42 CORBA::ULong number
= 0;
43 for (int i
= 1; i
<= 10; ++i
)
46 "CLIENT: Issuing colocal request %d.\n",
49 server
->collocated_call ();
57 "(%P|%t) ERROR: Did not forward to new location\n"));
63 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
67 Server_ORBInitializer
*temp_initializer
= 0;
68 ACE_NEW_RETURN (temp_initializer
,
69 Server_ORBInitializer (passes_before_forward
),
70 -1); // No exceptions yet!
71 PortableInterceptor::ORBInitializer_var orb_initializer
=
74 PortableInterceptor::register_orb_initializer (orb_initializer
.in ());
77 CORBA::ORB_init (argc
, argv
, "Server ORB");
79 if (::parse_args (argc
, argv
) != 0)
82 CORBA::Object_var poa_object
=
83 orb
->resolve_initial_references ("RootPOA");
85 if (CORBA::is_nil (poa_object
.in ()))
86 ACE_ERROR_RETURN ((LM_ERROR
,
87 " (%P|%t) Unable to initialize the POA.\n"),
90 PortableServer::POA_var root_poa
=
91 PortableServer::POA::_narrow (poa_object
.in ());
93 PortableServer::POAManager_var poa_manager
=
94 root_poa
->the_POAManager ();
96 test_i
servant1 (1, direct_collocation
, orb
.in ());
97 test_i
servant2 (2, direct_collocation
, orb
.in ());
99 PortableServer::ObjectId_var oid1
=
100 root_poa
->activate_object (&servant1
);
102 PortableServer::ObjectId_var oid2
=
103 root_poa
->activate_object (&servant2
);
105 CORBA::Object_var obj1
=
106 root_poa
->servant_to_reference (&servant1
);
108 CORBA::Object_var obj2
=
109 root_poa
->servant_to_reference (&servant2
);
111 poa_manager
->activate ();
113 // Set the forward references in the server request interceptor.
114 PortableInterceptor::ServerRequestInterceptor_var
115 server_interceptor
= temp_initializer
->server_interceptor ();
117 Collocated_ForwardRequestTest::ServerRequestInterceptor_var interceptor
=
118 Collocated_ForwardRequestTest::ServerRequestInterceptor::_narrow (
119 server_interceptor
.in ());
121 if (CORBA::is_nil (interceptor
.in ()))
122 ACE_ERROR_RETURN ((LM_ERROR
,
123 "(%P|%t) Could not obtain reference to "
124 "server request interceptor.\n"),
127 if (direct_collocation
)
129 servant1
.forward (obj2
.in (), passes_before_forward
);
133 interceptor
->forward (obj2
.in ());
138 Collocated_ForwardRequestTest::test_var server
=
139 Collocated_ForwardRequestTest::test::_narrow (obj1
.in ());
140 test_colocal (server
.in ());
143 root_poa
->destroy (1, 1);
147 ACE_DEBUG ((LM_DEBUG
, "Event loop finished.\n"));
149 catch (const CORBA::Exception
& ex
)
151 ex
._tao_print_exception ("Caught exception:");
161 ACE_TMAIN(int, ACE_TCHAR
*[])
166 #endif /* TAO_HAS_INTERCEPTORS */