1 #include "started_pch.h"
3 #include "Messenger_i.h"
4 #include "tao/Dynamic_TP/DTP_POA_Strategy.h"
7 #include "ace/Get_Opt.h"
9 const ACE_TCHAR
*ior_output_file
= ACE_TEXT ("Messenger.ior");
12 parse_args (int argc
, ACE_TCHAR
*argv
[])
14 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
17 while ((c
= get_opts ()) != -1)
21 ior_output_file
= get_opts
.opt_arg ();
26 ACE_ERROR_RETURN ((LM_ERROR
,
33 // Indicates successful parsing of the command line
37 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
40 // Initialize the ORB.
41 CORBA::ORB_var orb
= CORBA::ORB_init( argc
, argv
);
43 if (parse_args (argc
, argv
) != 0)
46 //Get reference to the RootPOA.
47 CORBA::Object_var obj
= orb
->resolve_initial_references( "RootPOA" );
48 PortableServer::POA_var poa
= PortableServer::POA::_narrow( obj
.in() );
50 // Create a configuration structure and set the values
51 TAO_DTP_Definition tp_config
;
53 tp_config
.min_threads_
= 1; // Set low water mark to 1 thread.
54 tp_config
.init_threads_
= 3; // Start 3 threads to start.
55 tp_config
.max_threads_
= -1; // Create threads as needed (no limit).
56 tp_config
.queue_depth_
= -1; // Allow infinite queue depth.
57 tp_config
.stack_size_
= (64 * 1024); // Each thread with 64K stacksize.
58 tp_config
.timeout_
= ACE_Time_Value(30,0); // Expire thread that is idle for 30 sec.
60 // Create the dynamic thread pool servant dispatching strategy object, and
61 // hold it in a (local) smart pointer variable.
62 TAO_Intrusive_Ref_Count_Handle
<TAO_DTP_POA_Strategy
> dtp_strategy
=
63 new TAO_DTP_POA_Strategy(&tp_config
, false);
65 // Tell the strategy to apply itself to the child poa.
66 if (dtp_strategy
->apply_to(poa
.in()) == false)
69 "Failed to apply CSD strategy to root poa.\n"));
74 // Activate the POAManager.
75 PortableServer::POAManager_var mgr
= poa
->the_POAManager();
79 PortableServer::Servant_var
<Messenger_i
> servant
= new Messenger_i();
81 // Register the servant with the RootPOA, obtain its object
82 // reference, stringify it, and write it to a file.
83 PortableServer::ObjectId_var oid
= poa
->activate_object( servant
.in() );
84 obj
= poa
->id_to_reference( oid
.in() );
85 CORBA::String_var str
= orb
->object_to_string( obj
.in() );
86 std::ofstream
iorFile( ACE_TEXT_ALWAYS_CHAR(ior_output_file
) );
87 iorFile
<< str
.in() << std::endl
;
89 std::cout
<< "IOR written to file " << ACE_TEXT_ALWAYS_CHAR(ior_output_file
) << std::endl
;
91 // Accept requests from clients.
97 catch(const CORBA::Exception
& ex
) {
98 std::cerr
<< "CORBA exception: " << ex
<< std::endl
;