00001 // $Id: PushConsumer.cpp 84685 2009-03-02 22:49:17Z mesnier_p $ 00002 00003 #include "orbsvcs/Notify/Any/PushConsumer.h" 00004 00005 ACE_RCSID (Notify, 00006 TAO_Notify_PushConsumer, 00007 "$Id: PushConsumer.cpp 84685 2009-03-02 22:49:17Z mesnier_p $") 00008 00009 #include "ace/Bound_Ptr.h" 00010 #include "tao/Stub.h" // For debug messages printing out ORBid. 00011 #include "tao/ORB_Core.h" 00012 #include "orbsvcs/CosEventCommC.h" 00013 #include "orbsvcs/Notify/Event.h" 00014 #include "orbsvcs/Notify/Properties.h" 00015 00016 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00017 00018 TAO_Notify_PushConsumer::TAO_Notify_PushConsumer (TAO_Notify_ProxySupplier* proxy) 00019 :TAO_Notify_Consumer (proxy) 00020 { 00021 } 00022 00023 TAO_Notify_PushConsumer::~TAO_Notify_PushConsumer () 00024 { 00025 } 00026 00027 void 00028 TAO_Notify_PushConsumer::init (CosEventComm::PushConsumer_ptr push_consumer) 00029 { 00030 // Initialize only once 00031 ACE_ASSERT( CORBA::is_nil (this->push_consumer_.in()) ); 00032 00033 // push_consumer not optional 00034 if (CORBA::is_nil (push_consumer)) 00035 { 00036 throw CORBA::BAD_PARAM(); 00037 } 00038 00039 try 00040 { 00041 if (!TAO_Notify_PROPERTIES::instance()->separate_dispatching_orb ()) 00042 { 00043 this->push_consumer_ = CosEventComm::PushConsumer::_duplicate (push_consumer); 00044 00045 this->publish_ = 00046 CosNotifyComm::NotifyPublish::_narrow (push_consumer); 00047 } 00048 else 00049 { 00050 // "Port" consumer's object reference from receiving ORB to dispatching ORB. 00051 CORBA::String_var temp = 00052 TAO_Notify_PROPERTIES::instance()->orb()->object_to_string(push_consumer); 00053 00054 CORBA::Object_var obj = 00055 TAO_Notify_PROPERTIES::instance()->dispatching_orb()->string_to_object(temp.in()); 00056 00057 CosEventComm::PushConsumer_var new_cos_comm_pc = 00058 CosEventComm::PushConsumer::_unchecked_narrow(obj.in()); 00059 00060 this->push_consumer_ = 00061 CosEventComm::PushConsumer::_duplicate (new_cos_comm_pc.in()); 00062 00063 // 00064 // Note that here we do an _unchecked_narrow() in order to avoid 00065 // making a call on the consumer b/c the consumer may not have activated 00066 // its POA just yet. That means that before we use this reference the first 00067 // time, we'll actually need to call _is_a() on it, i.e., the equivalent 00068 // of an _narrow(). At the time of this writing, the only use of 00069 // this->publish_ is in TAO_NS_Consumer::dispatch_updates_i (the superclass). 00070 // If any other use is made of this data member, then the code to validate 00071 // the actual type of the target object must be refactored. 00072 this->publish_ = 00073 CosNotifyComm::NotifyPublish::_unchecked_narrow (obj.in()); 00074 00075 00076 //--cj verify dispatching ORB 00077 if (TAO_debug_level >= 10) 00078 { 00079 ACE_DEBUG ((LM_DEBUG, "(%P|%t) Any push init dispatching ORB id is %s.\n", 00080 obj->_stubobj()->orb_core()->orbid())); 00081 } 00082 //--cj end 00083 } 00084 } 00085 catch (const CORBA::TRANSIENT& ex) 00086 { 00087 ex._tao_print_exception ("Got a TRANSIENT in NS_PushConsumer::init"); 00088 ACE_DEBUG ((LM_DEBUG, "(%P|%t) got it for NS_PushConsumer %@\n", this)); 00089 } 00090 catch (const CORBA::Exception&) 00091 { 00092 // _narrow failed which probably means the interface is CosEventComm type. 00093 } 00094 } 00095 00096 void 00097 TAO_Notify_PushConsumer::release (void) 00098 { 00099 delete this; 00100 //@@ inform factory 00101 } 00102 00103 void 00104 TAO_Notify_PushConsumer::push (const CORBA::Any& payload) 00105 { 00106 //--cj verify dispatching ORB 00107 if (TAO_debug_level >= 10) { 00108 ACE_DEBUG ((LM_DEBUG, "(%P|%t) Any push dispatching ORB id is %s.\n", 00109 this->push_consumer_->_stubobj()->orb_core()->orbid())); 00110 } 00111 //--cj end 00112 00113 last_ping_ = ACE_OS::gettimeofday (); 00114 this->push_consumer_->push (payload); 00115 } 00116 00117 void 00118 TAO_Notify_PushConsumer::push (const CosNotification::StructuredEvent& event) 00119 { 00120 CORBA::Any any; 00121 00122 TAO_Notify_Event::translate (event, any); 00123 00124 last_ping_ = ACE_OS::gettimeofday (); 00125 this->push_consumer_->push (any); 00126 } 00127 00128 /// Push a batch of events to this consumer. 00129 void 00130 TAO_Notify_PushConsumer::push (const CosNotification::EventBatch& event) 00131 { 00132 ACE_ASSERT(false); 00133 ACE_UNUSED_ARG (event); 00134 // TODO exception? 00135 } 00136 00137 ACE_CString 00138 TAO_Notify_PushConsumer::get_ior (void) const 00139 { 00140 ACE_CString result; 00141 CORBA::ORB_var orb = TAO_Notify_PROPERTIES::instance()->orb(); 00142 try 00143 { 00144 CORBA::String_var ior = orb->object_to_string(this->push_consumer_.in()); 00145 result = static_cast<const char*> (ior.in ()); 00146 } 00147 catch (const CORBA::Exception&) 00148 { 00149 result.fast_clear(); 00150 } 00151 return result; 00152 } 00153 00154 void 00155 TAO_Notify_PushConsumer::reconnect_from_consumer (TAO_Notify_Consumer* old_consumer) 00156 { 00157 TAO_Notify_PushConsumer* tmp = 00158 dynamic_cast<TAO_Notify_PushConsumer*> (old_consumer); 00159 ACE_ASSERT(tmp != 0); 00160 this->init(tmp->push_consumer_.in()); 00161 this->schedule_timer(false); 00162 } 00163 00164 CORBA::Object_ptr 00165 TAO_Notify_PushConsumer::get_consumer (void) 00166 { 00167 return CosEventComm::PushConsumer::_duplicate (this->push_consumer_.in ()); 00168 } 00169 00170 TAO_END_VERSIONED_NAMESPACE_DECL