=default for generated implementation copy ctor
[ACE_TAO.git] / TAO / tao / CSD_ThreadPool / CSD_TP_Strategy.cpp
blobc91f7ef99b302db5197b3ad31045a8e4e61b0fbd
1 #include "tao/CSD_ThreadPool/CSD_TP_Strategy.h"
2 #include "tao/CSD_ThreadPool/CSD_TP_Remote_Request.h"
3 #include "tao/CSD_ThreadPool/CSD_TP_Collocated_Synch_Request.h"
4 #include "tao/CSD_ThreadPool/CSD_TP_Collocated_Asynch_Request.h"
5 #include "tao/CSD_ThreadPool/CSD_TP_Custom_Synch_Request.h"
6 #include "tao/CSD_ThreadPool/CSD_TP_Custom_Asynch_Request.h"
7 #include "tao/CSD_ThreadPool/CSD_TP_Collocated_Synch_With_Server_Request.h"
8 #include "ace/Trace.h"
9 #include "tao/ORB_Core.h"
11 #if !defined (__ACE_INLINE__)
12 # include "tao/CSD_ThreadPool/CSD_TP_Strategy.inl"
13 #endif /* ! __ACE_INLINE__ */
15 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
17 TAO::CSD::TP_Strategy::~TP_Strategy()
22 TAO::CSD::TP_Strategy::CustomRequestOutcome
23 TAO::CSD::TP_Strategy::custom_synch_request(TP_Custom_Request_Operation* op)
25 TP_Servant_State::HandleType servant_state =
26 this->get_servant_state(op->servant());
28 TP_Custom_Synch_Request_Handle request = new
29 TP_Custom_Synch_Request(op, servant_state.in());
31 if (!this->task_.add_request(request.in()))
33 // The request was rejected by the task.
34 return REQUEST_REJECTED;
37 // Now we wait until the request is handled (executed or cancelled).
38 return (request->wait()) ? REQUEST_EXECUTED : REQUEST_CANCELLED;
42 TAO::CSD::TP_Strategy::CustomRequestOutcome
43 TAO::CSD::TP_Strategy::custom_asynch_request(TP_Custom_Request_Operation* op)
45 TP_Servant_State::HandleType servant_state =
46 this->get_servant_state(op->servant());
48 TP_Custom_Asynch_Request_Handle request = new
49 TP_Custom_Asynch_Request(op, servant_state.in());
51 return (this->task_.add_request(request.in()))
52 ? REQUEST_DISPATCHED : REQUEST_REJECTED;
56 bool
57 TAO::CSD::TP_Strategy::poa_activated_event_i(TAO_ORB_Core& orb_core)
59 this->task_.thr_mgr(orb_core.thr_mgr());
60 // Activates the worker threads, and waits until all have been started.
61 return (this->task_.open(&(this->num_threads_)) == 0);
65 void
66 TAO::CSD::TP_Strategy::poa_deactivated_event_i()
68 // Passing in a value of 1 means that we want to shutdown the task, which
69 // equates to causing all worker threads to shutdown. The worker threads
70 // themselves will also invoke the close() method, but the passed-in value
71 // will be 0. So, a 1 means "shutdown", and a 0 means "a single worker
72 // thread is going away".
73 this->task_.close(1);
77 TAO::CSD::Strategy_Base::DispatchResult
78 TAO::CSD::TP_Strategy::dispatch_remote_request_i
79 (TAO_ServerRequest& server_request,
80 const PortableServer::ObjectId& object_id,
81 PortableServer::POA_ptr poa,
82 const char* operation,
83 PortableServer::Servant servant)
85 TP_Servant_State::HandleType servant_state =
86 this->get_servant_state(servant);
88 // Handle the one ways that are SYNC_WITH_SERVER and not collocated.
89 // before queuing the request and thus avoid delaying the client.
90 // This is a problem if the servant ends up throwing a Location Forward
91 // exception. If necessary, add an override config option here.
92 CORBA::Boolean early_sync = true;
93 server_request.is_queued (early_sync);
94 server_request.sync_before_dispatch ();
96 // Now we can create the TP_Remote_Request object, and then add it to our
97 // task_'s "request queue".
99 // TBD-CSD: Need to use a Cached Allocator to "create" the
100 // TP_Remote_Request objects. For now, use the heap.
101 TP_Remote_Request_Handle request =
102 new TP_Remote_Request(server_request,
103 object_id,
104 poa,
105 operation,
106 servant,
107 servant_state.in());
109 // Hand the request object to our task so that it can add the request
110 // to its "request queue".
111 if (!this->task_.add_request(request.in()))
113 // Return the DISPATCH_REJECTED return code so that the caller (our
114 // base class' dispatch_request() method) knows that we did
115 // not handle the request, and that it should be rejected.
116 return TAO::CSD::Strategy_Base::DISPATCH_REJECTED;
119 return TAO::CSD::Strategy_Base::DISPATCH_HANDLED;
123 TAO::CSD::Strategy_Base::DispatchResult
124 TAO::CSD::TP_Strategy::dispatch_collocated_request_i
125 (TAO_ServerRequest& server_request,
126 const PortableServer::ObjectId& object_id,
127 PortableServer::POA_ptr poa,
128 const char* operation,
129 PortableServer::Servant servant)
131 TP_Servant_State::HandleType servant_state =
132 this->get_servant_state(servant);
134 bool is_sync_with_server = server_request.sync_with_server();
135 bool is_synchronous = server_request.response_expected();
137 TP_Collocated_Synch_Request_Handle synch_request;
138 TP_Collocated_Synch_With_Server_Request_Handle synch_with_server_request;
139 TP_Request_Handle request;
141 // Create the request object using the appropriate concrete type.
142 if (is_sync_with_server)
144 synch_with_server_request =
145 new TP_Collocated_Synch_With_Server_Request
146 (server_request,
147 object_id,
148 poa,
149 operation,
150 servant,
151 servant_state.in());
153 // Give the request handle its own "copy".
154 synch_with_server_request->_add_ref();
155 request = synch_with_server_request.in();
157 else if (is_synchronous)
159 synch_request = new TP_Collocated_Synch_Request(server_request,
160 object_id,
161 poa,
162 operation,
163 servant,
164 servant_state.in());
166 // Give the request handle its own "copy".
167 synch_request->_add_ref();
168 request = synch_request.in();
170 else
172 // Just use the (base) request handle to hold the request object.
173 request = new TP_Collocated_Asynch_Request(server_request,
174 object_id,
175 poa,
176 operation,
177 servant,
178 servant_state.in());
181 // Hand the request object to our task so that it can add the request
182 // to its "request queue".
183 if (!this->task_.add_request(request.in()))
185 // Return the DISPATCH_REJECTED return code so that the caller (our
186 // base class' dispatch_request() method) knows that we did
187 // not handle the request, and that it should be rejected.
188 return DISPATCH_REJECTED;
191 // We need to wait on the request object if the request type is a
192 // synchronous request.
193 if (!synch_request.is_nil())
195 int srw = synch_request->wait();
196 if (srw == false)
198 // Raise exception when request was cancelled.
199 throw ::CORBA::NO_IMPLEMENT();
202 else if (!synch_with_server_request.is_nil())
204 bool swsr = synch_with_server_request->wait();
205 if (swsr == false)
207 // Raise exception when request was cancelled.
208 throw ::CORBA::NO_IMPLEMENT();
212 return DISPATCH_HANDLED;
216 void
217 TAO::CSD::TP_Strategy::servant_activated_event_i
218 (PortableServer::Servant servant,
219 const PortableServer::ObjectId&)
221 if (this->serialize_servants_)
223 // Add the servant to the servant state map.
224 this->servant_state_map_.insert(servant);
229 void
230 TAO::CSD::TP_Strategy::servant_deactivated_event_i
231 (PortableServer::Servant servant,
232 const PortableServer::ObjectId&)
234 // Cancel all requests stuck in the queue for the specified servant.
235 this->task_.cancel_servant(servant);
237 if (this->serialize_servants_)
239 // Remove the servant from the servant state map.
240 this->servant_state_map_.remove(servant);
245 void
246 TAO::CSD::TP_Strategy::cancel_requests(PortableServer::Servant servant)
248 // Cancel all requests stuck in the queue for the specified servant.
249 this->task_.cancel_servant(servant);
253 TAO::CSD::TP_Servant_State::HandleType
254 TAO::CSD::TP_Strategy::get_servant_state(PortableServer::Servant servant)
256 TP_Servant_State::HandleType servant_state;
258 if (this->serialize_servants_)
260 servant_state = this->servant_state_map_.find(servant);
263 return servant_state;
265 TAO_END_VERSIONED_NAMESPACE_DECL