ProxyConsumer.cpp

Go to the documentation of this file.
00001 // ProxyConsumer.cpp,v 1.23 2006/03/14 06:14:34 jtc Exp
00002 
00003 #include "orbsvcs/Notify/ProxyConsumer.h"
00004 
00005 #if ! defined (__ACE_INLINE__)
00006 #include "orbsvcs/Notify/ProxyConsumer.inl"
00007 #endif /* __ACE_INLINE__ */
00008 
00009 ACE_RCSID(Notify, TAO_Notify_ProxyConsumer, "ProxyConsumer.cpp,v 1.23 2006/03/14 06:14:34 jtc Exp")
00010 
00011 #include "tao/debug.h"
00012 #include "ace/Atomic_Op.h"
00013 #include "orbsvcs/Notify/Supplier.h"
00014 #include "orbsvcs/Notify/AdminProperties.h"
00015 #include "orbsvcs/Notify/Property.h"
00016 #include "orbsvcs/Notify/Proxy.h"
00017 #include "orbsvcs/Notify/Event_Manager.h"
00018 #include "orbsvcs/Notify/Method_Request_Lookup.h"
00019 #include "orbsvcs/Notify/Worker_Task.h"
00020 #include "orbsvcs/Notify/Properties.h"
00021 #include "orbsvcs/Notify/SupplierAdmin.h"
00022 #include "orbsvcs/Notify/EventChannel.h"
00023 #include "orbsvcs/Notify/Routing_Slip.h"
00024 
00025 //#define DEBUG_LEVEL 10
00026 #ifndef DEBUG_LEVEL
00027 # define DEBUG_LEVEL TAO_debug_level
00028 #endif //DEBUG_LEVEL
00029 
00030 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00031 
00032 TAO_Notify_ProxyConsumer::TAO_Notify_ProxyConsumer (void)
00033   : supplier_admin_ (0)
00034 {
00035 }
00036 
00037 TAO_Notify_ProxyConsumer::~TAO_Notify_ProxyConsumer ()
00038 {
00039 }
00040 
00041 TAO_Notify_Peer*
00042 TAO_Notify_ProxyConsumer::peer (void)
00043 {
00044   return this->supplier ();
00045 }
00046 
00047 void
00048 TAO_Notify_ProxyConsumer::init (TAO_Notify::Topology_Parent* topology_parent ACE_ENV_ARG_DECL)
00049 {
00050   ACE_ASSERT( this->supplier_admin_.get() == 0 );
00051 
00052   TAO_Notify_Proxy::initialize (topology_parent ACE_ENV_ARG_PARAMETER);
00053   ACE_CHECK;
00054 
00055   this->supplier_admin_.reset (dynamic_cast<TAO_Notify_SupplierAdmin *>(topology_parent));
00056   ACE_ASSERT (this->supplier_admin_.get() != 0);
00057 
00058   const CosNotification::QoSProperties &default_ps_qos =
00059     TAO_Notify_PROPERTIES::instance ()->default_proxy_consumer_qos_properties ();
00060 
00061   this->set_qos (default_ps_qos ACE_ENV_ARG_PARAMETER);
00062 }
00063 
00064 void
00065 TAO_Notify_ProxyConsumer::connect (TAO_Notify_Supplier *supplier ACE_ENV_ARG_DECL)
00066   ACE_THROW_SPEC ((
00067                    CORBA::SystemException
00068                    , CosEventChannelAdmin::AlreadyConnected
00069                    ))
00070 {
00071   // Adopt the supplier
00072   ACE_Auto_Ptr< TAO_Notify_Supplier > auto_supplier (supplier);
00073 
00074   TAO_Notify_Atomic_Property_Long& supplier_count = this->admin_properties().suppliers ();
00075   const TAO_Notify_Property_Long& max_suppliers = this->admin_properties().max_suppliers ();
00076 
00077   if (max_suppliers != 0 && supplier_count >= max_suppliers.value ())
00078   {
00079     ACE_THROW (CORBA::IMP_LIMIT ()); // we've reached the limit of suppliers connected.
00080   }
00081 
00082   {
00083     ACE_GUARD_THROW_EX (TAO_SYNCH_MUTEX, ace_mon, this->lock_,
00084                         CORBA::INTERNAL ());
00085     ACE_CHECK;
00086 
00087     // if supplier is set and reconnect not allowed we get out.
00088     if (this->is_connected () && TAO_Notify_PROPERTIES::instance()->allow_reconnect() == false)
00089       {
00090         ACE_THROW (CosEventChannelAdmin::AlreadyConnected ());
00091       }
00092 
00093     // Adopt the supplier
00094     this->supplier_ = auto_supplier;
00095 
00096     this->supplier_admin_->subscribed_types (this->subscribed_types_ ACE_ENV_ARG_PARAMETER); // get the parents subscribed types.
00097     ACE_CHECK;
00098   }
00099 
00100   // Inform QoS values.
00101   ACE_ASSERT (this->supplier_.get() != 0);
00102   this->supplier_->qos_changed (this->qos_properties_);
00103 
00104   TAO_Notify_EventTypeSeq removed;
00105 
00106   this->event_manager().offer_change (this, this->subscribed_types_, removed ACE_ENV_ARG_PARAMETER);
00107   ACE_CHECK;
00108 
00109   this->event_manager().connect (this ACE_ENV_ARG_PARAMETER);
00110   ACE_CHECK;
00111 
00112   // Increment the global supplier count
00113   ++supplier_count;
00114 }
00115 void
00116 TAO_Notify_ProxyConsumer::push_i (TAO_Notify_Event * event ACE_ENV_ARG_DECL)
00117 {
00118   if (this->supports_reliable_events ())
00119     {
00120       TAO_Notify_Event::Ptr pevent(event->queueable_copy(ACE_ENV_SINGLE_ARG_PARAMETER));
00121       ACE_CHECK;
00122       TAO_Notify::Routing_Slip_Ptr routing_slip =
00123         TAO_Notify::Routing_Slip::create (pevent ACE_ENV_ARG_PARAMETER);
00124       ACE_CHECK;
00125       if (DEBUG_LEVEL > 0)
00126         ACE_DEBUG((LM_DEBUG, ACE_TEXT ("ProxyConsumer routing event.\n")));
00127       routing_slip->route (this, true ACE_ENV_ARG_PARAMETER);
00128       ACE_CHECK;
00129       routing_slip->wait_persist ();
00130     }
00131   else
00132     {
00133       TAO_Notify_Method_Request_Lookup_No_Copy request (event, this);
00134       this->execute_task (request ACE_ENV_ARG_PARAMETER);
00135       ACE_CHECK;
00136     }
00137 }
00138 
00139 bool
00140 TAO_Notify_ProxyConsumer::supports_reliable_events () const
00141 {
00142   bool reliable = false;
00143   CosNotification::PropertyValue value;
00144     if (this->find_qos_property_value (CosNotification::EventReliability, value))
00145     {
00146       CORBA::Long setting;
00147       if (value >>= setting)
00148       {
00149         reliable = (setting == CosNotification::Persistent);
00150       }
00151     }
00152   return reliable;
00153 }
00154 
00155 void
00156 TAO_Notify_ProxyConsumer::disconnect (ACE_ENV_SINGLE_ARG_DECL)
00157 {
00158   TAO_Notify_EventTypeSeq added;
00159 
00160   event_manager().offer_change (this, added, this->subscribed_types_ ACE_ENV_ARG_PARAMETER);
00161   ACE_CHECK;
00162 
00163   this->event_manager().disconnect (this ACE_ENV_ARG_PARAMETER);
00164   ACE_CHECK;
00165 
00166   // Decrement the global supplier count
00167   this->admin_properties().suppliers ()--;
00168 }
00169 
00170 int
00171 TAO_Notify_ProxyConsumer::shutdown (ACE_ENV_SINGLE_ARG_DECL)
00172 {
00173   if (this->TAO_Notify_Object::shutdown (ACE_ENV_SINGLE_ARG_PARAMETER) == 1)
00174     return 1;
00175 
00176   ACE_CHECK_RETURN (1);
00177 
00178   this->disconnect (ACE_ENV_SINGLE_ARG_PARAMETER);
00179   ACE_CHECK_RETURN (1);
00180 
00181   if (this->supplier_.get() != 0)
00182   {
00183     this->supplier_->shutdown (ACE_ENV_SINGLE_ARG_PARAMETER);
00184     ACE_CHECK_RETURN (1);
00185   }
00186   return 0;
00187 }
00188 
00189 void
00190 TAO_Notify_ProxyConsumer::destroy (ACE_ENV_SINGLE_ARG_DECL)
00191 {
00192   int result = this->shutdown (ACE_ENV_SINGLE_ARG_PARAMETER);
00193   ACE_CHECK;
00194   if ( result == 1)
00195     return;
00196 
00197   this->supplier_admin_->remove (this ACE_ENV_ARG_PARAMETER);
00198   ACE_CHECK;
00199 
00200   // Do not reset this->supplier_.
00201   // It is not safe to delete the non-refcounted supplier here.
00202 }
00203 
00204 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 13:24:14 2006 for TAO_CosNotification by doxygen 1.3.6