00001 // -*- C++ -*- 00002 00003 #include "tao/PortableServer/LifespanStrategyPersistent.h" 00004 00005 ACE_RCSID (PortableServer, 00006 Lifespan_Strategy, 00007 "$Id: LifespanStrategyPersistent.cpp 76898 2007-02-04 18:58:07Z johnnyw $") 00008 00009 #include "tao/PortableServer/Root_POA.h" 00010 #include "tao/PortableServer/POAManager.h" 00011 #include "tao/PortableServer/ImR_Client_Adapter.h" 00012 #include "tao/ORB_Core.h" 00013 #include "ace/OS_NS_sys_time.h" 00014 #include "ace/Dynamic_Service.h" 00015 #include "ace/Service_Config.h" 00016 00017 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00018 00019 namespace TAO 00020 { 00021 namespace Portable_Server 00022 { 00023 void 00024 LifespanStrategyPersistent::strategy_init (TAO_Root_POA *poa) 00025 { 00026 LifespanStrategy::strategy_init (poa); 00027 00028 this->use_imr_ = this->poa_->orb_core ().use_implrepo (); 00029 } 00030 00031 bool 00032 LifespanStrategyPersistent::validate ( 00033 CORBA::Boolean is_persistent, 00034 const TAO::Portable_Server::Temporary_Creation_Time& /*creation_time*/) const 00035 { 00036 return is_persistent; 00037 } 00038 00039 char 00040 LifespanStrategyPersistent::key_type (void) const 00041 { 00042 return 'P'; 00043 } 00044 00045 CORBA::Boolean 00046 LifespanStrategyPersistent::is_persistent (void) const 00047 { 00048 return true; 00049 } 00050 00051 void 00052 LifespanStrategyPersistent::create_key ( 00053 CORBA::Octet *buffer, 00054 CORBA::ULong& starting_at) 00055 { 00056 // Copy the persistence byte. 00057 buffer[starting_at] = static_cast<CORBA::Octet> (this->key_type ()); 00058 starting_at += this->key_type_length (); 00059 } 00060 00061 CORBA::ULong 00062 LifespanStrategyPersistent::key_length () const 00063 { 00064 return this->key_type_length (); 00065 } 00066 00067 void 00068 LifespanStrategyPersistent::notify_startup (void) 00069 { 00070 if (this->use_imr_) 00071 { 00072 // The user specified that the ImR should be used. 00073 ImR_Client_Adapter *adapter = 00074 ACE_Dynamic_Service<ImR_Client_Adapter>::instance ( 00075 TAO_Root_POA::imr_client_adapter_name () 00076 ); 00077 00078 #if !defined (TAO_AS_STATIC_LIBS) 00079 // In case we build shared, try to load the ImR Client library, in a 00080 // static build we just can't do this, so don't try it, lower layers 00081 // output an error then. 00082 if (adapter == 0) 00083 { 00084 ACE_Service_Config::process_directive ( 00085 ACE_DYNAMIC_SERVICE_DIRECTIVE( 00086 "ImR_Client_Adapter", "TAO_ImR_Client", 00087 "_make_ImR_Client_Adapter_Impl", "")); 00088 00089 adapter = 00090 ACE_Dynamic_Service<ImR_Client_Adapter>::instance ( 00091 TAO_Root_POA::imr_client_adapter_name ()); 00092 } 00093 #endif /* !TAO_AS_STATIC_LIBS */ 00094 00095 if (adapter != 0) 00096 { 00097 adapter->imr_notify_startup (this->poa_); 00098 } 00099 else 00100 { 00101 // When we don't have a ImR_Client adapter, but the user 00102 // has specified that the ImR has to be used we have an 00103 // error situation which has to be reported. 00104 ACE_ERROR ((LM_ERROR, 00105 ACE_TEXT ("(%P|%t) ERROR: No ImR_Client library ") 00106 ACE_TEXT ("available but use IMR has been specified.\n"))); 00107 00108 throw ::CORBA::INTERNAL (); 00109 } 00110 } 00111 } 00112 00113 void 00114 LifespanStrategyPersistent::notify_shutdown (void) 00115 { 00116 ImR_Client_Adapter *adapter = 00117 ACE_Dynamic_Service<ImR_Client_Adapter>::instance ( 00118 TAO_Root_POA::imr_client_adapter_name () 00119 ); 00120 00121 if (adapter != 0) 00122 { 00123 adapter->imr_notify_shutdown (this->poa_); 00124 } 00125 } 00126 00127 LifespanStrategyPersistent::LifespanStrategyPersistent() : 00128 use_imr_ (true) 00129 { 00130 } 00131 00132 void 00133 LifespanStrategyPersistent::check_state (void) 00134 { 00135 this->poa_->tao_poa_manager().check_state (); 00136 } 00137 00138 ::PortableServer::LifespanPolicyValue 00139 LifespanStrategyPersistent::type() const 00140 { 00141 return ::PortableServer::PERSISTENT; 00142 } 00143 00144 bool 00145 LifespanStrategyPersistent::use_imr () const 00146 { 00147 return use_imr_; 00148 } 00149 } /* namespace Portable_Server */ 00150 } /* namespace TAO */ 00151 00152 00153 TAO_END_VERSIONED_NAMESPACE_DECL