Go to the documentation of this file.00001
00002 #include "orbsvcs/Notify/Structured/StructuredPushConsumer.h"
00003
00004 ACE_RCSID(RT_Notify, TAO_Notify_StructuredPushConsumer, "$Id: StructuredPushConsumer.cpp 84685 2009-03-02 22:49:17Z mesnier_p $")
00005
00006 #include "ace/Bound_Ptr.h"
00007 #include "tao/Stub.h"
00008 #include "tao/ORB_Core.h"
00009 #include "orbsvcs/Notify/Properties.h"
00010 #include "orbsvcs/Notify/Event.h"
00011
00012 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00013
00014 TAO_Notify_StructuredPushConsumer::TAO_Notify_StructuredPushConsumer (TAO_Notify_ProxySupplier* proxy)
00015 :TAO_Notify_Consumer (proxy), connection_valid(0)
00016 {
00017 }
00018
00019 TAO_Notify_StructuredPushConsumer::~TAO_Notify_StructuredPushConsumer ()
00020 {
00021 }
00022
00023 void
00024 TAO_Notify_StructuredPushConsumer::init (CosNotifyComm::StructuredPushConsumer_ptr push_consumer)
00025 {
00026
00027 ACE_ASSERT( CORBA::is_nil (this->push_consumer_.in()) );
00028
00029 if (CORBA::is_nil (push_consumer))
00030 {
00031 throw CORBA::BAD_PARAM();
00032 }
00033
00034 if (!TAO_Notify_PROPERTIES::instance()->separate_dispatching_orb ())
00035 {
00036 this->push_consumer_ = CosNotifyComm::StructuredPushConsumer::_duplicate (push_consumer);
00037 this->publish_ = CosNotifyComm::NotifyPublish::_duplicate (push_consumer);
00038 }
00039 else
00040 {
00041
00042 CORBA::String_var temp =
00043 TAO_Notify_PROPERTIES::instance()->orb()->object_to_string(push_consumer);
00044
00045 CORBA::Object_var obj =
00046 TAO_Notify_PROPERTIES::instance()->dispatching_orb()->string_to_object(temp.in());
00047
00048 try
00049 {
00050 CosNotifyComm::StructuredPushConsumer_var new_push_consumer =
00051 CosNotifyComm::StructuredPushConsumer::_unchecked_narrow(obj.in());
00052
00053 this->push_consumer_ = CosNotifyComm::StructuredPushConsumer::_duplicate (new_push_consumer.in());
00054 this->publish_ = CosNotifyComm::NotifyPublish::_duplicate (new_push_consumer.in());
00055
00056
00057 if (TAO_debug_level >= 10)
00058 {
00059 ACE_DEBUG ((LM_DEBUG,
00060 "(%P|%t) Structured push init dispatching ORB id is %s.\n",
00061 obj->_stubobj()->orb_core()->orbid()));
00062 }
00063
00064 }
00065 catch (const CORBA::TRANSIENT& ex)
00066 {
00067 ex._tao_print_exception (
00068 "Got a TRANSIENT in NS_StructuredPushConsumer::init");
00069 ACE_DEBUG ((LM_DEBUG, "(%P|%t) got it for NS_StructuredPushConsumer %@\n", this));
00070 }
00071 catch (const CORBA::Exception&)
00072 {
00073
00074 }
00075 }
00076 }
00077
00078 void
00079 TAO_Notify_StructuredPushConsumer::release (void)
00080 {
00081 delete this;
00082
00083 }
00084
00085 void
00086 TAO_Notify_StructuredPushConsumer::push (const CORBA::Any& event)
00087 {
00088 CosNotification::StructuredEvent notification;
00089
00090 TAO_Notify_Event::translate (event, notification);
00091
00092
00093 if ( !connection_valid ) {
00094 try
00095 {
00096 CORBA::PolicyList_var inconsistent_policies;
00097 this->push_consumer_->_validate_connection (inconsistent_policies.out());
00098 }
00099 catch (const CORBA::COMM_FAILURE&)
00100 {
00101
00102 if (TAO_debug_level >= 1)
00103 {
00104 ACE_DEBUG ((LM_DEBUG, "(%P|%t) Found bad connection.\n"));
00105 }
00106 }
00107 connection_valid = 1;
00108 }
00109
00110 last_ping_ = ACE_OS::gettimeofday ();
00111
00112 this->push_consumer_->push_structured_event (notification);
00113 }
00114
00115 void
00116 TAO_Notify_StructuredPushConsumer::push (const CosNotification::StructuredEvent& event)
00117 {
00118
00119 if (TAO_debug_level >= 10) {
00120 ACE_DEBUG ((LM_DEBUG, "(%P|%t) Structured push dispatching ORB id is %s.\n",
00121 this->push_consumer_->_stubobj()->orb_core()->orbid()));
00122 }
00123
00124
00125
00126 if ( !connection_valid ) {
00127 try
00128 {
00129 CORBA::PolicyList_var inconsistent_policies;
00130 this->push_consumer_->_validate_connection (inconsistent_policies.out());
00131 }
00132 catch (const CORBA::COMM_FAILURE&)
00133 {
00134
00135 if (TAO_debug_level >= 1)
00136 {
00137 ACE_DEBUG ((LM_DEBUG, "(%P|%t) Found bad connection.\n"));
00138 }
00139 }
00140 connection_valid = 1;
00141 }
00142
00143 last_ping_ = ACE_OS::gettimeofday ();
00144
00145 this->push_consumer_->push_structured_event (event);
00146 }
00147
00148
00149 void
00150 TAO_Notify_StructuredPushConsumer::push (const CosNotification::EventBatch& event)
00151 {
00152 ACE_ASSERT(false);
00153 ACE_UNUSED_ARG (event);
00154
00155 }
00156
00157 void
00158 TAO_Notify_StructuredPushConsumer::reconnect_from_consumer (TAO_Notify_Consumer* old_consumer)
00159 {
00160 TAO_Notify_StructuredPushConsumer* tmp = dynamic_cast<TAO_Notify_StructuredPushConsumer *> (old_consumer);
00161 ACE_ASSERT(tmp != 0);
00162 this->init(tmp->push_consumer_.in());
00163 this->schedule_timer(false);
00164 }
00165
00166 ACE_CString
00167 TAO_Notify_StructuredPushConsumer::get_ior (void) const
00168 {
00169 ACE_CString result;
00170 CORBA::ORB_var orb = TAO_Notify_PROPERTIES::instance()->orb();
00171 try
00172 {
00173 CORBA::String_var ior = orb->object_to_string(this->push_consumer_.in());
00174 result = static_cast<const char*> (ior.in ());
00175 }
00176 catch (const CORBA::Exception&)
00177 {
00178 result.fast_clear();
00179 }
00180 return result;
00181 }
00182
00183 CORBA::Object_ptr
00184 TAO_Notify_StructuredPushConsumer::get_consumer (void)
00185 {
00186 return CosNotifyComm::StructuredPushConsumer::_duplicate (this->push_consumer_.in ());
00187 }
00188
00189 TAO_END_VERSIONED_NAMESPACE_DECL