summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/Ice/Instance.cpp12
-rw-r--r--cpp/src/Ice/MetricsAdminI.cpp143
-rw-r--r--cpp/src/Ice/MetricsAdminI.h63
-rw-r--r--cpp/src/Ice/MetricsObserverI.h89
-rw-r--r--cpp/src/Ice/ObserverHelper.cpp19
-rw-r--r--cpp/src/Ice/ObserverI.cpp170
-rw-r--r--cpp/src/Ice/ObserverI.h7
7 files changed, 325 insertions, 178 deletions
diff --git a/cpp/src/Ice/Instance.cpp b/cpp/src/Ice/Instance.cpp
index 5edfcd294d4..71dde521406 100644
--- a/cpp/src/Ice/Instance.cpp
+++ b/cpp/src/Ice/Instance.cpp
@@ -1103,17 +1103,19 @@ IceInternal::Instance::Instance(const CommunicatorPtr& communicator, const Initi
PropertiesAdminIPtr props = new PropertiesAdminI("Properties", _initData.properties, _initData.logger);
_adminFacets.insert(FacetMap::value_type("Properties",props));
- // Make sure the MetricsAdmin plugin received property update notifications.
- props->addUpdateCallback(admin);
-
//
// Setup the communicator observer only the metrics admin plugin only if the user didn't already set an
// Ice observer resovler.
//
if(!_initData.observer &&
- (_adminFacetFilter.empty() || _adminFacetFilter.find("MetricsAdmin") != _adminFacetFilter.end()))
+ (_adminFacetFilter.empty() || _adminFacetFilter.find("MetricsAdmin") != _adminFacetFilter.end()) &&
+ _initData.properties->getProperty("Ice.Admin.Endpoints") != "")
{
- _initData.observer = new IceMX::CommunicatorObserverI(admin);
+ IceMX::CommunicatorObserverIPtr observer = new IceMX::CommunicatorObserverI(admin);
+ _initData.observer = observer;
+
+ // Make sure the MetricsAdmin plugin received property update notifications.
+ props->addUpdateCallback(observer);
}
__setNoDelete(false);
diff --git a/cpp/src/Ice/MetricsAdminI.cpp b/cpp/src/Ice/MetricsAdminI.cpp
index 2c0bc9594d3..341c8f852f7 100644
--- a/cpp/src/Ice/MetricsAdminI.cpp
+++ b/cpp/src/Ice/MetricsAdminI.cpp
@@ -71,7 +71,8 @@ MetricsMapI::RegExp::match(const MetricsHelper& helper)
#endif
}
-MetricsMapI::Entry::Entry(MetricsMapI* map, const MetricsPtr& object) : _object(object), _map(map)
+MetricsMapI::Entry::Entry(MetricsMapI* map, const MetricsPtr& object, const list<Entry*>::iterator& pos) :
+ _object(object), _map(map), _detachedPos(pos)
{
}
@@ -101,25 +102,6 @@ MetricsMapI::Entry::getFailures() const
return f;
}
-void
-MetricsMapI::Entry::detach(Ice::Long lifetime)
-{
- MetricsMapI* map;
- {
- IceUtil::Mutex::Lock sync(*this);
- _object->totalLifetime += lifetime;
- if(--_object->current > 0)
- {
- return;
- }
- map = _map;
- }
- if(map)
- {
- map->detached(this);
- }
-}
-
MetricsPtr
MetricsMapI::Entry::clone() const
{
@@ -133,13 +115,6 @@ MetricsMapI::Entry::id() const
return _object->id;
}
-bool
-MetricsMapI::Entry::isDetached() const
-{
- Lock sync(*this);
- return _object->current == 0;
-}
-
MetricsMapI::Entry*
MetricsMapI::Entry::getMatching(const string&, const MetricsHelper&)
{
@@ -272,20 +247,27 @@ MetricsMapI::getMatching(const MetricsHelper& helper)
return 0;
}
}
-
- ostringstream os;
- vector<string>::const_iterator q = _groupBySeparators.begin();
- for(vector<string>::const_iterator p = _groupByAttributes.begin(); p != _groupByAttributes.end(); ++p)
+
+ string key;
+ if(_groupByAttributes.size() == 1)
+ {
+ key = helper(_groupByAttributes.front());
+ }
+ else
{
- os << helper(*p);
- if(q != _groupBySeparators.end())
+ ostringstream os;
+ vector<string>::const_iterator q = _groupBySeparators.begin();
+ for(vector<string>::const_iterator p = _groupByAttributes.begin(); p != _groupByAttributes.end(); ++p)
{
- os << *q++;
+ os << helper(*p);
+ if(q != _groupBySeparators.end())
+ {
+ os << *q++;
+ }
}
+ key = os.str();
}
- string key = os.str();
-
Lock sync(*this);
map<string, EntryPtr>::const_iterator p = _objects.find(key);
if(p == _objects.end())
@@ -298,29 +280,35 @@ MetricsMapI::getMatching(const MetricsHelper& helper)
void
MetricsMapI::detached(Entry* entry)
{
- Lock sync(*this);
if(_retain == 0)
{
return;
}
+ Lock sync(*this);
assert(static_cast<int>(_detachedQueue.size()) <= _retain);
- deque<Entry*>::iterator p = _detachedQueue.begin();
- while(p != _detachedQueue.end())
+ if(entry->_detachedPos != _detachedQueue.end())
{
- if(*p == entry)
- {
- _detachedQueue.erase(p);
- break;
- }
- else if(!(*p)->isDetached())
- {
- p = _detachedQueue.erase(p);
- }
- else
+ _detachedQueue.splice(_detachedQueue.end(), _detachedQueue, entry->_detachedPos);
+ entry->_detachedPos = --_detachedQueue.end();
+ return;
+ }
+
+ if(static_cast<int>(_detachedQueue.size()) == _retain)
+ {
+ // Remove entries which are no longer detached
+ list<Entry*>::iterator p = _detachedQueue.begin();
+ while(p != _detachedQueue.end())
{
- ++p;
+ if(!(*p)->isDetached())
+ {
+ p = _detachedQueue.erase(p);
+ }
+ else
+ {
+ ++p;
+ }
}
}
@@ -332,6 +320,7 @@ MetricsMapI::detached(Entry* entry)
}
_detachedQueue.push_back(entry);
+ entry->_detachedPos = --_detachedQueue.end();
}
MetricsViewI::MetricsViewI(const string& name) : _name(name)
@@ -414,17 +403,6 @@ MetricsViewI::getFailures(const string& mapName, const string& id)
return MetricsFailures();
}
-MetricsMapI::EntryPtr
-MetricsViewI::getMatching(const string& mapName, const MetricsHelper& helper) const
-{
- map<string, MetricsMapIPtr>::const_iterator p = _maps.find(mapName);
- if(p != _maps.end())
- {
- return p->second->getMatching(helper);
- }
- return 0;
-}
-
vector<string>
MetricsViewI::getMaps() const
{
@@ -436,6 +414,17 @@ MetricsViewI::getMaps() const
return maps;
}
+MetricsMapIPtr
+MetricsViewI::getMap(const string& mapName) const
+{
+ map<string, MetricsMapIPtr>::const_iterator p = _maps.find(mapName);
+ if(p != _maps.end())
+ {
+ return p->second;
+ }
+ return 0;
+}
+
MetricsAdminI::MetricsAdminI(const Ice::PropertiesPtr& properties) : _properties(properties)
{
}
@@ -527,23 +516,6 @@ MetricsAdminI::updateViews()
}
}
-vector<MetricsMapI::EntryPtr>
-MetricsAdminI::getMatching(const string& mapName, const MetricsHelper& helper) const
-{
- Lock sync(*this);
- vector<MetricsMapI::EntryPtr> objects;
- for(map<string, MetricsViewIPtr>::const_iterator p = _views.begin(); p != _views.end(); ++p)
- {
- MetricsMapI::EntryPtr e = p->second->getMatching(mapName, helper);
- if(e)
- {
- objects.push_back(e);
- }
- }
- sort(objects.begin(), objects.end());
- return objects;
-}
-
Ice::StringSeq
MetricsAdminI::getMetricsViewNames(const ::Ice::Current&)
{
@@ -593,15 +565,18 @@ MetricsAdminI::getMetricsFailures(const string& view, const string& map, const s
return p->second->getFailures(map, id);
}
-void
-MetricsAdminI::updated(const PropertyDict& props)
+vector<MetricsMapIPtr>
+MetricsAdminI::getMaps(const string& mapName) const
{
- for(PropertyDict::const_iterator p = props.begin(); p != props.end(); ++p)
+ Lock sync(*this);
+ vector<MetricsMapIPtr> maps;
+ for(std::map<string, MetricsViewIPtr>::const_iterator p = _views.begin(); p != _views.end(); ++p)
{
- if(p->first.find("IceMX.") == 0)
+ MetricsMapIPtr map = p->second->getMap(mapName);
+ if(map)
{
- updateViews();
- return;
+ maps.push_back(map);
}
}
+ return maps;
}
diff --git a/cpp/src/Ice/MetricsAdminI.h b/cpp/src/Ice/MetricsAdminI.h
index 0f6171d5a46..92c0277353c 100644
--- a/cpp/src/Ice/MetricsAdminI.h
+++ b/cpp/src/Ice/MetricsAdminI.h
@@ -25,6 +25,8 @@
# include <regex.h>
#endif
+#include <list>
+
namespace IceMX
{
@@ -61,21 +63,20 @@ public:
{
public:
- Entry(MetricsMapI* map, const MetricsPtr& object);
+ Entry(MetricsMapI* map, const MetricsPtr& object, const std::list<Entry*>::iterator&);
void destroy();
void failed(const std::string& exceptionName);
MetricsFailures getFailures() const;
- void detach(Ice::Long lifetime);
+
virtual MetricsPtr clone() const;
const std::string& id() const;
- bool isDetached() const;
virtual Entry* getMatching(const std::string&, const MetricsHelper&);
template<typename T> IceInternal::Handle<T>
attach(const MetricsHelperT<T>& helper)
{
- IceUtil::Mutex::Lock sync(*this);
+ Lock sync(*this);
++_object->total;
++_object->current;
IceInternal::Handle<T> obj = IceInternal::Handle<T>::dynamicCast(_object);
@@ -84,18 +85,45 @@ public:
return obj;
}
+ void detach(Ice::Long lifetime)
+ {
+ MetricsMapI* map;
+ {
+ Lock sync(*this);
+ _object->totalLifetime += lifetime;
+ if(--_object->current > 0)
+ {
+ return;
+ }
+ map = _map;
+ }
+ if(map)
+ {
+ map->detached(this);
+ }
+ }
+
+ bool isDetached() const
+ {
+ Lock sync(*this);
+ return _object->current == 0;
+ }
+
template<typename Function, typename MetricsType> void
execute(Function func, const MetricsType& obj)
{
- IceUtil::Mutex::Lock sync(*this);
+ Lock sync(*this);
func(obj);
}
protected:
+ friend class MetricsMapI;
+
MetricsPtr _object;
MetricsMapI* _map;
StringIntDict _failures;
+ std::list<Entry*>::iterator _detachedPos;
};
typedef IceUtil::Handle<Entry> EntryPtr;
@@ -119,6 +147,7 @@ public:
protected:
virtual EntryPtr newEntry(const std::string&) = 0;
+ std::list<Entry*> _detachedQueue;
private:
@@ -133,7 +162,6 @@ private:
const std::vector<RegExpPtr> _reject;
std::map<std::string, EntryPtr> _objects;
- std::deque<Entry*> _detachedQueue;
};
typedef IceUtil::Handle<MetricsMapI> MetricsMapIPtr;
@@ -158,7 +186,8 @@ public:
{
public:
- EntryT(MetricsMapT* map, const TPtr& object) : Entry(map, object), _map(map)
+ EntryT(MetricsMapT* map, const TPtr& object, const std::list<Entry*>::iterator& p) :
+ Entry(map, object, p), _map(map)
{
}
@@ -185,7 +214,7 @@ public:
virtual MetricsPtr
clone() const
{
- IceUtil::Mutex::Lock sync(*this);
+ Lock sync(*this);
TPtr metrics = TPtr::dynamicCast(_object->ice_clone());
for(typename std::map<std::string, std::pair<MetricsMapIPtr, SubMapMember> >::const_iterator p =
_subMaps.begin(); p != _subMaps.end(); ++p)
@@ -210,7 +239,7 @@ public:
typename std::map<std::string, std::pair<SubMapMember, MetricsMapFactoryPtr> >::const_iterator p;
for(p = subMaps.begin(); p != subMaps.end(); ++p)
{
- const std::string subMapsPrefix = mapPrefix + ".Map.";
+ const std::string subMapsPrefix = mapPrefix + "Map.";
std::string subMapPrefix = subMapsPrefix + p->first;
if(properties->getPropertiesForPrefix(subMapPrefix).empty())
{
@@ -254,11 +283,11 @@ protected:
t->failures = 0;
if(_subMaps.empty())
{
- return new Entry(this, t);
+ return new Entry(this, t, _detachedQueue.end());
}
else
{
- return new EntryT(this, t);
+ return new EntryT(this, t, _detachedQueue.end());
}
}
@@ -303,10 +332,10 @@ public:
MetricsFailuresSeq getFailures(const std::string&);
MetricsFailures getFailures(const std::string&, const std::string&);
- MetricsMapI::EntryPtr getMatching(const std::string&, const MetricsHelper&) const;
-
std::vector<std::string> getMaps() const;
+ MetricsMapIPtr getMap(const std::string&) const;
+
private:
const std::string _name;
@@ -314,14 +343,12 @@ private:
};
typedef IceUtil::Handle<MetricsViewI> MetricsViewIPtr;
-class MetricsAdminI : public MetricsAdmin, public Ice::PropertiesAdminUpdateCallback, private IceUtil::Mutex
+class MetricsAdminI : public MetricsAdmin, private IceUtil::Mutex
{
public:
MetricsAdminI(const ::Ice::PropertiesPtr&);
- std::vector<MetricsMapI::EntryPtr> getMatching(const std::string&, const MetricsHelper&) const;
-
void addUpdater(const std::string&, const UpdaterPtr&);
void updateViews();
@@ -347,8 +374,8 @@ public:
virtual MetricsFailures getMetricsFailures(const std::string&, const std::string&, const std::string&,
const ::Ice::Current&);
- virtual void updated(const Ice::PropertyDict&);
-
+ std::vector<MetricsMapIPtr> getMaps(const std::string&) const;
+
private:
std::map<std::string, MetricsViewIPtr> _views;
diff --git a/cpp/src/Ice/MetricsObserverI.h b/cpp/src/Ice/MetricsObserverI.h
index ef669150b23..0adfb9f4283 100644
--- a/cpp/src/Ice/MetricsObserverI.h
+++ b/cpp/src/Ice/MetricsObserverI.h
@@ -58,6 +58,10 @@ protected:
public:
+ AttributeResolverT() : _default(0)
+ {
+ }
+
~AttributeResolverT()
{
for(typename std::map<std::string, Resolver*>::iterator p = _attributes.begin(); p != _attributes.end();++p)
@@ -75,33 +79,43 @@ protected:
{
return "";
}
+ if(_default)
+ {
+ return (helper->*_default)(attribute);
+ }
return "unknown";
}
return (*p->second)(helper);
}
+
+ void
+ setDefault(std::string (Helper::*memberFn)(const std::string&) const)
+ {
+ _default = memberFn;
+ }
template<typename Y> void
add(const std::string& name, Y Helper::*member)
{
- _attributes.insert(make_pair(name, new HelperMemberResolver<Y>(member)));
+ _attributes.insert(make_pair(name, new HelperMemberResolver<Y>(member)));
}
template<typename Y> void
add(const std::string& name, Y (Helper::*memberFn)() const)
{
- _attributes.insert(make_pair(name, new HelperMemberFunctionResolver<Y>(memberFn)));
+ _attributes.insert(make_pair(name, new HelperMemberFunctionResolver<Y>(memberFn)));
}
template<typename I, typename O, typename Y> void
add(const std::string& name, O (Helper::*getFn)() const, Y I::*member)
{
- _attributes.insert(make_pair(name, new MemberResolver<I, O, Y>(getFn, member)));
+ _attributes.insert(make_pair(name, new MemberResolver<I, O, Y>(getFn, member)));
}
template<typename I, typename O, typename Y> void
add(const std::string& name, O (Helper::*getFn)() const, Y (I::*memberFn)() const)
{
- _attributes.insert(make_pair(name, new MemberFunctionResolver<I, O, Y>(getFn, memberFn)));
+ _attributes.insert(make_pair(name, new MemberFunctionResolver<I, O, Y>(getFn, memberFn)));
}
private:
@@ -208,7 +222,7 @@ protected:
return os.str();
}
- static std::string
+ static const std::string&
toString(const std::string& s)
{
return s;
@@ -221,6 +235,7 @@ protected:
}
std::map<std::string, Resolver*> _attributes;
+ std::string (Helper::*_default)(const std::string&) const;
};
};
@@ -257,7 +272,7 @@ public:
ObserverT()
{
}
-
+
virtual void
attach()
{
@@ -293,6 +308,16 @@ public:
}
void
+ init(const MetricsHelperT<MetricsType>& helper, const std::vector<MetricsMapI::EntryPtr>& objects)
+ {
+ _objects.reserve(objects.size());
+ for(std::vector<MetricsMapI::EntryPtr>::const_iterator p = objects.begin(); p != objects.end(); ++p)
+ {
+ _objects.push_back(std::make_pair((*p)->attach(helper), *p));
+ }
+ }
+
+ void
update(const MetricsHelperT<MetricsType>& helper, const std::vector<MetricsMapI::EntryPtr>& objects)
{
std::vector<MetricsMapI::EntryPtr>::const_iterator p = objects.begin();
@@ -331,7 +356,7 @@ public:
}
IceInternal::Handle<ObserverImpl> obsv = new ObserverImpl();
- obsv->update(helper, metricsObjects);
+ obsv->init(helper, metricsObjects);
return obsv;
}
@@ -358,7 +383,7 @@ newUpdater(const IceInternal::Handle<T>& updater, void (T::*fn)())
}
template<typename ObserverImplType>
-class ObserverFactoryT
+class ObserverFactoryT : private IceUtil::Mutex
{
public:
@@ -373,21 +398,43 @@ public:
ObserverImplPtrType
getObserver(const MetricsHelperT<MetricsType>& helper)
{
- std::vector<MetricsMapI::EntryPtr> metricsObjects = _metrics->getMatching(_name, helper);
+ IceUtil::Mutex::Lock sync(*this);
+
+ std::vector<MetricsMapI::EntryPtr> metricsObjects;
+ for(std::vector<MetricsMapIPtr>::const_iterator p = _maps.begin(); p != _maps.end(); ++p)
+ {
+ MetricsMapI::EntryPtr entry = (*p)->getMatching(helper);
+ if(entry)
+ {
+ metricsObjects.push_back(entry);
+ }
+ }
+
if(metricsObjects.empty())
{
return 0;
}
ObserverImplPtrType obsv = new ObserverImplType();
- obsv->update(helper, metricsObjects);
+ obsv->init(helper, metricsObjects);
return obsv;
}
template<typename ObserverPtrType> ObserverImplPtrType
getObserver(const MetricsHelperT<MetricsType>& helper, const ObserverPtrType& observer)
{
- std::vector<MetricsMapI::EntryPtr> metricsObjects = _metrics->getMatching(_name, helper);
+ IceUtil::Mutex::Lock sync(*this);
+
+ std::vector<MetricsMapI::EntryPtr> metricsObjects;
+ for(std::vector<MetricsMapIPtr>::const_iterator p = _maps.begin(); p != _maps.end(); ++p)
+ {
+ MetricsMapI::EntryPtr entry = (*p)->getMatching(helper);
+ if(entry)
+ {
+ metricsObjects.push_back(entry);
+ }
+ }
+
if(metricsObjects.empty())
{
return 0;
@@ -397,8 +444,12 @@ public:
if(!obsv)
{
obsv = new ObserverImplType();
+ obsv->init(helper, metricsObjects);
+ }
+ else
+ {
+ obsv->update(helper, metricsObjects);
}
- obsv->update(helper, metricsObjects);
return obsv;
}
@@ -408,10 +459,24 @@ public:
_metrics->registerSubMap<SubMapMetricsType>(_name, subMap, member);
}
+ bool isEnabled() const
+ {
+ return _enabled;
+ }
+
+ void updateMaps()
+ {
+ IceUtil::Mutex::Lock sync(*this);
+ _maps = _metrics->getMaps(_name);
+ _enabled = !_maps.empty();
+ }
+
private:
const MetricsAdminIPtr _metrics;
const std::string _name;
+ std::vector<MetricsMapIPtr> _maps;
+ volatile bool _enabled;
};
}
diff --git a/cpp/src/Ice/ObserverHelper.cpp b/cpp/src/Ice/ObserverHelper.cpp
index f4e128ff652..c4406dd088b 100644
--- a/cpp/src/Ice/ObserverHelper.cpp
+++ b/cpp/src/Ice/ObserverHelper.cpp
@@ -19,16 +19,23 @@ using namespace IceInternal;
InvocationObserver::InvocationObserver(IceProxy::Ice::Object* proxy, const string& operation, const Context* context)
{
- if(proxy->__reference()->getInstance()->initializationData().observer)
+ const Ice::Instrumentation::CommunicatorObserverPtr& obsv =
+ proxy->__reference()->getInstance()->initializationData().observer;
+ if(obsv)
{
- attach(proxy, operation, context);
+ if(context)
+ {
+ ObserverHelperT<Ice::Instrumentation::InvocationObserver>::attach(
+ obsv->getInvocationObserverWithContext(proxy, operation, *context));
+ }
+ else
+ {
+ ObserverHelperT<Ice::Instrumentation::InvocationObserver>::attach(
+ obsv->getInvocationObserver(proxy, operation));
+ }
}
}
-InvocationObserver::InvocationObserver()
-{
-}
-
void
InvocationObserver::attach(IceProxy::Ice::Object* proxy, const string& operation, const Context* context)
{
diff --git a/cpp/src/Ice/ObserverI.cpp b/cpp/src/Ice/ObserverI.cpp
index 7ad96f4610e..5ec9296bbc3 100644
--- a/cpp/src/Ice/ObserverI.cpp
+++ b/cpp/src/Ice/ObserverI.cpp
@@ -21,6 +21,8 @@ using namespace IceMX;
namespace
{
+Ice::Context emptyCtx;
+
int ConnectionMetrics::*
getConnectionStateMetric(ConnectionState s)
{
@@ -167,22 +169,26 @@ public:
++(v.get()->*getConnectionStateMetric(_state));
}
- string
+ const string&
getId() const
{
- ostringstream os;
- IPConnectionInfoPtr info = IPConnectionInfoPtr::dynamicCast(_connection);
- if(info)
- {
- os << info->localAddress << ':' << info->localPort;
- os << " -> ";
- os << info->remoteAddress << ':' << info->remotePort;
- }
- else
+ if(_id.empty())
{
- os << "connection-" << _connection.get();
+ ostringstream os;
+ IPConnectionInfoPtr info = IPConnectionInfoPtr::dynamicCast(_connection);
+ if(info)
+ {
+ os << info->localAddress << ':' << info->localPort;
+ os << " -> ";
+ os << info->remoteAddress << ':' << info->remotePort;
+ }
+ else
+ {
+ os << "connection-" << _connection.get();
+ }
+ _id = os.str();
}
- return os.str();
+ return _id;
}
string
@@ -212,9 +218,10 @@ public:
private:
- const ConnectionInfoPtr _connection;
- const EndpointInfoPtr _endpoint;
+ const ConnectionInfoPtr& _connection;
+ const EndpointInfoPtr& _endpoint;
const ConnectionState _state;
+ mutable string _id;
};
ConnectionHelper::Attributes ConnectionHelper::attributes;
@@ -240,6 +247,8 @@ public:
add("facet", &DispatchHelper::getCurrent, &Current::facet);
add("encoding", &DispatchHelper::getCurrent, &Current::encoding);
add("mode", &DispatchHelper::getMode);
+
+ setDefault(&DispatchHelper::resolve);
}
};
static Attributes attributes;
@@ -250,19 +259,20 @@ public:
virtual string operator()(const string& attribute) const
{
- if(attribute.find("context.") == 0)
+ return attributes(this, attribute);
+ }
+
+ string resolve(const string& attribute) const
+ {
+ if(attribute.compare(0, 8, "context.") == 0)
{
Ice::Context::const_iterator p = _current.ctx.find(attribute.substr(8));
if(p != _current.ctx.end())
{
return p->second;
}
- return "unknown";
- }
- else
- {
- return attributes(this, attribute);
}
+ return "unknown";
}
string
@@ -271,16 +281,20 @@ public:
return _current.requestId == 0 ? "oneway" : "twoway";
}
- string
+ const string&
getId() const
{
- ostringstream os;
- if(!_current.id.category.empty())
+ if(_id.empty())
{
- os << _current.id.category << '/';
+ ostringstream os;
+ if(!_current.id.category.empty())
+ {
+ os << _current.id.category << '/';
+ }
+ os << _current.id.name << " [" << _current.operation << ']';
+ _id = os.str();
}
- os << _current.id.name << " [" << _current.operation << ']';
- return os.str();
+ return _id;
}
string
@@ -316,6 +330,7 @@ public:
private:
const Current& _current;
+ mutable string _id;
};
DispatchHelper::Attributes DispatchHelper::attributes;
@@ -333,37 +348,40 @@ public:
add("parent", &InvocationHelper::getParent);
add("id", &InvocationHelper::getId);
- add("operation", &InvocationHelper::_operation);
+ add("operation", &InvocationHelper::getOperation);
add("identityCategory", &InvocationHelper::getIdentity, &Identity::category);
add("identityName", &InvocationHelper::getIdentity, &Identity::name);
add("facet", &InvocationHelper::getProxy, &IceProxy::Ice::Object::ice_getFacet);
add("encoding", &InvocationHelper::getProxy, &IceProxy::Ice::Object::ice_getEncodingVersion);
add("mode", &InvocationHelper::getMode);
add("proxy", &InvocationHelper::getProxy);
+
+ setDefault(&InvocationHelper::resolve);
}
};
static Attributes attributes;
- InvocationHelper(const Ice::ObjectPrx& proxy, const string& op, const Ice::Context& ctx = Ice::Context()) :
+ InvocationHelper(const Ice::ObjectPrx& proxy, const string& op, const Ice::Context& ctx = emptyCtx) :
_proxy(proxy), _operation(op), _context(ctx)
{
}
- virtual string operator()(const string& attribute) const
+ string resolve(const string& attribute) const
{
- if(attribute.find("context.") == 0)
+ if(attribute.compare(0, 8, "context.") == 0)
{
Ice::Context::const_iterator p = _context.find(attribute.substr(8));
if(p != _context.end())
{
return p->second;
}
- return "unknown";
- }
- else
- {
- return attributes(this, attribute);
}
+ return "unknown";
+ }
+
+ virtual string operator()(const string& attribute) const
+ {
+ return attributes(this, attribute);
}
string
@@ -395,12 +413,16 @@ public:
}
}
- string
+ const string&
getId() const
{
- ostringstream os;
- os << _proxy << " [" << _operation << ']';
- return os.str();
+ if(_id.empty())
+ {
+ ostringstream os;
+ os << _proxy << " [" << _operation << ']';
+ _id = os.str();
+ }
+ return _id;
}
string
@@ -422,11 +444,18 @@ public:
return _proxy->ice_getIdentity();
}
+ const string&
+ getOperation() const
+ {
+ return _operation;
+ }
+
private:
const ObjectPrx& _proxy;
- const string _operation;
+ const string& _operation;
const Ice::Context& _context;
+ mutable string _id;
};
InvocationHelper::Attributes InvocationHelper::attributes;
@@ -457,20 +486,24 @@ public:
return attributes(this, attribute);
}
- string
+ const string&
getId() const
{
- ostringstream os;
- IPConnectionInfoPtr info = IPConnectionInfoPtr::dynamicCast(_connection->getInfo());
- if(info)
- {
- os << info->remoteAddress << ':' << info->remotePort;
- }
- else
+ if(_id.empty())
{
- os << "connection-" << _connection.get();
+ ostringstream os;
+ IPConnectionInfoPtr info = IPConnectionInfoPtr::dynamicCast(_connection->getInfo());
+ if(info)
+ {
+ os << info->remoteAddress << ':' << info->remotePort;
+ }
+ else
+ {
+ os << "connection-" << _connection.get();
+ }
+ _id = os.str();
}
- return os.str();
+ return _id;
}
string
@@ -500,7 +533,8 @@ public:
private:
- const ConnectionPtr _connection;
+ const ConnectionPtr& _connection;
+ mutable string _id;
};
RemoteInvocationHelper::Attributes RemoteInvocationHelper::attributes;
@@ -649,6 +683,7 @@ CommunicatorObserverI::CommunicatorObserverI(const MetricsAdminIPtr& metrics) :
{
_invocations.registerSubMap<Metrics>("Remote", &InvocationMetrics::remotes);
_metrics->updateViews();
+ updateObservers();
}
void
@@ -691,7 +726,11 @@ CommunicatorObserverI::getThreadObserver(const string& parent,
InvocationObserverPtr
CommunicatorObserverI::getInvocationObserver(const ObjectPrx& proxy, const string& op)
{
- return _invocations.getObserver(InvocationHelper(proxy, op));
+ if(_invocations.isEnabled())
+ {
+ return _invocations.getObserver(InvocationHelper(proxy, op));
+ }
+ return 0;
}
InvocationObserverPtr
@@ -705,3 +744,30 @@ CommunicatorObserverI::getDispatchObserver(const Current& current)
{
return _dispatch.getObserver(DispatchHelper(current));
}
+
+void
+CommunicatorObserverI::updateObservers()
+{
+ _connections.updateMaps();
+ _dispatch.updateMaps();
+ _invocations.updateMaps();
+ _threads.updateMaps();
+ _connects.updateMaps();
+ _endpointLookups.updateMaps();
+}
+
+void
+CommunicatorObserverI::updated(const PropertyDict& props)
+{
+ for(PropertyDict::const_iterator p = props.begin(); p != props.end(); ++p)
+ {
+ if(p->first.find("IceMX.") == 0)
+ {
+ // Udpate the metrics views using the new configuration and then update
+ // the maps associated to observers.
+ _metrics->updateViews();
+ updateObservers();
+ return;
+ }
+ }
+}
diff --git a/cpp/src/Ice/ObserverI.h b/cpp/src/Ice/ObserverI.h
index 62d1f75057c..9ce1712bc55 100644
--- a/cpp/src/Ice/ObserverI.h
+++ b/cpp/src/Ice/ObserverI.h
@@ -45,7 +45,8 @@ private:
};
-class CommunicatorObserverI : public Ice::Instrumentation::CommunicatorObserver
+class CommunicatorObserverI : public Ice::Instrumentation::CommunicatorObserver,
+ public Ice::PropertiesAdminUpdateCallback
{
public:
@@ -80,6 +81,9 @@ public:
private:
+ void updateObservers();
+ virtual void updated(const Ice::PropertyDict&);
+
const MetricsAdminIPtr _metrics;
ObserverFactoryT<ConnectionObserverI> _connections;
@@ -89,6 +93,7 @@ private:
ObserverFactoryT<ObserverI> _connects;
ObserverFactoryT<ObserverI> _endpointLookups;
};
+typedef IceUtil::Handle<CommunicatorObserverI> CommunicatorObserverIPtr;
};