// -*- C++ -*- //============================================================================= /** * @file CSD_TP_Strategy.h * * $Id$ * * @author Tim Bradley */ //============================================================================= #ifndef TAO_CSD_TP_STRATEGY_H #define TAO_CSD_TP_STRATEGY_H #include /**/ "ace/pre.h" #include "CSD_TP_Export.h" #include "CSD_TP_Task.h" #include "CSD_TP_Servant_State_Map.h" #if !defined (ACE_LACKS_PRAGMA_ONCE) # pragma once #endif /* ACE_LACKS_PRAGMA_ONCE */ #include "tao/CSD_Framework/CSD_Strategy_Base.h" #include "tao/Intrusive_Ref_Count_Handle_T.h" TAO_BEGIN_VERSIONED_NAMESPACE_DECL namespace TAO { namespace CSD { class TP_Strategy; typedef TAO_Intrusive_Ref_Count_Handle TP_Strategy_Handle; class TP_Custom_Request_Operation; /** * @class TP_Strategy * * @brief A simple custom Thread-Pool servant dispatching strategy class. * * This class represents a concrete implementation of a "Custom * Servant Dispatching Strategy". This implementation is being called * the "Thread Pool Strategy" reference implementation. * * A custom servant dispatching strategy object can be applied to a * POA object in order to carry out the servant dispatching duties * for that POA. * */ class TAO_CSD_TP_Export TP_Strategy : public Strategy_Base { public: /// Constructor. TP_Strategy(unsigned num_threads = 1); /// Virtual Destructor. virtual ~TP_Strategy(); /// Set the number of threads in the pool (must be > 0). void set_num_threads(unsigned num_threads); /// Return codes for the custom dispatch_request() methods. enum CustomRequestOutcome { /// The request was successfully put on the request queue. REQUEST_DISPATCHED, /// The request has been executed/completed by a worker thread. REQUEST_EXECUTED, /// The request was removed from the queue and cancelled. REQUEST_CANCELLED, /// The request queue rejected the request REQUEST_REJECTED }; /// Inject a synchronous, custom request into the request queue. /// This will block the calling thread until the request is handled /// (dispatched or cancelled) or rejected. /// Will return REQUEST_EXECUTED, REQUEST_CANCELLED, or REQUEST_REJECTED. CustomRequestOutcome custom_synch_request (TP_Custom_Request_Operation* op ACE_ENV_ARG_DECL); /// Inject an asynchronous, custom request into the request queue. /// This will return control to the calling thread once the request /// has been placed into the queue (or rejected). /// Will return REQUEST_DISPATCHED or REQUEST_REJECTED. CustomRequestOutcome custom_asynch_request (TP_Custom_Request_Operation* op ACE_ENV_ARG_DECL); /// Cancel all requests that are targeted for the provided servant. /// This is requested on the user application level. void cancel_requests(PortableServer::Servant servant ACE_ENV_ARG_DECL); protected: /// Handle the dispatching of a remote request. /// /// This will cause a new "request" object to be created and pushed /// on to a "request queue". The worker threads are responsible for /// servicing the queue, and performing the actual dispatch logic. virtual Strategy_Base::DispatchResult dispatch_remote_request_i (TAO_ServerRequest& server_request, const PortableServer::ObjectId& object_id, PortableServer::POA_ptr poa, const char* operation, PortableServer::Servant servant ACE_ENV_ARG_DECL); /// Handle the dispatching of a collocated request. /// /// This will cause a new "request" object to be created and pushed /// on to a "request queue". The worker threads are responsible for /// servicing the queue, and performing the actual dispatch logic. virtual Strategy_Base::DispatchResult dispatch_collocated_request_i (TAO_ServerRequest& server_request, const PortableServer::ObjectId& object_id, PortableServer::POA_ptr poa, const char* operation, PortableServer::Servant servant ACE_ENV_ARG_DECL); /// Event - The POA has been activated. /// This will activate the worker thread(s). /// Returns true if the worker threads were activated successfully. /// Otherwise, returns false. virtual bool poa_activated_event_i(); /// Event - The POA has been deactivated. /// This will shutdown the worker thread(s). virtual void poa_deactivated_event_i(); /// Event - A servant has been activated virtual void servant_activated_event_i (PortableServer::Servant servant, const PortableServer::ObjectId& oid ACE_ENV_ARG_DECL); /// Event - A servant has been deactivated virtual void servant_deactivated_event_i (PortableServer::Servant servant, const PortableServer::ObjectId& oid ACE_ENV_ARG_DECL); private: /// This is the active object used by the worker threads. /// The request queue is owned/managed by the task object. /// The strategy object puts requests into the task's request /// queue, and the worker threads service the queued requests /// by performing the actual servant request dispatching logic. TP_Task task_; /// The number of worker threads to use for the task. unsigned num_threads_; /// The map of servant state objects. TP_Servant_State_Map servant_state_map_; }; } } TAO_END_VERSIONED_NAMESPACE_DECL #if defined (__ACE_INLINE__) # include "CSD_TP_Strategy.inl" #endif /* __ACE_INLINE__ */ #include /**/ "ace/post.h" #endif /* TAO_CSD_TP_STRATEGY_H */