POAManager.cpp

Go to the documentation of this file.
00001 // $Id: POAManager.cpp 78900 2007-07-15 13:05:48Z sowayaa $
00002 
00003 #include "tao/PortableServer/POAManager.h"
00004 #include "tao/PortableServer/POAManagerFactory.h"
00005 #include "tao/PortableServer/Root_POA.h"
00006 #include "tao/PortableServer/poa_macros.h"
00007 #include "tao/Server_Strategy_Factory.h"
00008 #include "tao/ORB_Core.h"
00009 #include "tao/IORInterceptor_Adapter.h"
00010 
00011 #if !defined (__ACE_INLINE__)
00012 # include "tao/PortableServer/POAManager.inl"
00013 #endif /* ! __ACE_INLINE__ */
00014 
00015 ACE_RCSID (PortableServer,
00016            POAManager,
00017            "$Id: POAManager.cpp 78900 2007-07-15 13:05:48Z sowayaa $")
00018 
00019 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00020 
00021 TAO_POA_Manager::TAO_POA_Manager (
00022   TAO_Object_Adapter &object_adapter,
00023 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
00024   const char * id,
00025   const ::CORBA::PolicyList &policies,
00026   PortableServer::POAManagerFactory_ptr poa_manager_factory)
00027 #else
00028   const char * id)
00029 #endif
00030   : state_ (PortableServer::POAManager::HOLDING),
00031     lock_ (object_adapter.lock ()),
00032     poa_collection_ (),
00033     object_adapter_ (object_adapter),
00034 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
00035     id_ (id == 0 ? this->generate_manager_id () : CORBA::string_dup (id)),
00036     poa_manager_factory_ (* dynamic_cast <TAO_POAManager_Factory*> (poa_manager_factory)),
00037     policies_ (policies)
00038 {
00039   poa_manager_factory_._add_ref ();
00040 }
00041 #else
00042     id_ (id == 0 ? this->generate_manager_id () : CORBA::string_dup (id))
00043 {
00044 }
00045 #endif
00046 
00047 
00048 TAO_POA_Manager::~TAO_POA_Manager (void)
00049 {
00050 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
00051   poa_manager_factory_._remove_ref ();
00052 #endif
00053 }
00054 
00055 char *
00056 TAO_POA_Manager::get_id (void)
00057 {
00058   return CORBA::string_dup (this->id_.in ());
00059 }
00060 
00061 void
00062 TAO_POA_Manager::activate_i (void)
00063 {
00064   // This operation changes the state of the POA manager to active. If
00065   // issued while the POA manager is in the inactive state, the
00066   // AdapterInactive exception is raised.  Entering the active state
00067   // enables the associated POAs to process requests.
00068 
00069   if (this->state_ == PortableServer::POAManager::INACTIVE)
00070     {
00071       throw PortableServer::POAManager::AdapterInactive ();
00072     }
00073   else
00074     {
00075       this->state_ = PortableServer::POAManager::ACTIVE;
00076       // Find the poas that applied the custom servant dispatching
00077       // strategy to launch the dispatching threads.
00078 
00079       for (POA_COLLECTION::iterator iterator = this->poa_collection_.begin ();
00080        iterator != this->poa_collection_.end ();
00081        ++iterator)
00082         {
00083           (*iterator)->poa_activated_hook ();
00084         }
00085     }
00086 
00087   this->adapter_manager_state_changed (this->state_);
00088 }
00089 
00090 void
00091 TAO_POA_Manager::deactivate_i (CORBA::Boolean etherealize_objects,
00092                                CORBA::Boolean wait_for_completion)
00093 {
00094   // Is the <wait_for_completion> semantics for this thread correct?
00095   TAO_Root_POA::check_for_valid_wait_for_completions (this->object_adapter_.orb_core (),
00096                                                       wait_for_completion);
00097 
00098   // This operation changes the state of the POA manager to
00099   // inactive. If issued while the POA manager is in the inactive
00100   // state, the AdapterInactive exception is raised.  Entering the
00101   // inactive state causes the associated POAs to reject requests that
00102   // have not begun to be executed as well as any new requests.
00103 
00104   if (this->state_ == PortableServer::POAManager::INACTIVE)
00105     {
00106       throw PortableServer::POAManager::AdapterInactive ();
00107     }
00108   else
00109     {
00110       this->state_ = PortableServer::POAManager::INACTIVE;
00111     }
00112 
00113   // After changing the state, if the etherealize_objects parameter is:
00114   //
00115   // a) TRUE - the POA manager will cause all associated POAs that
00116   // have the RETAIN and USE_SERVANT_MANAGER policies to perform the
00117   // etherealize operation on the associated servant manager for all
00118   // active objects.
00119   //
00120   // b) FALSE - the etherealize operation is not called. The purpose
00121   // is to provide developers with a means to shut down POAs in a
00122   // crisis (for example, unrecoverable error) situation.
00123 
00124   // If the wait_for_completion parameter is FALSE, this operation
00125   // will return immediately after changing the state. If the
00126   // parameter is TRUE and the current thread is not in an invocation
00127   // context dispatched by some POA belonging to the same ORB as this
00128   // POA, this operation does not return until there are no actively
00129   // executing requests in any of the POAs associated with this POA
00130   // manager (that is, all requests that were started prior to the
00131   // state change have completed) and, in the case of a TRUE
00132   // etherealize_objects, all invocations of etherealize have
00133   // completed for POAs having the RETAIN and USE_SERVANT_MANAGER
00134   // policies. If the parameter is TRUE and the current thread is in
00135   // an invocation context dispatched by some POA belonging to the
00136   // same ORB as this POA the BAD_INV_ORDER exception is raised and
00137   // the state is not changed.
00138 
00139   for (POA_COLLECTION::iterator iterator = this->poa_collection_.begin ();
00140        iterator != this->poa_collection_.end ();
00141        ++iterator)
00142     {
00143       TAO_Root_POA *poa = *iterator;
00144       // Notify the poas that applied the custom servant dispatching
00145       // strategy to stop the dispatching threads.
00146       poa->poa_deactivated_hook ();
00147 
00148       poa->deactivate_all_objects_i (etherealize_objects, wait_for_completion);
00149     }
00150 
00151   // If the ORB::shutdown operation is called, it makes a call on
00152   // deactivate with a TRUE etherealize_objects parameter for each POA
00153   // manager known in the process; the wait_for_completion parameter
00154   // to deactivate will be the same as the similarly named parameter
00155   // of ORB::shutdown.
00156   this->adapter_manager_state_changed (this->state_);
00157 }
00158 
00159 void
00160 TAO_POA_Manager::adapter_manager_state_changed (PortableServer::POAManager::State state)
00161 {
00162   PortableInterceptor::AdapterState adapter_state =
00163     static_cast<PortableInterceptor::AdapterState> (state);
00164 
00165   TAO_IORInterceptor_Adapter *ior_adapter =
00166     this->object_adapter_.orb_core ().ior_interceptor_adapter ();
00167 
00168   if (ior_adapter)
00169     {
00170       ior_adapter->adapter_manager_state_changed (this->id_.in (),
00171                                                   adapter_state);
00172     }
00173 }
00174 
00175 #if (TAO_HAS_MINIMUM_POA == 0)
00176 
00177 void
00178 TAO_POA_Manager::hold_requests_i (CORBA::Boolean wait_for_completion)
00179 {
00180   // Is the <wait_for_completion> semantics for this thread correct?
00181   TAO_Root_POA::check_for_valid_wait_for_completions (this->object_adapter_.orb_core (),
00182                                                       wait_for_completion);
00183 
00184   // This operation changes the state of the POA manager to
00185   // holding. If issued while the POA manager is in the inactive
00186   // state, the AdapterInactive exception is raised.  Entering the
00187   // holding state causes the associated POAs to queue incoming
00188   // requests.  Any requests that have been queued but have not
00189   // started executing will continue to be queued while in the holding
00190   // state.
00191 
00192   if (this->state_ == PortableServer::POAManager::INACTIVE)
00193     {
00194       throw PortableServer::POAManager::AdapterInactive ();
00195     }
00196   else
00197     {
00198       this->state_ = PortableServer::POAManager::HOLDING;
00199     }
00200 
00201   // If the wait_for_completion parameter is FALSE, this operation
00202   // returns immediately after changing the state. If the parameter is
00203   // TRUE and the current thread is not in an invocation context
00204   // dispatched by some POA belonging to the same ORB as this POA,
00205   // this operation does not return until either there are no actively
00206   // executing requests in any of the POAs associated with this POA
00207   // manager (that is, all requests that were started prior to the
00208   // state change have completed) or the state of the POA manager is
00209   // changed to a state other than holding. If the parameter is TRUE
00210   // and the current thread is in an invocation context dispatched by
00211   // some POA belonging to the same ORB as this POA the BAD_INV_ORDER
00212   // exception is raised and the state is not changed.
00213 
00214   if (wait_for_completion)
00215     {
00216       for (POA_COLLECTION::iterator iterator = this->poa_collection_.begin ();
00217            iterator != this->poa_collection_.end ();
00218            ++iterator)
00219         {
00220           TAO_Root_POA *poa = *iterator;
00221           poa->wait_for_completions (wait_for_completion);
00222         }
00223     }
00224 
00225   this->adapter_manager_state_changed (this->state_);
00226 }
00227 
00228 void
00229 TAO_POA_Manager::discard_requests_i (CORBA::Boolean wait_for_completion)
00230 {
00231   // Is the <wait_for_completion> semantics for this thread correct?
00232   TAO_Root_POA::check_for_valid_wait_for_completions (this->object_adapter_.orb_core (),
00233                                                       wait_for_completion);
00234 
00235   // This operation changes the state of the POA manager to
00236   // discarding. If issued while the POA manager is in the inactive
00237   // state, the AdapterInactive exception is raised.  Entering the
00238   // discarding state causes the associated POAs to discard incoming
00239   // requests.  In addition, any requests that have been queued but
00240   // have not started executing are discarded. When a request is
00241   // discarded, a TRANSIENT system exception is returned to the
00242   // client.
00243 
00244   if (this->state_ == PortableServer::POAManager::INACTIVE)
00245     {
00246       throw PortableServer::POAManager::AdapterInactive ();
00247     }
00248   else
00249     {
00250       this->state_ = PortableServer::POAManager::DISCARDING;
00251     }
00252 
00253   // If the wait_for_completion parameter is FALSE, this operation
00254   // returns immediately after changing the state. If the
00255   // parameter is TRUE and the current thread is not in an
00256   // invocation context dispatched by some POA belonging to the
00257   // same ORB as this POA, this operation does not return until
00258   // either there are no actively executing requests in any of the
00259   // POAs associated with this POA manager (that is, all requests
00260   // that were started prior to the state change have completed)
00261   // or the state of the POA manager is changed to a state other
00262   // than discarding. If the parameter is TRUE and the current
00263   // thread is in an invocation context dispatched by some POA
00264   // belonging to the same ORB as this POA the BAD_INV_ORDER
00265   // exception is raised and the state is not changed.
00266 
00267   if (wait_for_completion)
00268     {
00269       for (POA_COLLECTION::iterator iterator = this->poa_collection_.begin ();
00270            iterator != this->poa_collection_.end ();
00271            ++iterator)
00272         {
00273           TAO_Root_POA *poa = *iterator;
00274           poa->wait_for_completions (wait_for_completion);
00275         }
00276     }
00277 
00278   this->adapter_manager_state_changed (this->state_);
00279 }
00280 
00281 #endif /* TAO_HAS_MINIMUM_POA == 0 */
00282 
00283 int
00284 TAO_POA_Manager::remove_poa (TAO_Root_POA *poa)
00285 {
00286   int const result = this->poa_collection_.remove (poa);
00287 
00288   // The #if really only needs to go around the
00289   // "this->poa_manager_factory_.remove_poamanager (this);" line, but it's
00290   // moved out as an optimization for now.  If additional non-CORBA/e and
00291   // non-minimum POA code needs to go in that clause the #if would have to
00292   // move back in.
00293 
00294 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
00295   if (result == 0)
00296     {
00297       if (this->poa_collection_.is_empty ())
00298         {
00299           this->poa_manager_factory_.remove_poamanager (this);
00300         }
00301     }
00302 #endif
00303   return result;
00304 }
00305 
00306 int
00307 TAO_POA_Manager::register_poa (TAO_Root_POA *poa)
00308 {
00309   return this->poa_collection_.insert (poa);
00310 }
00311 
00312 void
00313 TAO_POA_Manager::check_state (void)
00314 {
00315   if (state_ == PortableServer::POAManager::ACTIVE)
00316     {
00317       // When a POA manager is in the active state, the associated
00318       // POAs will receive and start processing requests (assuming
00319       // that appropriate thread resources are available).
00320       return;
00321     }
00322 
00323   if (state_ == PortableServer::POAManager::DISCARDING)
00324     {
00325       // When a POA manager is in the discarding state, the associated
00326       // POAs will discard all incoming requests (whose processing has
00327       // not yet begun). When a request is discarded, the TRANSIENT
00328       // system exception, with standard minor code 1, must be
00329       // returned to the client-side to indicate that the request
00330       // should be re-issued. (Of course, an ORB may always reject a
00331       // request for other reasons and raise some other system
00332       // exception.)
00333       throw
00334         CORBA::TRANSIENT (
00335           CORBA::SystemException::_tao_minor_code (
00336             TAO_POA_DISCARDING,
00337             1),
00338           CORBA::COMPLETED_NO);
00339     }
00340 
00341   if (state_ == PortableServer::POAManager::HOLDING)
00342     {
00343       // When a POA manager is in the holding state, the associated
00344       // POAs will queue incoming requests. The number of requests
00345       // that can be queued is an implementation limit. If this limit
00346       // is reached, the POAs may discard requests and return the
00347       // TRANSIENT system exception, with standard minor code 1, to
00348       // the client to indicate that the client should reissue the
00349       // request. (Of course, an ORB may always reject a request for
00350       // other reasons and raise some other system exception.)
00351 
00352       // Since there is no queuing in TAO, we immediately raise a
00353       // TRANSIENT exception.
00354       throw ::CORBA::TRANSIENT (
00355                 CORBA::SystemException::_tao_minor_code (TAO_POA_HOLDING, 1),
00356                 CORBA::COMPLETED_NO);
00357     }
00358 
00359   if (state_ == PortableServer::POAManager::INACTIVE)
00360     {
00361       // The inactive state is entered when the associated POAs are to
00362       // be shut down. Unlike the discarding state, the inactive state
00363       // is not a temporary state. When a POA manager is in the
00364       // inactive state, the associated POAs will reject new
00365       // requests. The rejection mechanism used is specific to the
00366       // vendor. The GIOP location forwarding mechanism and
00367       // CloseConnection message are examples of mechanisms that could
00368       // be used to indicate the rejection. If the client is
00369       // co-resident in the same process, the ORB could raise the
00370       // OBJ_ADAPTER system exception, with standard minor code 1, to
00371       // indicate that the object implementation is unavailable.
00372       throw ::CORBA::OBJ_ADAPTER (
00373                 CORBA::SystemException::_tao_minor_code (TAO_POA_INACTIVE, 1),
00374                 CORBA::COMPLETED_NO);
00375     }
00376 }
00377 
00378 CORBA::ORB_ptr
00379 TAO_POA_Manager::_get_orb (void)
00380 {
00381   return CORBA::ORB::_duplicate (this->object_adapter_.orb_core ().orb ());
00382 }
00383 
00384 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Tue Feb 2 17:40:54 2010 for TAO_PortableServer by  doxygen 1.4.7