00001 // $Id: Supplier.cpp 84685 2009-03-02 22:49:17Z mesnier_p $ 00002 00003 #include "tao/corba.h" 00004 #include "orbsvcs/Time_Utilities.h" 00005 #include "orbsvcs/Notify/Properties.h" 00006 #include "orbsvcs/Notify/Supplier.h" 00007 #include "tao/debug.h" 00008 #include "tao/Messaging/Messaging_TypesC.h" 00009 00010 #if ! defined (__ACE_INLINE__) 00011 #include "orbsvcs/Notify/Supplier.inl" 00012 #endif /* __ACE_INLINE__ */ 00013 00014 ACE_RCSID(Notify, TAO_Notify_Supplier, "$Id: Supplier.cpp 84685 2009-03-02 22:49:17Z mesnier_p $") 00015 00016 #include "orbsvcs/Notify/ProxyConsumer.h" 00017 #include "orbsvcs/Notify/Proxy.h" 00018 00019 #ifndef DEBUG_LEVEL 00020 # define DEBUG_LEVEL TAO_debug_level 00021 #endif //DEBUG_LEVEL 00022 00023 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00024 00025 TAO_Notify_Supplier::TAO_Notify_Supplier (TAO_Notify_ProxyConsumer* proxy) 00026 : proxy_ (proxy) 00027 { 00028 } 00029 00030 TAO_Notify_Supplier::~TAO_Notify_Supplier () 00031 { 00032 } 00033 00034 TAO_Notify_Proxy* 00035 TAO_Notify_Supplier::proxy (void) 00036 { 00037 return this->proxy_consumer (); 00038 } 00039 00040 void 00041 TAO_Notify_Supplier::dispatch_updates_i ( 00042 const CosNotification::EventTypeSeq& added, 00043 const CosNotification::EventTypeSeq& removed) 00044 { 00045 if (!CORBA::is_nil (this->subscribe_.in ())) 00046 this->subscribe_->subscription_change (added, removed); 00047 } 00048 00049 00050 00051 bool 00052 TAO_Notify_Supplier::is_alive (bool allow_nil_supplier) 00053 { 00054 bool status = false; 00055 CORBA::Object_var supplier = this->get_supplier (); 00056 if (CORBA::is_nil (supplier.in ())) 00057 { 00058 // The supplier may not connected or the supplier did 00059 // not provide a callback. In this case, the liveliness 00060 // check should return true so it will be validated in 00061 // next period. 00062 if (allow_nil_supplier) 00063 return true; 00064 else 00065 return status; 00066 } 00067 00068 CORBA::PolicyList policy_list; 00069 try 00070 { 00071 bool do_liveliness_check = false; 00072 ACE_Time_Value now = ACE_OS::gettimeofday (); 00073 ACE_Time_Value last_ping = proxy_->last_ping(); 00074 if (CORBA::is_nil (this->rtt_obj_.in ())) 00075 { 00076 // We need to determine if the supplier on the other end is still 00077 // alive. Since we may be in an upcall from the owner of the 00078 // original supplier, we have to put a timeout on the call in case 00079 // the client side is not processing ORB requests at this time. In 00080 // the event that the timeout exception occurs, we will assume that 00081 // the original supplier is still around. If we get any other 00082 // exception we will say that the original supplier is not 00083 // available anymore. 00084 TimeBase::TimeT timeout = 10000000; 00085 CORBA::Any timeout_any; 00086 timeout_any <<= timeout; 00087 00088 policy_list.length (1); 00089 policy_list[0] = TAO_Notify_PROPERTIES::instance()->orb()-> 00090 create_policy ( 00091 Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE, 00092 timeout_any); 00093 rtt_obj_ = 00094 supplier->_set_policy_overrides (policy_list, 00095 CORBA::ADD_OVERRIDE); 00096 00097 // Clean up the policy that was allocated in the try/catch 00098 for (CORBA::ULong i = 0; i < policy_list.length (); i++) 00099 policy_list[i]->destroy (); 00100 00101 do_liveliness_check 00102 = (last_ping == ACE_Time_Value::zero ? true 00103 : now - last_ping >= TAO_Notify_PROPERTIES::instance()->validate_client_delay ()); 00104 } 00105 else 00106 do_liveliness_check = 00107 now - last_ping >= TAO_Notify_PROPERTIES::instance()->validate_client_interval (); 00108 00109 if (CORBA::is_nil (rtt_obj_.in ())) 00110 status = false; 00111 else if (do_liveliness_check || allow_nil_supplier) 00112 { 00113 this->proxy_->last_ping (now); 00114 status = !rtt_obj_->_non_existent (); 00115 } 00116 else 00117 status = true; 00118 } 00119 catch (CORBA::TIMEOUT&) 00120 { 00121 status = true; 00122 } 00123 catch (CORBA::Exception& ex) 00124 { 00125 if (DEBUG_LEVEL > 0) 00126 { 00127 ex._tao_print_exception ("TAO_Notify_Supplier::is_alive: false"); 00128 } 00129 } 00130 00131 return status; 00132 } 00133 00134 TAO_END_VERSIONED_NAMESPACE_DECL