1 #include "RT_POA_Command.h"
5 #include "../lib/LookupManager.h"
6 #include "../lib/Name.h"
8 TAO_Notify_Tests_RT_POA_Command::TAO_Notify_Tests_RT_POA_Command ()
9 :priority_model_ (RTCORBA::CLIENT_PROPAGATED
)
10 , server_priority_ (0)
11 , thread_pool_static_threads_ (0)
12 , thread_pool_default_priority_ (0)
16 TAO_Notify_Tests_RT_POA_Command::~TAO_Notify_Tests_RT_POA_Command ()
21 TAO_Notify_Tests_RT_POA_Command::get_name ()
23 return TAO_Notify_Tests_RT_POA_Command::name ();
27 TAO_Notify_Tests_RT_POA_Command::name ()
29 return TAO_Notify_Tests_Name::poa_command
;
33 TAO_Notify_Tests_RT_POA_Command::init (ACE_Arg_Shifter
& arg_shifter
)
35 const ACE_TCHAR
*current_arg
= 0;
37 if (arg_shifter
.is_anything_left ())
39 if (arg_shifter
.cur_arg_strncasecmp (ACE_TEXT("-Create")) == 0)
41 this->command_
= CREATE
;
43 arg_shifter
.consume_arg ();
45 this->POA_name_
= ACE_TEXT_ALWAYS_CHAR(arg_shifter
.get_current ());
47 arg_shifter
.consume_arg ();
49 while (arg_shifter
.is_anything_left ())
51 if (0 != (current_arg
= arg_shifter
.get_the_parameter (ACE_TEXT("-PriorityModel"))))
53 if (arg_shifter
.cur_arg_strncasecmp (ACE_TEXT("CLIENT")) == 0)
54 priority_model_
= RTCORBA::CLIENT_PROPAGATED
;
56 priority_model_
= RTCORBA::SERVER_DECLARED
;
57 arg_shifter
.consume_arg ();
59 server_priority_
= ACE_OS::atoi (current_arg
);
60 arg_shifter
.consume_arg ();
64 // -Lanes lane-count -Lane prio statc_thr dyn_thr
65 if (0 != (current_arg
= arg_shifter
.get_the_parameter (ACE_TEXT("-Lanes"))))
67 int lanecount
= ACE_OS::atoi (current_arg
);
68 lanes_
.length (lanecount
);
69 arg_shifter
.consume_arg ();
72 //parse lane values ...
73 while (arg_shifter
.is_anything_left ())
75 if (arg_shifter
.cur_arg_strncasecmp (ACE_TEXT("-Lane")) == 0)
77 arg_shifter
.consume_arg ();
80 lanes_
[l_index
].lane_priority
= ACE_OS::atoi (arg_shifter
.get_current ());
81 arg_shifter
.consume_arg ();
83 // static thread count
84 lanes_
[l_index
].static_threads
= ACE_OS::atoi (arg_shifter
.get_current ());
85 arg_shifter
.consume_arg ();
87 // dynamic thread count
88 lanes_
[l_index
].dynamic_threads
= ACE_OS::atoi (arg_shifter
.get_current ());
89 arg_shifter
.consume_arg ();
91 if (TAO_debug_level
> 0)
92 ACE_DEBUG ((LM_DEBUG
, "POA Create: lane parsed - %d, %d, %d\n",
93 lanes_
[l_index
].lane_priority
, lanes_
[l_index
].static_threads
, lanes_
[l_index
].dynamic_threads
));
98 } /* while -- lane values */
103 if (0 != (current_arg
= arg_shifter
.get_the_parameter (ACE_TEXT("-Bands"))))
105 int bandcount
= ACE_OS::atoi (current_arg
);
106 bands_
.length (bandcount
);
107 arg_shifter
.consume_arg ();
110 //parse band values ...
111 while (arg_shifter
.is_anything_left ())
113 if (arg_shifter
.cur_arg_strncasecmp (ACE_TEXT("-Band")) == 0)
115 arg_shifter
.consume_arg ();
118 bands_
[b_index
].low
= ACE_OS::atoi (arg_shifter
.get_current ());
119 arg_shifter
.consume_arg ();
122 bands_
[b_index
].high
= ACE_OS::atoi (arg_shifter
.get_current ());
123 arg_shifter
.consume_arg ();
125 if (TAO_debug_level
> 0)
126 ACE_DEBUG ((LM_DEBUG
, "POA Create: band parsed - %d, %d\n",
127 bands_
[b_index
].low
, bands_
[b_index
].high
));
132 } /* while -- Band values */
137 // -ThreadPool thread_pool_count thread_pool_default_priority
138 if (arg_shifter
.cur_arg_strncasecmp (ACE_TEXT("-ThreadPool")) == 0)
140 arg_shifter
.consume_arg ();
142 current_arg
= arg_shifter
.get_current ();
143 this->thread_pool_static_threads_
= ACE_OS::atoi (current_arg
);
145 arg_shifter
.consume_arg ();
147 current_arg
= arg_shifter
.get_current ();
148 this->thread_pool_default_priority_
= ACE_OS::atoi (current_arg
);
150 arg_shifter
.consume_arg ();
152 if (TAO_debug_level
> 0)
153 ACE_DEBUG ((LM_DEBUG
, "ThreadPool parsed - static threads = %d, prio = %d\n",
154 this->thread_pool_static_threads_
, this->thread_pool_default_priority_
));
159 // none of the matched so break out...
163 else if (arg_shifter
.cur_arg_strncasecmp (ACE_TEXT("-Destroy")) == 0)
165 this->command_
= DESTROY
;
167 arg_shifter
.consume_arg ();
169 this->POA_name_
= ACE_TEXT_ALWAYS_CHAR(arg_shifter
.get_current ());
171 arg_shifter
.consume_arg ();
177 TAO_Notify_Tests_RT_POA_Command::execute_i ()
179 if (this->command_
== CREATE
)
184 LOOKUP_MANAGER
->resolve (orb
);
187 CORBA::Object_var object
=
188 orb
->resolve_initial_references ("RTORB");
190 RTCORBA::RTORB_var rt_orb
=
191 RTCORBA::RTORB::_narrow (object
.in ());
193 // Resolve parent poa.
194 PortableServer::POA_var parent_poa
;
196 LOOKUP_MANAGER
->resolve (parent_poa
);
199 this->create (rt_orb
.in (), parent_poa
.in ());
201 ACE_DEBUG ((LM_DEBUG
, "Created RT POA %s\n", this->POA_name_
.c_str ()));
203 else if (this->command_
== DESTROY
)
205 PortableServer::POA_var poa
;
207 LOOKUP_MANAGER
->resolve (poa
, this->POA_name_
.c_str ());
211 ACE_DEBUG ((LM_DEBUG
, "Destroyed RT POA %s\n", this->POA_name_
.c_str ()));
216 TAO_Notify_Tests_RT_POA_Command::create (RTCORBA::RTORB_ptr rt_orb
, PortableServer::POA_ptr parent_poa
)
219 lanes bands priomodel
221 if lanes create lanespolicy
222 if bands create bands policy
224 if lanes and bands , policy_list_length = 3
226 if lanes policy_list_length = 2
228 if threadpool and bands , policy_list_length = 3
230 if threadpool policy_list_length = 2
232 if bands policy_list_length = 2
234 policy_list_length = 1
238 CORBA::Policy_var priority_model_policy
;
239 CORBA::Policy_var lanes_policy
;
240 CORBA::Policy_var thread_pool_policy
;
241 CORBA::Policy_var bands_policy
;
243 // Create a priority model policy.
244 priority_model_policy
=
245 rt_orb
->create_priority_model_policy (priority_model_
,
248 if (lanes_
.length () != 0)
250 // Create a thread-pool.
251 CORBA::ULong stacksize
= 0;
252 CORBA::Boolean allow_request_buffering
= 0;
253 CORBA::ULong max_buffered_requests
= 0;
254 CORBA::ULong max_request_buffer_size
= 0;
255 CORBA::Boolean allow_borrowing
= 0;
256 // CORBA::ULong static_threads = 1;
257 // CORBA::ULong dynamic_threads = 0;
259 // Create the thread-pool.
260 RTCORBA::ThreadpoolId threadpool_id
=
261 rt_orb
->create_threadpool_with_lanes (stacksize
,
264 allow_request_buffering
,
265 max_buffered_requests
,
266 max_request_buffer_size
);
269 // Create a thread-pool policy.
271 rt_orb
->create_threadpool_policy (threadpool_id
);
273 else if (thread_pool_static_threads_
> 0)
275 CORBA::ULong stacksize
= 0;
276 CORBA::ULong static_threads
= this->thread_pool_static_threads_
;
277 CORBA::ULong dynamic_threads
= 0;
278 RTCORBA::Priority default_priority
= this->thread_pool_default_priority_
;
279 CORBA::Boolean allow_request_buffering
= 0;
280 CORBA::ULong max_buffered_requests
= 0;
281 CORBA::ULong max_request_buffer_size
= 0;
283 // Create the thread-pool.
284 RTCORBA::ThreadpoolId threadpool_id
=
285 rt_orb
->create_threadpool (stacksize
,
289 allow_request_buffering
,
290 max_buffered_requests
,
291 max_request_buffer_size
);
294 rt_orb
->create_threadpool_policy (threadpool_id
);
297 if (bands_
.length () != 0)
299 // Create a bands policy.
301 rt_orb
->create_priority_banded_connection_policy (this->bands_
);
304 CORBA::PolicyList poa_policy_list
;
306 CORBA::Policy_var activation_policy
=
307 parent_poa
->create_implicit_activation_policy (PortableServer::IMPLICIT_ACTIVATION
);
309 if (lanes_
.length () == 0 && thread_pool_static_threads_
== 0 && bands_
.length () == 0)
311 poa_policy_list
.length (1);
312 poa_policy_list
[0] = priority_model_policy
;
314 else if (lanes_
.length () == 0 && thread_pool_static_threads_
== 0 && bands_
.length () > 0)
316 poa_policy_list
.length (2);
317 poa_policy_list
[0] = priority_model_policy
;
318 poa_policy_list
[1] = bands_policy
;
320 else if (lanes_
.length () == 0 && thread_pool_static_threads_
> 0 && bands_
.length () == 0)
322 poa_policy_list
.length (2);
323 poa_policy_list
[0] = priority_model_policy
;
324 poa_policy_list
[1] = thread_pool_policy
;
326 else if (lanes_
.length () == 0 && thread_pool_static_threads_
> 0 && bands_
.length () > 0)
328 poa_policy_list
.length (3);
329 poa_policy_list
[0] = priority_model_policy
;
330 poa_policy_list
[1] = bands_policy
;
331 poa_policy_list
[2] = thread_pool_policy
;
333 else if (lanes_
.length () > 0 && thread_pool_static_threads_
== 0 && bands_
.length () == 0)
335 poa_policy_list
.length (2);
336 poa_policy_list
[0] = priority_model_policy
;
337 poa_policy_list
[1] = lanes_policy
;
339 else if (lanes_
.length () > 0 && thread_pool_static_threads_
== 0 && bands_
.length () > 0)
341 poa_policy_list
.length (3);
342 poa_policy_list
[0] = priority_model_policy
;
343 poa_policy_list
[1] = bands_policy
;
344 poa_policy_list
[2] = lanes_policy
;
347 // Add the activation policy
348 int act_index
= poa_policy_list
.length ();
349 poa_policy_list
.length (act_index
+ 1);
351 poa_policy_list
[act_index
] = activation_policy
;
353 if (TAO_debug_level
> 0)
354 ACE_DEBUG ((LM_DEBUG
, "creating POA %C\n", POA_name_
.c_str ()));
356 // Get the POA Manager.
357 PortableServer::POAManager_var poa_manager
=
358 parent_poa
->the_POAManager ();
360 parent_poa
->create_POA (POA_name_
.c_str (),