Go to the documentation of this file.00001
00002
00003 #include "orbsvcs/Notify/MonitorControlExt/MonitorConsumerAdmin.h"
00004
00005 #include "ace/Monitor_Size.h"
00006 #include "ace/Monitor_Base.h"
00007
00008 #include "orbsvcs/Notify/MonitorControlExt/MonitorEventChannel.h"
00009 #include "orbsvcs/Notify/MonitorControl/Control_Registry.h"
00010 #include "orbsvcs/Notify/MonitorControl/Control.h"
00011 #include "orbsvcs/Notify/Buffering_Strategy.h"
00012
00013 #if defined (TAO_HAS_MONITOR_FRAMEWORK) && (TAO_HAS_MONITOR_FRAMEWORK == 1)
00014
00015 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00016
00017 class ConsumerAdminControl : public TAO_NS_Control
00018 {
00019 public:
00020 ConsumerAdminControl (TAO_MonitorEventChannel* ec,
00021 const ACE_CString& name,
00022 CosNotifyChannelAdmin::AdminID id)
00023 : TAO_NS_Control (name.c_str ()),
00024 ec_ (ec),
00025 id_ (id)
00026 {
00027 }
00028
00029 virtual bool execute (const char* command)
00030 {
00031 if (ACE_OS::strcmp (command, TAO_NS_CONTROL_REMOVE_CONSUMERADMIN) == 0)
00032 {
00033 CosNotifyChannelAdmin::ConsumerAdmin_var admin =
00034 this->ec_->get_consumeradmin (this->id_);
00035
00036 if (!CORBA::is_nil (admin.in ()))
00037 {
00038 admin->destroy ();
00039 }
00040 }
00041 else
00042 {
00043 return false;
00044 }
00045
00046 return true;
00047 }
00048
00049 private:
00050 TAO_MonitorEventChannel* ec_;
00051 CosNotifyChannelAdmin::AdminID id_;
00052 };
00053
00054 TAO_MonitorConsumerAdmin::TAO_MonitorConsumerAdmin (void)
00055 : stat_name_ (),
00056 control_name_ (),
00057 queue_size_ (0)
00058 {
00059 }
00060
00061 TAO_MonitorConsumerAdmin::~TAO_MonitorConsumerAdmin (void)
00062 {
00063 this->remove ();
00064
00065
00066
00067 this->queue_size_->remove_ref ();
00068 }
00069
00070 void
00071 TAO_MonitorConsumerAdmin::register_stats_controls (
00072 TAO_MonitorEventChannel* mec,
00073 const ACE_CString& base)
00074 {
00075
00076 this->stat_name_ = base + "/";
00077 this->queue_size_stat_name_ = stat_name_ +
00078 NotifyMonitoringExt::EventChannelQueueSize;
00079 ACE_NEW_THROW_EX (this->queue_size_,
00080 Monitor_Base (this->queue_size_stat_name_.c_str (),
00081 Monitor_Control_Types::MC_NUMBER),
00082 CORBA::NO_MEMORY ());
00083
00084 if (!mec->register_statistic (this->queue_size_stat_name_, this->queue_size_))
00085 {
00086
00087
00088 this->queue_size_->remove_ref ();
00089 this->queue_size_ = 0;
00090 throw NotifyMonitoringExt::NameAlreadyUsed ();
00091 }
00092
00093 this->overflow_stat_name_ = stat_name_ +
00094 NotifyMonitoringExt::EventChannelQueueOverflows;
00095 ACE_NEW_THROW_EX (this->overflows_,
00096 Monitor_Base (this->overflow_stat_name_.c_str (),
00097 Monitor_Control_Types::MC_COUNTER),
00098 CORBA::NO_MEMORY ());
00099 if (!mec->register_statistic (this->overflow_stat_name_, this->overflows_))
00100 {
00101 delete this->overflows_;
00102 this->overflows_ = 0;
00103 throw NotifyMonitoringExt::NameAlreadyUsed ();
00104 }
00105
00106 this->control_name_ = base;
00107 ConsumerAdminControl* control = 0;
00108 ACE_NEW_THROW_EX (control,
00109 ConsumerAdminControl (mec,
00110 this->control_name_.c_str (),
00111 this->id ()),
00112 CORBA::NO_MEMORY ());
00113 TAO_Control_Registry* cinstance = TAO_Control_Registry::instance ();
00114
00115 if (!cinstance->add (control))
00116 {
00117 delete control;
00118 ACE_ERROR ((LM_ERROR,
00119 "Unable to add control: %s\n",
00120 this->control_name_.c_str ()));
00121 }
00122 }
00123
00124 CosNotifyChannelAdmin::ProxySupplier_ptr
00125 TAO_MonitorConsumerAdmin::obtain_named_notification_push_supplier (
00126 CosNotifyChannelAdmin::ClientType ctype,
00127 CosNotifyChannelAdmin::ProxyID_out proxy_id,
00128 const char * name)
00129 {
00130
00131 TAO_MonitorEventChannel* ec =
00132 dynamic_cast<TAO_MonitorEventChannel*> (this->ec_.get ());
00133
00134 if (ec == 0)
00135 {
00136 throw CORBA::INTERNAL ();
00137 }
00138
00139
00140 CosNotifyChannelAdmin::ProxySupplier_var proxy =
00141 this->TAO_Notify_ConsumerAdmin::obtain_notification_push_supplier (
00142 ctype, proxy_id);
00143
00144
00145 ec->map_supplier_proxy (proxy_id, name);
00146
00147 return proxy._retn ();
00148 }
00149
00150 CosNotifyChannelAdmin::ProxySupplier_ptr
00151 TAO_MonitorConsumerAdmin::obtain_notification_push_supplier (
00152 CosNotifyChannelAdmin::ClientType ctype,
00153 CosNotifyChannelAdmin::ProxyID_out proxy_id)
00154 {
00155
00156 TAO_MonitorEventChannel* ec =
00157 dynamic_cast<TAO_MonitorEventChannel*> (this->ec_.get ());
00158
00159 if (ec == 0)
00160 {
00161 throw CORBA::INTERNAL ();
00162 }
00163
00164
00165 CosNotifyChannelAdmin::ProxySupplier_var proxy =
00166 this->TAO_Notify_ConsumerAdmin::obtain_notification_push_supplier (
00167 ctype, proxy_id);
00168
00169
00170 char name[64];
00171 ACE_OS::sprintf (name, "%d", proxy_id);
00172 ec->map_supplier_proxy (proxy_id, name);
00173
00174 return proxy._retn ();
00175 }
00176
00177 void
00178 TAO_MonitorConsumerAdmin::update_queue_count (size_t count)
00179 {
00180
00181
00182 this->queue_size_->receive (count);
00183
00184 if (this->child_ != 0)
00185 {
00186 this->child_->update_queue_count (count);
00187 }
00188 }
00189
00190
00191 void
00192 TAO_MonitorConsumerAdmin::count_queue_overflow (
00193 bool local_overflow,
00194 bool global_overflow)
00195 {
00196
00197
00198 this->overflows_->receive ((size_t)1);
00199
00200 if (this->child_ != 0)
00201 {
00202 this->child_->count_queue_overflow (local_overflow, global_overflow);
00203 }
00204 }
00205
00206 TAO_MonitorEventChannel *
00207 TAO_MonitorConsumerAdmin::get_ec (void) const
00208 {
00209 TAO_MonitorEventChannel* ec = dynamic_cast<TAO_MonitorEventChannel*> (this->ec_.get ());
00210 if (ec == 0)
00211 throw CORBA::INTERNAL ();
00212 return ec;
00213 }
00214
00215 const ACE_CString &
00216 TAO_MonitorConsumerAdmin::stat_name (void)const
00217 {
00218 return stat_name_;
00219 }
00220
00221
00222 void
00223 TAO_MonitorConsumerAdmin::destroy (void)
00224 {
00225 this->remove ();
00226 this->TAO_Notify_ConsumerAdmin::destroy ();
00227 }
00228
00229 void
00230 TAO_MonitorConsumerAdmin::remove (void)
00231 {
00232
00233 TAO_MonitorEventChannel* ec =
00234 dynamic_cast<TAO_MonitorEventChannel*> (this->ec_.get ());
00235 if (ec != 0)
00236 {
00237 ec->unregister_statistic (this->queue_size_stat_name_);
00238 ec->unregister_statistic (this->overflow_stat_name_);
00239 ec->unregister_statistic (this->stat_name_);
00240 ec->remove_consumeradmin (this->id ());
00241 TAO_Control_Registry* cinstance = TAO_Control_Registry::instance ();
00242 cinstance->remove (this->control_name_);
00243 }
00244
00245
00246 }
00247
00248
00249
00250 TAO_END_VERSIONED_NAMESPACE_DECL
00251
00252 #endif
00253