3 //=============================================================================
5 * @file DTP_POA_Strategy.h
7 * @author Marc Neeley <neeleym@ociweb.com>
9 //=============================================================================
11 #ifndef TAO_DYNAMIC_TP_POA_STRATEGY_H
12 #define TAO_DYNAMIC_TP_POA_STRATEGY_H
14 #include /**/ "ace/pre.h"
16 #include "tao/orbconf.h"
18 #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0
20 #include "tao/Dynamic_TP/dynamic_tp_export.h"
21 #include "tao/Dynamic_TP/DTP_Config.h"
22 #include "tao/Dynamic_TP/DTP_Task.h"
23 #include "tao/CSD_ThreadPool/CSD_TP_Servant_State_Map.h"
24 #include "tao/CSD_ThreadPool/CSD_TP_Custom_Request_Operation.h"
25 #include "tao/CSD_ThreadPool/CSD_TP_Strategy.h"
27 #if !defined (ACE_LACKS_PRAGMA_ONCE)
29 #endif /* ACE_LACKS_PRAGMA_ONCE */
31 #include "tao/CSD_Framework/CSD_Strategy_Base.h"
32 #include "tao/Intrusive_Ref_Count_Handle_T.h"
33 #include "ace/OS_NS_strings.h"
35 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
37 class TAO_DTP_POA_Strategy
;
38 typedef TAO_Intrusive_Ref_Count_Handle
<TAO_DTP_POA_Strategy
>
39 TAO_DTP_POA_Strategy_Handle
;
45 class TP_Custom_Request_Operation
;
51 * @class TAO_DTP_POA_Strategy
55 class TAO_Dynamic_TP_Export TAO_DTP_POA_Strategy
:
56 public TAO::CSD::Strategy_Base
60 /// This constructor supports situations where dynamic instantiation
61 /// of a thread pool for POAs is initiated from a svc.conf file.
62 /// A configuration name is passed in such that the object can
63 /// lookup a configuration in a pre-populated repository.
64 TAO_DTP_POA_Strategy(ACE_CString tp_config_name
,
65 bool serialize_servants
= true);
67 /// This constructor supports situations where explicit instantiation
68 /// of a thread pool for POAs is initiated from an application, such as
69 /// the use of the apply_to() method.
70 TAO_DTP_POA_Strategy(TAO_DTP_Definition
* tp_config
,
71 bool serialize_servants
= true);
73 /// Virtual Destructor.
74 virtual ~TAO_DTP_POA_Strategy();
76 /// Turn on/off serialization of servants.
77 void set_servant_serialization(bool serialize_servants
);
79 /// Return codes for the custom dispatch_request() methods.
80 enum CustomRequestOutcome
82 /// The request was successfully put on the request queue.
84 /// The request has been executed/completed by a worker thread.
86 /// The request was removed from the queue and cancelled.
88 /// The request queue rejected the request
92 /// Inject a synchronous, custom request into the request queue.
93 /// This will block the calling thread until the request is handled
94 /// (dispatched or cancelled) or rejected.
95 /// Will return REQUEST_EXECUTED, REQUEST_CANCELLED, or REQUEST_REJECTED.
96 CustomRequestOutcome custom_synch_request
97 (TAO::CSD::TP_Custom_Request_Operation
* op
);
99 /// Inject an asynchronous, custom request into the request queue.
100 /// This will return control to the calling thread once the request
101 /// has been placed into the queue (or rejected).
102 /// Will return REQUEST_DISPATCHED or REQUEST_REJECTED.
103 CustomRequestOutcome custom_asynch_request
104 (TAO::CSD::TP_Custom_Request_Operation
* op
);
106 /// Cancel all requests that are targeted for the provided servant.
107 /// This is requested on the user application level.
108 void cancel_requests(PortableServer::Servant servant
);
111 /// Handle the dispatching of a remote request.
113 /// This will cause a new "request" object to be created and pushed
114 /// on to a "request queue". The worker threads are responsible for
115 /// servicing the queue, and performing the actual dispatch logic.
116 virtual TAO::CSD::Strategy_Base::DispatchResult dispatch_remote_request_i
117 (TAO_ServerRequest
& server_request
,
118 const PortableServer::ObjectId
& object_id
,
119 PortableServer::POA_ptr poa
,
120 const char* operation
,
121 PortableServer::Servant servant
);
123 /// Handle the dispatching of a collocated request.
125 /// This will cause a new "request" object to be created and pushed
126 /// on to a "request queue". The worker threads are responsible for
127 /// servicing the queue, and performing the actual dispatch logic.
128 virtual TAO::CSD::Strategy_Base::DispatchResult dispatch_collocated_request_i
129 (TAO_ServerRequest
& server_request
,
130 const PortableServer::ObjectId
& object_id
,
131 PortableServer::POA_ptr poa
,
132 const char* operation
,
133 PortableServer::Servant servant
);
135 /// Event - The POA has been activated.
136 /// This will activate the worker thread(s).
137 /// Returns true if the worker threads were activated successfully.
138 /// Otherwise, returns false.
139 virtual bool poa_activated_event_i(TAO_ORB_Core
& orb_core
);
141 /// Event - The POA has been deactivated.
142 /// This will shutdown the worker thread(s).
143 virtual void poa_deactivated_event_i();
145 /// Event - A servant has been activated
146 virtual void servant_activated_event_i
147 (PortableServer::Servant servant
,
148 const PortableServer::ObjectId
& oid
);
150 /// Event - A servant has been deactivated
151 virtual void servant_deactivated_event_i
152 (PortableServer::Servant servant
,
153 const PortableServer::ObjectId
& oid
);
157 * Helper method that is responsible for looking up the servant
158 * state object in the servant state map *if* the "serialize
159 * servants" flag is set to true. In the case where the
160 * "serialize servants" flag is set to false, then a "nil"
161 * servant state handle object is returned.
163 * @param servant - input - a pointer to the servant object.
165 * @returns a handle to a servant state object.
167 * @throw PortableServer::POA::ServantNotActive if the servant
168 * state cannot be determined.
170 TAO::CSD::TP_Servant_State::HandleType get_servant_state
171 (PortableServer::Servant servant
);
173 /// The "serialize servants" flag.
174 bool serialize_servants_
;
176 /// The map of servant state objects - only used when the
177 /// "serialize servants" flag is set to true.
178 TAO::CSD::TP_Servant_State_Map servant_state_map_
;
180 /// This holds the name of a configuration that have been loaded
181 /// into a DTP_Config_Registry. This is the key to the RB
184 ACE_CString dynamic_tp_config_name_
;
186 /// This is the active object used by the worker threads.
187 /// The request queue is owned/managed by the task object.
188 /// The strategy object puts requests into the task's request
189 /// queue, and the worker threads service the queued requests
190 /// by performing the actual servant request dispatching logic.
191 TAO_DTP_Task dtp_task_
;
194 /// This boolean is used to determine if the configuration has
195 /// been sent in from an application or, if false, needs to be
196 /// looked up from a Dynamic TP Config repo. It works in conjunction with
197 /// dynamic_tp_config_name_ above.
198 bool config_initialized_
;
200 void set_dtp_config(TAO_DTP_Definition
&tp_config
);
204 TAO_END_VERSIONED_NAMESPACE_DECL
206 #if defined (__ACE_INLINE__)
207 #include "tao/Dynamic_TP/DTP_POA_Strategy.inl"
208 #endif /* __ACE_INLINE__ */
210 #endif /* (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0 */
212 #include /**/ "ace/post.h"
214 #endif /* TAO_DYNAMIC_TP_POA_STRATEGY_H */