Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / examples / RTScheduling / POA_Holder.cpp
blob5049898618e0d7edea72fe57a167236dd54711e4
1 #include "POA_Holder.h"
3 #include "tao/debug.h"
5 #include "ace/Arg_Shifter.h"
6 #include "ace/Log_Msg.h"
8 POA_Holder::POA_Holder (void)
9 :priority_model_ (RTCORBA::CLIENT_PROPAGATED),
10 server_priority_ (0),
11 thread_pool_ (0)
15 int
16 POA_Holder::init (ACE_Arg_Shifter& arg_shifter)
18 ACE_DEBUG ((LM_DEBUG,
19 "Init POA\n"));
21 const ACE_TCHAR *current_arg = 0;
23 POA_name_ = ACE_TEXT_ALWAYS_CHAR(arg_shifter.get_current ()); // Read the name of the POA
24 arg_shifter.consume_arg ();
26 while (arg_shifter.is_anything_left ())
28 if (0 != (current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-PriorityModel"))))
30 if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("CLIENT")) == 0)
31 priority_model_ = RTCORBA::CLIENT_PROPAGATED;
32 else
33 priority_model_ = RTCORBA::SERVER_DECLARED;
34 arg_shifter.consume_arg ();
36 server_priority_ = ACE_OS::atoi (current_arg);
37 arg_shifter.consume_arg ();
39 else if (0 != (current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-Lanes"))))
41 int lanecount = ACE_OS::atoi (current_arg);
42 lanes_.length (lanecount);
43 arg_shifter.consume_arg ();
45 int l_index = 0;
46 //parse lane values ...
47 while (arg_shifter.is_anything_left ())
49 if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("-Lane")) == 0)
51 arg_shifter.consume_arg ();
53 // read priority
54 lanes_[l_index].lane_priority = ACE_OS::atoi (arg_shifter.get_current ());
55 arg_shifter.consume_arg ();
57 // static thread count
58 lanes_[l_index].static_threads = ACE_OS::atoi (arg_shifter.get_current ());
59 arg_shifter.consume_arg ();
61 // dynamic thread count
62 lanes_[l_index].dynamic_threads = ACE_OS::atoi (arg_shifter.get_current ());
63 arg_shifter.consume_arg ();
65 //if (TAO_debug_level > 0)
66 ACE_DEBUG ((LM_DEBUG, "lane parsed - %d, %d, %d\n",
67 lanes_[l_index].lane_priority, lanes_[l_index].static_threads, lanes_[l_index].dynamic_threads));
68 l_index++;
70 else
71 break;
72 } /* while -- lane values */
74 } /* if -Lanes */
75 else if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("-ThreadPool")) == 0)
77 ACE_DEBUG ((LM_DEBUG,
78 "Thread Pool\n"));
80 arg_shifter.consume_arg ();
81 thread_pool_ = 1;
82 // read priority
83 tp_static_threads_ = ACE_OS::atoi (arg_shifter.get_current ());
84 arg_shifter.consume_arg ();
86 tp_dynamic_threads_ = ACE_OS::atoi (arg_shifter.get_current ());
87 arg_shifter.consume_arg ();
89 tp_priority_ = ACE_OS::atoi (arg_shifter.get_current ());
90 arg_shifter.consume_arg ();
91 ACE_DEBUG ((LM_DEBUG,
92 "Thread Pool Initialized\n"));
95 else if (0 != (current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-Bands"))))
97 ACE_DEBUG ((LM_DEBUG,
98 "Initializing Bands\n"));
100 int bandcount = ACE_OS::atoi (current_arg);
101 bands_.length (bandcount);
102 arg_shifter.consume_arg ();
104 int b_index = 0;
105 //parse band values ...
106 while (arg_shifter.is_anything_left ())
108 if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("-Band")) == 0)
110 arg_shifter.consume_arg ();
112 // read low
113 bands_[b_index].low = ACE_OS::atoi (arg_shifter.get_current ());
114 arg_shifter.consume_arg ();
116 // read high
117 bands_[b_index].high = ACE_OS::atoi (arg_shifter.get_current ());
118 arg_shifter.consume_arg ();
120 //if (TAO_debug_level > 0)
121 ACE_DEBUG ((LM_DEBUG, "band parsed - %d, %d\n",
122 bands_[b_index].low, bands_[b_index].high));
123 b_index++;
125 else
126 break;
127 } /* while -- Band values */
128 ACE_DEBUG ((LM_DEBUG,
129 "Bands Initialized\n"));
131 } /* if -Bands */
132 else // something else is showing up ...
134 ACE_DEBUG ((LM_DEBUG,
135 "Finish Init POA\n"));
137 return 0;
140 ACE_DEBUG ((LM_DEBUG,
141 "Finish Init POA\n"));
142 return 0;
145 void
146 POA_Holder::activate (RTCORBA::RTORB_ptr rt_orb, PortableServer::POA_ptr parent_poa)
148 CORBA::Policy_var priority_model_policy;
149 CORBA::Policy_var lanes_policy;
150 CORBA::Policy_var bands_policy;
151 CORBA::Policy_var thread_pool_policy;
153 // Create a priority model policy.
154 priority_model_policy =
155 rt_orb->create_priority_model_policy (priority_model_,
156 server_priority_);
158 if (lanes_.length () != 0)
160 // Create a thread-pool.
161 CORBA::ULong stacksize = 0;
162 CORBA::Boolean allow_request_buffering = 0;
163 CORBA::ULong max_buffered_requests = 0;
164 CORBA::ULong max_request_buffer_size = 0;
165 CORBA::Boolean allow_borrowing = 0;
167 // Create the thread-pool.
168 RTCORBA::ThreadpoolId threadpool_id =
169 rt_orb->create_threadpool_with_lanes (stacksize,
170 lanes_,
171 allow_borrowing,
172 allow_request_buffering,
173 max_buffered_requests,
174 max_request_buffer_size);
176 // Create a thread-pool policy.
177 lanes_policy =
178 rt_orb->create_threadpool_policy (threadpool_id);
180 ACE_DEBUG ((LM_DEBUG,
181 "Activated Lanes\n"));
185 if (thread_pool_)
187 CORBA::ULong stacksize = 0;
188 CORBA::Boolean allow_request_buffering = 0;
189 CORBA::ULong max_buffered_requests = 0;
190 CORBA::ULong max_request_buffer_size = 0;
192 RTCORBA::ThreadpoolId threadpool_id_1 =
193 rt_orb->create_threadpool (stacksize,
194 tp_static_threads_,
195 tp_dynamic_threads_,
196 tp_priority_,
197 allow_request_buffering,
198 max_buffered_requests,
199 max_request_buffer_size);
202 thread_pool_policy = rt_orb->create_threadpool_policy (threadpool_id_1);
204 ACE_DEBUG ((LM_DEBUG,
205 "Activated thread pool\n"));
210 if (bands_.length () != 0)
212 // Create a bands policy.
213 bands_policy =
214 rt_orb->create_priority_banded_connection_policy (this->bands_);
215 ACE_DEBUG ((LM_DEBUG,
216 "Activated Bands\n"));
220 CORBA::PolicyList poa_policy_list;
222 if (lanes_.length () == 0 && bands_.length () == 0)
224 if (thread_pool_)
226 poa_policy_list.length (2);
227 poa_policy_list[0] = priority_model_policy;
228 poa_policy_list[1] = thread_pool_policy;
230 else
232 poa_policy_list.length (1);
233 poa_policy_list[0] = priority_model_policy;
236 else if (lanes_.length () != 0 && bands_.length () == 0)
238 if (thread_pool_)
240 poa_policy_list.length (3);
241 poa_policy_list[0] = priority_model_policy;
242 poa_policy_list[1] = lanes_policy;
243 poa_policy_list[2] = thread_pool_policy;
245 else
247 poa_policy_list.length (2);
248 poa_policy_list[0] = priority_model_policy;
249 poa_policy_list[1] = lanes_policy;
252 else if (lanes_.length () == 0 && bands_.length () != 0)
254 if (thread_pool_)
256 poa_policy_list.length (3);
257 poa_policy_list[0] = priority_model_policy;
258 poa_policy_list[1] = bands_policy;
259 poa_policy_list[2] = thread_pool_policy;
261 else
263 poa_policy_list.length (2);
264 poa_policy_list[0] = priority_model_policy;
265 poa_policy_list[1] = bands_policy;
268 else
270 if (thread_pool_)
272 poa_policy_list.length (4);
273 poa_policy_list[0] = priority_model_policy;
274 poa_policy_list[1] = lanes_policy;
275 poa_policy_list[2] = bands_policy;
276 poa_policy_list[3] = thread_pool_policy;
278 else
280 poa_policy_list.length (3);
281 poa_policy_list[0] = priority_model_policy;
282 poa_policy_list[1] = lanes_policy;
283 poa_policy_list[2] = bands_policy;
287 ACE_DEBUG ((LM_DEBUG,
288 "Initialized POA Policy\n"));
290 if (TAO_debug_level > 0)
291 ACE_DEBUG ((LM_DEBUG, "creating POA %C\n", POA_name_.c_str ()));
293 // Get the POA Manager.
294 PortableServer::POAManager_var poa_manager =
295 parent_poa->the_POAManager ();
297 PortableServer::POA_var poa =
298 parent_poa->create_POA (POA_name_.c_str (),
299 poa_manager.in (),
300 poa_policy_list);