ProxySupplier.cpp

Go to the documentation of this file.
00001 // ProxySupplier.cpp,v 1.22 2006/03/14 06:14:34 jtc Exp
00002 
00003 #include "orbsvcs/Notify/ProxySupplier.h"
00004 
00005 #if ! defined (__ACE_INLINE__)
00006 #include "orbsvcs/Notify/ProxySupplier.inl"
00007 #endif /* __ACE_INLINE__ */
00008 
00009 ACE_RCSID(Notify, TAO_Notify_ProxySupplier, "ProxySupplier.cpp,v 1.22 2006/03/14 06:14:34 jtc Exp")
00010 
00011 #include "orbsvcs/Notify/Event_Manager.h"
00012 #include "orbsvcs/Notify/AdminProperties.h"
00013 #include "orbsvcs/Notify/Consumer.h"
00014 #include "orbsvcs/Notify/Method_Request_Dispatch.h"
00015 #include "orbsvcs/Notify/Worker_Task.h"
00016 #include "orbsvcs/Notify/Buffering_Strategy.h"
00017 #include "orbsvcs/Notify/Properties.h"
00018 #include "orbsvcs/Notify/ConsumerAdmin.h"
00019 
00020 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00021 
00022 TAO_Notify_ProxySupplier::TAO_Notify_ProxySupplier (void)
00023   : consumer_admin_ (0)
00024 {
00025 }
00026 
00027 TAO_Notify_ProxySupplier::~TAO_Notify_ProxySupplier ()
00028 {
00029 }
00030 
00031 void
00032 TAO_Notify_ProxySupplier::init (TAO_Notify_ConsumerAdmin* consumer_admin ACE_ENV_ARG_DECL)
00033 {
00034   ACE_ASSERT (consumer_admin != 0 && this->consumer_admin_.get() == 0);
00035 
00036   TAO_Notify_Proxy::initialize (consumer_admin ACE_ENV_ARG_PARAMETER);
00037   ACE_CHECK;
00038 
00039   this->consumer_admin_.reset (consumer_admin);
00040 
00041   const CosNotification::QoSProperties &default_ps_qos =
00042     TAO_Notify_PROPERTIES::instance ()->default_proxy_supplier_qos_properties ();
00043 
00044   this->set_qos (default_ps_qos ACE_ENV_ARG_PARAMETER);
00045   ACE_CHECK;
00046 }
00047 
00048 TAO_Notify_Peer*
00049 TAO_Notify_ProxySupplier:: peer (void)
00050 {
00051   return this->consumer ();
00052 }
00053 
00054 void
00055 TAO_Notify_ProxySupplier::connect (TAO_Notify_Consumer *consumer ACE_ENV_ARG_DECL)
00056   ACE_THROW_SPEC ((
00057                    CORBA::SystemException
00058                    , CosEventChannelAdmin::AlreadyConnected
00059                    ))
00060 {
00061   // Adopt the consumer
00062   ACE_Auto_Ptr< TAO_Notify_Consumer > auto_consumer (consumer);
00063 
00064   TAO_Notify_Atomic_Property_Long& consumer_count = this->admin_properties().consumers ();
00065   const TAO_Notify_Property_Long& max_consumers = this->admin_properties().max_consumers ();
00066 
00067   if (max_consumers != 0 && consumer_count >= max_consumers.value ())
00068   {
00069     ACE_THROW (CORBA::IMP_LIMIT ()); // we've reached the limit of consumers connected.
00070   }
00071 
00072   {
00073     ACE_GUARD_THROW_EX (TAO_SYNCH_MUTEX, ace_mon, this->lock_,
00074                         CORBA::INTERNAL ());
00075     ACE_CHECK;
00076 
00077     // if consumer is set and reconnect not allowed we get out.
00078     if (this->is_connected () && TAO_Notify_PROPERTIES::instance()->allow_reconnect() == false)
00079       {
00080           ACE_THROW (CosEventChannelAdmin::AlreadyConnected ());
00081       }
00082 
00083     // Adopt the consumer
00084     this->consumer_ = auto_consumer;
00085 
00086     this->consumer_admin_->subscribed_types (this->subscribed_types_ ACE_ENV_ARG_PARAMETER); // get the parents subscribed types.
00087     ACE_CHECK;
00088   }
00089 
00090   // Inform QoS values.
00091   ACE_ASSERT (this->consumer_.get() != 0);
00092   this->consumer_->qos_changed (this->qos_properties_);
00093 
00094   TAO_Notify_EventTypeSeq removed;
00095 
00096   this->event_manager().subscription_change (this, this->subscribed_types_, removed ACE_ENV_ARG_PARAMETER);
00097   ACE_CHECK;
00098 
00099   this->event_manager().connect (this ACE_ENV_ARG_PARAMETER);
00100   ACE_CHECK;
00101 
00102   // Increment the global consumer count
00103   ++consumer_count;
00104 }
00105 
00106 void
00107 TAO_Notify_ProxySupplier::disconnect (ACE_ENV_SINGLE_ARG_DECL)
00108 {
00109   TAO_Notify_EventTypeSeq added;
00110 
00111   this->event_manager().subscription_change (this, added, this->subscribed_types_ ACE_ENV_ARG_PARAMETER);
00112   ACE_CHECK;
00113 
00114   this->event_manager().disconnect (this ACE_ENV_ARG_PARAMETER);
00115   ACE_CHECK;
00116 
00117   // Decrement the global consumer count
00118   this->admin_properties().consumers ()--;
00119 }
00120 
00121 int
00122 TAO_Notify_ProxySupplier::shutdown (ACE_ENV_SINGLE_ARG_DECL)
00123 {
00124   if (this->TAO_Notify_Object::shutdown (ACE_ENV_SINGLE_ARG_PARAMETER) == 1)
00125     return 1;
00126 
00127   ACE_CHECK_RETURN (1);
00128 
00129   this->disconnect (ACE_ENV_SINGLE_ARG_PARAMETER);
00130   ACE_CHECK_RETURN (1);
00131 
00132   if (this->consumer_.get() != 0)
00133   {
00134     this->consumer_->shutdown (ACE_ENV_SINGLE_ARG_PARAMETER);
00135   }
00136   return 0;
00137 }
00138 
00139 void
00140 TAO_Notify_ProxySupplier::destroy (ACE_ENV_SINGLE_ARG_DECL)
00141 {
00142   int result = this->shutdown (ACE_ENV_SINGLE_ARG_PARAMETER);
00143   ACE_CHECK;
00144   if ( result == 1)
00145     return;
00146 
00147   this->consumer_admin_->remove (this ACE_ENV_ARG_PARAMETER);
00148   ACE_CHECK;
00149 
00150   // Do not reset this->consumer_.
00151   // It is not safe to delete the non-refcounted consumer here.
00152 }
00153 
00154 void
00155 TAO_Notify_ProxySupplier::deliver (TAO_Notify_Method_Request_Dispatch_No_Copy & request ACE_ENV_ARG_DECL)
00156 {
00157   this->execute_task (request ACE_ENV_ARG_PARAMETER);
00158 }
00159 
00160 void
00161 TAO_Notify_ProxySupplier::qos_changed (const TAO_Notify_QoSProperties& qos_properties)
00162 {
00163   TAO_Notify_Proxy::qos_changed (qos_properties);
00164 }
00165 
00166 TAO_END_VERSIONED_NAMESPACE_DECL

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