Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / examples / RTCORBA / Activity / POA_Holder.cpp
blobb880c30d6f732f3520f5459eaf88d4ba2fdb2ef2
1 #include "POA_Holder.h"
2 #include "tao/debug.h"
3 #include "ace/Log_Msg.h"
5 POA_Holder::POA_Holder (void)
6 : priority_model_ (RTCORBA::CLIENT_PROPAGATED),
7 server_priority_ (0)
11 int
12 POA_Holder::init (ACE_Arg_Shifter& arg_shifter)
14 const ACE_TCHAR *current_arg = 0;
16 POA_name_ = ACE_TEXT_ALWAYS_CHAR(arg_shifter.get_current ()); // Read the name of the POA
17 arg_shifter.consume_arg ();
19 while (arg_shifter.is_anything_left ())
21 if (0 != (current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-PriorityModel"))))
23 if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("CLIENT")) == 0)
24 priority_model_ = RTCORBA::CLIENT_PROPAGATED;
25 else
26 priority_model_ = RTCORBA::SERVER_DECLARED;
27 arg_shifter.consume_arg ();
29 server_priority_ = ACE_OS::atoi (current_arg);
30 arg_shifter.consume_arg ();
32 else if (0 != (current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-Lanes"))))
34 int lanecount = ACE_OS::atoi (current_arg);
35 lanes_.length (lanecount);
36 arg_shifter.consume_arg ();
38 int l_index = 0;
39 //parse lane values ...
40 while (arg_shifter.is_anything_left ())
42 if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("-Lane")) == 0)
44 arg_shifter.consume_arg ();
46 // read priority
47 lanes_[l_index].lane_priority = ACE_OS::atoi (arg_shifter.get_current ());
48 arg_shifter.consume_arg ();
50 // static thread count
51 lanes_[l_index].static_threads = ACE_OS::atoi (arg_shifter.get_current ());
52 arg_shifter.consume_arg ();
54 // dynamic thread count
55 lanes_[l_index].dynamic_threads = ACE_OS::atoi (arg_shifter.get_current ());
56 arg_shifter.consume_arg ();
58 //if (TAO_debug_level > 0)
59 ACE_DEBUG ((LM_DEBUG, "lane parsed - %d, %d, %d\n",
60 lanes_[l_index].lane_priority,
61 lanes_[l_index].static_threads,
62 lanes_[l_index].dynamic_threads));
63 l_index++;
65 else
66 break;
67 } /* while -- lane values */
68 } /* if -Lanes */
69 else if (0 != (current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-Bands"))))
71 int bandcount = ACE_OS::atoi (current_arg);
72 bands_.length (bandcount);
73 arg_shifter.consume_arg ();
75 int b_index = 0;
76 //parse band values ...
77 while (arg_shifter.is_anything_left ())
79 if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("-Band")) == 0)
81 arg_shifter.consume_arg ();
83 // read low
84 bands_[b_index].low = ACE_OS::atoi (arg_shifter.get_current ());
85 arg_shifter.consume_arg ();
87 // read high
88 bands_[b_index].high = ACE_OS::atoi (arg_shifter.get_current ());
89 arg_shifter.consume_arg ();
91 //if (TAO_debug_level > 0)
92 ACE_DEBUG ((LM_DEBUG, "band parsed - %d, %d\n",
93 bands_[b_index].low, bands_[b_index].high));
94 b_index++;
96 else
97 break;
98 } /* while -- Band values */
100 } /* if -Bands */
101 else // something else is showing up ...
103 return 0;
106 return 0;
109 void
110 POA_Holder::activate (RTCORBA::RTORB_ptr rt_orb, PortableServer::POA_ptr parent_poa)
114 lanes bands priomodel
116 if lanes create lanespolicy
117 if bands create bands policy
119 if lanes and bands , policy_list_length = 3
120 else
121 if lanes policy_list_length = 2
122 else
123 if bands policy_list_length = 2
124 else
125 policy_list_length = 1
129 CORBA::Policy_var priority_model_policy;
130 CORBA::Policy_var lanes_policy;
131 CORBA::Policy_var bands_policy;
133 // Create a priority model policy.
134 priority_model_policy =
135 rt_orb->create_priority_model_policy (priority_model_,
136 server_priority_);
138 if (lanes_.length () != 0)
140 // Create a thread-pool.
141 CORBA::ULong stacksize = 0;
142 CORBA::Boolean allow_request_buffering = 0;
143 CORBA::ULong max_buffered_requests = 0;
144 CORBA::ULong max_request_buffer_size = 0;
145 CORBA::Boolean allow_borrowing = 0;
146 // CORBA::ULong static_threads = 1;
147 // CORBA::ULong dynamic_threads = 0;
149 // Create the thread-pool.
150 RTCORBA::ThreadpoolId threadpool_id =
151 rt_orb->create_threadpool_with_lanes (stacksize,
152 lanes_,
153 allow_borrowing,
154 allow_request_buffering,
155 max_buffered_requests,
156 max_request_buffer_size);
159 // Create a thread-pool policy.
160 lanes_policy =
161 rt_orb->create_threadpool_policy (threadpool_id);
165 if (bands_.length () != 0)
167 // Create a bands policy.
168 bands_policy =
169 rt_orb->create_priority_banded_connection_policy (this->bands_);
172 CORBA::PolicyList poa_policy_list;
174 if (lanes_.length () == 0 && bands_.length () == 0)
176 poa_policy_list.length (1);
177 poa_policy_list[0] = priority_model_policy;
179 else if (lanes_.length () != 0 && bands_.length () == 0)
181 poa_policy_list.length (2);
182 poa_policy_list[0] = priority_model_policy;
183 poa_policy_list[1] = lanes_policy;
185 else if (lanes_.length () == 0 && bands_.length () != 0)
187 poa_policy_list.length (2);
188 poa_policy_list[0] = priority_model_policy;
189 poa_policy_list[1] = bands_policy;
191 else
193 poa_policy_list.length (3);
194 poa_policy_list[0] = priority_model_policy;
195 poa_policy_list[1] = lanes_policy;
196 poa_policy_list[2] = bands_policy;
199 if (TAO_debug_level > 0)
200 ACE_DEBUG ((LM_DEBUG, "creating POA %C\n", POA_name_.c_str ()));
202 // Get the POA Manager.
203 PortableServer::POAManager_var poa_manager =
204 parent_poa->the_POAManager ();
206 this->poa_ = parent_poa->create_POA (POA_name_.c_str (),
207 poa_manager.in (),
208 poa_policy_list);