RequestProcessingStrategyDefaultServant.cpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 #include "tao/orbconf.h"
00004 
00005 ACE_RCSID (PortableServer,
00006            Request_Processing,
00007            "$Id: RequestProcessingStrategyDefaultServant.cpp 76995 2007-02-11 12:51:42Z johnnyw $")
00008 
00009 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
00010 
00011 #include "tao/ORB_Constants.h"
00012 #include "tao/TSS_Resources.h"
00013 #include "tao/PortableServer/RequestProcessingStrategyDefaultServant.h"
00014 #include "tao/PortableServer/Non_Servant_Upcall.h"
00015 #include "tao/PortableServer/Root_POA.h"
00016 #include "tao/PortableServer/ServantManagerC.h"
00017 #include "tao/PortableServer/Servant_Base.h"
00018 #include "tao/PortableServer/POA_Current_Impl.h"
00019 
00020 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00021 
00022 namespace TAO
00023 {
00024   namespace Portable_Server
00025   {
00026     RequestProcessingStrategyDefaultServant::RequestProcessingStrategyDefaultServant (void)
00027       : default_servant_ (0)
00028     {
00029     }
00030 
00031     void
00032     RequestProcessingStrategyDefaultServant::strategy_cleanup(void)
00033     {
00034       this->default_servant_ = 0;
00035     }
00036 
00037     PortableServer::ServantManager_ptr
00038     RequestProcessingStrategyDefaultServant::get_servant_manager (void)
00039     {
00040       throw PortableServer::POA::WrongPolicy ();
00041     }
00042 
00043     void
00044     RequestProcessingStrategyDefaultServant::set_servant_manager (
00045       PortableServer::ServantManager_ptr /*imgr*/)
00046     {
00047       throw PortableServer::POA::WrongPolicy ();
00048     }
00049 
00050     PortableServer::Servant
00051     RequestProcessingStrategyDefaultServant::get_servant (void)
00052     {
00053       // This operation returns the default servant associated with the
00054       // POA.
00055       return this->default_servant_.in ();
00056     }
00057 
00058     void
00059     RequestProcessingStrategyDefaultServant::set_servant (
00060       PortableServer::Servant servant
00061       )
00062     {
00063       // This operation registers the specified servant with the POA as
00064       // the default servant. This servant will be used for all requests
00065       // for which no servant is found in the Active Object Map.
00066       this->default_servant_ = servant;
00067 
00068       // The implementation of set_servant will invoke _add_ref at least
00069       // once on the Servant argument before returning. When the POA no
00070       // longer needs the Servant, it will invoke _remove_ref on it the
00071       // same number of times.
00072       if (servant != 0)
00073         {
00074           // A recursive thread lock without using a recursive thread
00075           // lock.  Non_Servant_Upcall has a magic constructor and
00076           // destructor.  We unlock the Object_Adapter lock for the
00077           // duration of the servant activator upcalls; reacquiring once
00078           // the upcalls complete.  Even though we are releasing the lock,
00079           // other threads will not be able to make progress since
00080           // <Object_Adapter::non_servant_upcall_in_progress_> has been
00081           // set.
00082           Non_Servant_Upcall non_servant_upcall (*this->poa_);
00083           ACE_UNUSED_ARG (non_servant_upcall);
00084 
00085           servant->_add_ref ();
00086         }
00087     }
00088 
00089     TAO_SERVANT_LOCATION
00090     RequestProcessingStrategyDefaultServant::locate_servant (
00091       const PortableServer::ObjectId & system_id,
00092       PortableServer::Servant & servant
00093       )
00094     {
00095       TAO_SERVANT_LOCATION location = TAO_SERVANT_NOT_FOUND;
00096 
00097       location = this->poa_->servant_present (system_id, servant);
00098 
00099       if (location == TAO_SERVANT_NOT_FOUND)
00100         {
00101           if (this->default_servant_.in () != 0)
00102             {
00103               location = TAO_DEFAULT_SERVANT;
00104             }
00105         }
00106 
00107       return location;
00108     }
00109 
00110     PortableServer::Servant
00111     RequestProcessingStrategyDefaultServant::locate_servant (
00112       const char * /*operation*/,
00113       const PortableServer::ObjectId & system_id,
00114       TAO::Portable_Server::Servant_Upcall &servant_upcall,
00115       TAO::Portable_Server::POA_Current_Impl &poa_current_impl,
00116       bool & /*wait_occurred_restart_call*/
00117       )
00118     {
00119       PortableServer::Servant servant = 0;
00120 
00121       servant = this->poa_->find_servant (system_id,
00122                                           servant_upcall,
00123                                           poa_current_impl);
00124 
00125       if (servant == 0)
00126         {
00127           // If the POA has the USE_DEFAULT_SERVANT policy, a default servant
00128           // has been associated with the POA so the POA will invoke the
00129           // appropriate method on that servant. If no servant has been
00130           // associated with the POA, the POA raises the OBJ_ADAPTER system
00131           // exception.
00132           PortableServer::Servant default_servant = this->default_servant_.in ();
00133           if (default_servant == 0)
00134             {
00135               throw ::CORBA::OBJ_ADAPTER (
00136                 CORBA::OMGVMCID | 3,
00137                 CORBA::COMPLETED_NO);
00138             }
00139           else
00140             {
00141               // Success
00142               servant = default_servant;
00143             }
00144         }
00145 
00146         return servant;
00147     }
00148 
00149     PortableServer::Servant
00150     RequestProcessingStrategyDefaultServant::system_id_to_servant (
00151       const PortableServer::ObjectId &system_id)
00152     {
00153       PortableServer::Servant servant = this->default_servant_.in ();
00154 
00155       if (servant == 0)
00156         {
00157           servant = this->poa_->find_servant (system_id);
00158         }
00159 
00160       return servant;
00161     }
00162 
00163     PortableServer::Servant
00164     RequestProcessingStrategyDefaultServant::id_to_servant (
00165       const PortableServer::ObjectId & /*id*/)
00166     {
00167       PortableServer::Servant servant = this->default_servant_.in ();
00168 
00169       if (servant == 0)
00170         {
00171           /*
00172            * If using default servant request processing strategy but
00173            * no default servant is available, we will raise the
00174            * ObjectNotActive system exception.
00175            */
00176           throw PortableServer::POA::ObjectNotActive ();
00177         }
00178 
00179       return servant;
00180     }
00181 
00182     void
00183     RequestProcessingStrategyDefaultServant::cleanup_servant (
00184       PortableServer::Servant servant,
00185       const PortableServer::ObjectId &user_id
00186       )
00187     {
00188       if (servant)
00189         {
00190           // ATTENTION: Trick locking here, see class header for details
00191           Non_Servant_Upcall non_servant_upcall (*this->poa_);
00192           ACE_UNUSED_ARG (non_servant_upcall);
00193 
00194           servant->_remove_ref ();
00195         }
00196 
00197       // This operation causes the association of the Object Id specified
00198       // by the oid parameter and its servant to be removed from the
00199       // Active Object Map.
00200       if (this->poa_->unbind_using_user_id (user_id) != 0)
00201         {
00202           throw ::CORBA::OBJ_ADAPTER ();
00203         }
00204     }
00205 
00206     void
00207     RequestProcessingStrategyDefaultServant::etherealize_objects (
00208       CORBA::Boolean /*etherealize_objects*/)
00209     {
00210     }
00211 
00212     PortableServer::ObjectId *
00213     RequestProcessingStrategyDefaultServant::servant_to_id (
00214       PortableServer::Servant servant
00215       )
00216     {
00217       PortableServer::Servant default_servant = this->default_servant_.in ();
00218 
00219       if (default_servant != 0 &&
00220           default_servant == servant)
00221         {
00222           // If they are the same servant, then check if we are in an
00223           // upcall.
00224           TAO::Portable_Server::POA_Current_Impl *poa_current_impl =
00225             static_cast <TAO::Portable_Server::POA_Current_Impl *>
00226                         (TAO_TSS_Resources::instance ()->poa_current_impl_);
00227           // If we are in an upcall on the default servant, return the
00228           // ObjectId associated with the current invocation.
00229           if (poa_current_impl != 0 &&
00230               servant == poa_current_impl->servant ())
00231             {
00232               return poa_current_impl->get_object_id ();
00233             }
00234         }
00235 
00236       return this->poa_->servant_to_user_id (servant);
00237     }
00238 
00239     void
00240     RequestProcessingStrategyDefaultServant::post_invoke_servant_cleanup(
00241       const PortableServer::ObjectId &/*system_id*/,
00242       const TAO::Portable_Server::Servant_Upcall &/*servant_upcall*/)
00243     {
00244     }
00245 
00246     ::PortableServer::RequestProcessingPolicyValue
00247     RequestProcessingStrategyDefaultServant::type() const
00248     {
00249       return ::PortableServer::USE_DEFAULT_SERVANT;
00250     }
00251   }
00252 }
00253 
00254 TAO_END_VERSIONED_NAMESPACE_DECL
00255 
00256 #endif /* TAO_HAS_MINIMUM_POA == 0 */
00257 

Generated on Sun Jan 27 13:23:43 2008 for TAO_PortableServer by doxygen 1.3.6