1 #include "ace/Get_Opt.h"
4 #include "tao/Utils/ORB_Manager.h"
5 #include "tao/AnyTypeCode/Any.h"
6 #include "tao/Messaging/Messaging.h"
7 #include "tao/ORBInitializer_Registry.h"
9 #include "tao/LocalObject.h"
12 bool g_setTimeout
= true;
13 bool g_registerORBinitializer
= true;
14 bool g_initInMain
= false;
18 int initORB(int threadID
);
21 parse_args (int argc
, ACE_TCHAR
*argv
[])
23 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("min:"));
26 while ((c
= get_opts ()) != -1)
34 g_registerORBinitializer
= false;
38 g_nthreads
= ACE_OS::atoi (get_opts
.opt_arg ());
43 ACE_ERROR_RETURN ((LM_ERROR
,
45 "-m (Initialize an ORB from the main thread first) "
46 "-i (Do not register ORB initializer) "
47 "-n <numberOfThreads>"
52 // Indicates successful parsing of the command line
56 class Worker
: public ACE_Task_Base
66 class MyORBinitializer
67 : public virtual PortableInterceptor::ORBInitializer
68 , public virtual CORBA::LocalObject
71 MyORBinitializer( ACE_CString orbID
)
76 pre_init( PortableInterceptor::ORBInitInfo_ptr
)
79 "MyORBinitializer::pre_init() called for ORB \"%C\"\n",
85 post_init( PortableInterceptor::ORBInitInfo_ptr
)
88 "MyORBinitializer::post_init() called for ORB \"%C\"\n",
97 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
104 if (parse_args (argc
, argv
) != 0)
111 // Run in both main and background thread
115 if (worker
.activate (THR_NEW_LWP
| THR_JOINABLE
,
117 ACE_ERROR_RETURN ((LM_ERROR
,
118 "Cannot activate ORB thread(s)\n"),
121 worker
.thr_mgr ()->wait ();
123 ACE_DEBUG ((LM_DEBUG
, "Event loop finished\n"));
125 catch (const CORBA::Exception
& ex
)
127 ex
._tao_print_exception ("Exception caught:");
134 // ****************************************************************
143 static int threadID
= 0;
151 initORB(int threadID
)
156 ACE_OS::sprintf (ORBid
, "ORB_%d", threadID
);
158 ACE_DEBUG ((LM_DEBUG
, "Initializing ORB \"%C\"\n", ORBid
));
160 if (g_registerORBinitializer
)
162 ACE_DEBUG ((LM_DEBUG
, "Creating ORB initializer\n"));
163 PortableInterceptor::ORBInitializer_var
rCOI(
164 new MyORBinitializer(ORBid
));
165 PortableInterceptor::register_orb_initializer( rCOI
.in());
168 ACE_DEBUG ((LM_DEBUG
, "Creating TAO_ORB_Manager\n"));
169 TAO_ORB_Manager
* pORBmgr
= new TAO_ORB_Manager
;
171 if (-1 == pORBmgr
->init(g_argc
, g_argv
, ORBid
))
173 ACE_DEBUG ((LM_DEBUG
, "Failed to initialize ORB \"%C\"\n", ORBid
));
174 throw CORBA::INTERNAL();
177 ACE_DEBUG ((LM_DEBUG
, "ORB \"%C\" initialized\n", ORBid
));
181 ACE_DEBUG ((LM_DEBUG
,
182 "Setting connection timeout policy for ORB \"%C\"\n",
185 CORBA::PolicyList policyList
;
187 CORBA::ORB_var orb
= pORBmgr
->orb();
189 TimeBase::TimeT connectionTimeout
= 100*10000;
191 any
<<= connectionTimeout
;
193 CORBA::ULong
l( policyList
.length());
194 policyList
.length(l
+1);
196 policyList
[l
] = orb
->create_policy(TAO::CONNECTION_TIMEOUT_POLICY_TYPE
, any
);
198 ACE_DEBUG ((LM_DEBUG
, "Connection timeout policy set for ORB \"%C\"\n",
206 catch (const CORBA::Exception
& ex
)
208 ACE_ERROR ((LM_ERROR
, "Caught exception: %C\n", ex
._info().c_str()));