Go to the documentation of this file.00001
00002
00003 #include "tao/CSD_ThreadPool/CSD_TP_Strategy.h"
00004 #include "tao/CSD_ThreadPool/CSD_TP_Remote_Request.h"
00005 #include "tao/CSD_ThreadPool/CSD_TP_Collocated_Synch_Request.h"
00006 #include "tao/CSD_ThreadPool/CSD_TP_Collocated_Asynch_Request.h"
00007 #include "tao/CSD_ThreadPool/CSD_TP_Custom_Synch_Request.h"
00008 #include "tao/CSD_ThreadPool/CSD_TP_Custom_Asynch_Request.h"
00009 #include "tao/CSD_ThreadPool/CSD_TP_Collocated_Synch_With_Server_Request.h"
00010 #include "ace/Trace.h"
00011 #include "tao/ORB_Core.h"
00012
00013 ACE_RCSID (CSD_ThreadPool,
00014 TP_Strategy,
00015 "$Id: CSD_TP_Strategy.cpp 81882 2008-06-10 14:59:20Z johnc $")
00016
00017 #if !defined (__ACE_INLINE__)
00018 # include "tao/CSD_ThreadPool/CSD_TP_Strategy.inl"
00019 #endif
00020
00021 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00022
00023 TAO::CSD::TP_Strategy::~TP_Strategy()
00024 {
00025 }
00026
00027
00028
00029 TAO::CSD::TP_Strategy::CustomRequestOutcome
00030 TAO::CSD::TP_Strategy::custom_synch_request(TP_Custom_Request_Operation* op)
00031 {
00032 TP_Servant_State::HandleType servant_state =
00033 this->get_servant_state(op->servant());
00034
00035 TP_Custom_Synch_Request_Handle request = new
00036 TP_Custom_Synch_Request(op, servant_state.in());
00037
00038 if (!this->task_.add_request(request.in()))
00039 {
00040
00041 return REQUEST_REJECTED;
00042 }
00043
00044
00045 return (request->wait()) ? REQUEST_EXECUTED : REQUEST_CANCELLED;
00046 }
00047
00048
00049 TAO::CSD::TP_Strategy::CustomRequestOutcome
00050 TAO::CSD::TP_Strategy::custom_asynch_request(TP_Custom_Request_Operation* op)
00051 {
00052 TP_Servant_State::HandleType servant_state =
00053 this->get_servant_state(op->servant());
00054
00055 TP_Custom_Asynch_Request_Handle request = new
00056 TP_Custom_Asynch_Request(op, servant_state.in());
00057
00058 return (this->task_.add_request(request.in()))
00059 ? REQUEST_DISPATCHED : REQUEST_REJECTED;
00060 }
00061
00062
00063 bool
00064 TAO::CSD::TP_Strategy::poa_activated_event_i(TAO_ORB_Core& orb_core)
00065 {
00066 this->task_.thr_mgr(orb_core.thr_mgr());
00067
00068 return (this->task_.open(&(this->num_threads_)) == 0);
00069 }
00070
00071
00072 void
00073 TAO::CSD::TP_Strategy::poa_deactivated_event_i()
00074 {
00075
00076
00077
00078
00079
00080 this->task_.close(1);
00081 }
00082
00083
00084 TAO::CSD::Strategy_Base::DispatchResult
00085 TAO::CSD::TP_Strategy::dispatch_remote_request_i
00086 (TAO_ServerRequest& server_request,
00087 const PortableServer::ObjectId& object_id,
00088 PortableServer::POA_ptr poa,
00089 const char* operation,
00090 PortableServer::Servant servant)
00091 {
00092 TP_Servant_State::HandleType servant_state =
00093 this->get_servant_state(servant);
00094
00095
00096
00097
00098
00099
00100 TP_Remote_Request_Handle request =
00101 new TP_Remote_Request(server_request,
00102 object_id,
00103 poa,
00104 operation,
00105 servant,
00106 servant_state.in());
00107
00108
00109
00110 if (!this->task_.add_request(request.in()))
00111 {
00112
00113
00114
00115 return TAO::CSD::Strategy_Base::DISPATCH_REJECTED;
00116 }
00117
00118 return TAO::CSD::Strategy_Base::DISPATCH_HANDLED;
00119 }
00120
00121
00122 TAO::CSD::Strategy_Base::DispatchResult
00123 TAO::CSD::TP_Strategy::dispatch_collocated_request_i
00124 (TAO_ServerRequest& server_request,
00125 const PortableServer::ObjectId& object_id,
00126 PortableServer::POA_ptr poa,
00127 const char* operation,
00128 PortableServer::Servant servant)
00129 {
00130 TP_Servant_State::HandleType servant_state =
00131 this->get_servant_state(servant);
00132
00133 bool is_sync_with_server = server_request.sync_with_server();
00134 bool is_synchronous = server_request.response_expected();
00135
00136 TP_Collocated_Synch_Request_Handle synch_request;
00137 TP_Collocated_Synch_With_Server_Request_Handle synch_with_server_request;
00138 TP_Request_Handle request;
00139
00140
00141 if (is_sync_with_server)
00142 {
00143 synch_with_server_request =
00144 new TP_Collocated_Synch_With_Server_Request
00145 (server_request,
00146 object_id,
00147 poa,
00148 operation,
00149 servant,
00150 servant_state.in());
00151
00152
00153 synch_with_server_request->_add_ref();
00154 request = synch_with_server_request.in();
00155 }
00156 else if (is_synchronous)
00157 {
00158 synch_request = new TP_Collocated_Synch_Request(server_request,
00159 object_id,
00160 poa,
00161 operation,
00162 servant,
00163 servant_state.in());
00164
00165
00166 synch_request->_add_ref();
00167 request = synch_request.in();
00168 }
00169 else
00170 {
00171
00172 request = new TP_Collocated_Asynch_Request(server_request,
00173 object_id,
00174 poa,
00175 operation,
00176 servant,
00177 servant_state.in());
00178 }
00179
00180
00181
00182 if (!this->task_.add_request(request.in()))
00183 {
00184
00185
00186
00187 return DISPATCH_REJECTED;
00188 }
00189
00190
00191
00192 if (!synch_request.is_nil())
00193 {
00194 int srw = synch_request->wait();
00195 if (srw == false)
00196 {
00197
00198 throw ::CORBA::NO_IMPLEMENT();
00199 }
00200 }
00201 else if (!synch_with_server_request.is_nil())
00202 {
00203 bool swsr = synch_with_server_request->wait();
00204 if (swsr == false)
00205 {
00206
00207 throw ::CORBA::NO_IMPLEMENT();
00208 }
00209 }
00210
00211 return DISPATCH_HANDLED;
00212 }
00213
00214
00215 void
00216 TAO::CSD::TP_Strategy::servant_activated_event_i
00217 (PortableServer::Servant servant,
00218 const PortableServer::ObjectId&)
00219 {
00220 if (this->serialize_servants_)
00221 {
00222
00223 this->servant_state_map_.insert(servant);
00224 }
00225 }
00226
00227
00228 void
00229 TAO::CSD::TP_Strategy::servant_deactivated_event_i
00230 (PortableServer::Servant servant,
00231 const PortableServer::ObjectId&)
00232 {
00233
00234 this->task_.cancel_servant(servant);
00235
00236 if (this->serialize_servants_)
00237 {
00238
00239 this->servant_state_map_.remove(servant);
00240 }
00241 }
00242
00243
00244 void
00245 TAO::CSD::TP_Strategy::cancel_requests(PortableServer::Servant servant)
00246 {
00247
00248 this->task_.cancel_servant(servant);
00249 }
00250
00251
00252 TAO::CSD::TP_Servant_State::HandleType
00253 TAO::CSD::TP_Strategy::get_servant_state(PortableServer::Servant servant)
00254 {
00255 TP_Servant_State::HandleType servant_state;
00256
00257 if (this->serialize_servants_)
00258 {
00259 servant_state = this->servant_state_map_.find(servant);
00260 }
00261
00262 return servant_state;
00263 }
00264 TAO_END_VERSIONED_NAMESPACE_DECL