POAManager.cpp

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

Generated on Thu Nov 9 12:40:40 2006 for TAO_PortableServer by doxygen 1.3.6