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
61 virtual int svc (void);
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 ();
124 ACE_DEBUG ((LM_DEBUG
, "Event loop finished\n"));
126 catch (const CORBA::Exception
& ex
)
128 ex
._tao_print_exception ("Exception caught:");
135 // ****************************************************************
144 static int threadID
= 0;
152 initORB(int threadID
)
157 ACE_OS::sprintf (ORBid
, "ORB_%d", threadID
);
159 ACE_DEBUG ((LM_DEBUG
, "Initializing ORB \"%C\"\n", ORBid
));
161 if ( g_registerORBinitializer
)
163 ACE_DEBUG ((LM_DEBUG
, "Creating ORB initializer\n"));
164 PortableInterceptor::ORBInitializer_var
rCOI(
165 new MyORBinitializer( ORBid
) );
166 PortableInterceptor::register_orb_initializer( rCOI
.in() );
169 ACE_DEBUG ((LM_DEBUG
, "Creating TAO_ORB_Manager\n"));
170 TAO_ORB_Manager
* pORBmgr
= new TAO_ORB_Manager
;
172 if ( -1 == pORBmgr
->init( g_argc
, g_argv
, ORBid
) )
174 ACE_DEBUG ((LM_DEBUG
, "Failed to initialize ORB \"%C\"\n", ORBid
));
175 throw CORBA::INTERNAL();
178 ACE_DEBUG ((LM_DEBUG
, "ORB \"%C\" initialized\n", ORBid
));
182 ACE_DEBUG ((LM_DEBUG
,
183 "Setting connection timeout policy for ORB \"%C\"\n",
186 CORBA::PolicyList policyList
;
188 CORBA::ORB_var orb
= pORBmgr
->orb();
190 TimeBase::TimeT connectionTimeout
= 100*10000;
192 any
<<= connectionTimeout
;
194 CORBA::ULong
l( policyList
.length() );
195 policyList
.length( l
+1 );
197 policyList
[l
] = orb
->create_policy(
198 TAO::CONNECTION_TIMEOUT_POLICY_TYPE
,
201 ACE_DEBUG ((LM_DEBUG
, "Connection timeout policy set for ORB \"%C\"\n",
209 catch (const CORBA::Exception
& ex
)
211 ACE_ERROR ((LM_ERROR
, "Caught exception: %C\n", ex
._info().c_str()));