summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/Ice/MetricsAdminI.cpp108
-rw-r--r--cpp/src/Ice/MetricsAdminI.h42
2 files changed, 70 insertions, 80 deletions
diff --git a/cpp/src/Ice/MetricsAdminI.cpp b/cpp/src/Ice/MetricsAdminI.cpp
index 9cf34111335..30f59eed52a 100644
--- a/cpp/src/Ice/MetricsAdminI.cpp
+++ b/cpp/src/Ice/MetricsAdminI.cpp
@@ -23,24 +23,52 @@ using namespace IceMX;
namespace
{
-NameValueDict
+vector<MetricsMapI::RegExpPtr>
parseRule(const ::Ice::PropertiesPtr& properties, const string& name)
{
- NameValueDict dict;
+ vector<MetricsMapI::RegExpPtr> regexps;
PropertyDict rules = properties->getPropertiesForPrefix(name + '.');
for(PropertyDict::const_iterator p = rules.begin(); p != rules.end(); ++p)
{
- dict.insert(make_pair(p->first.substr(name.size() + 1), p->second));
+ regexps.push_back(new MetricsMapI::RegExp(p->first.substr(name.length() + 1), p->second));
}
- return dict;
+ return regexps;
}
-bool
-match(const string& value, const string& expr)
+}
+
+MetricsMapI::RegExp::RegExp(const string& attribute, const string& regexp) : _attribute(attribute)
{
- return true; // TODO
+#ifndef ICE_CPP11_REGEXP
+ if(regcomp(&_preg, regexp.c_str(), REG_EXTENDED | REG_NOSUB) != 0)
+ {
+ throw Ice::SyscallException(__FILE__, __LINE__);
+ }
+#else
+ _regex = regex(regexp, std::regex_constants::extended | std::regex_constants::nosubs);
+#endif
}
+MetricsMapI::RegExp::~RegExp()
+{
+#ifndef ICE_CPP11_REGEXP
+ regfree(&_preg);
+#endif
+}
+
+bool
+MetricsMapI::RegExp::match(const MetricsHelper& helper)
+{
+ string value = helper(_attribute);
+#ifndef ICE_CPP11_REGEXP
+ if(regexec(&_preg, value.c_str(), 0, 0, 0) == 0)
+ {
+ return true;
+ }
+ return false;
+#else
+ return regex_match(value, _regex);
+#endif
}
MetricsMapI::MetricsMapI(const std::string& mapPrefix, const Ice::PropertiesPtr& properties) :
@@ -132,17 +160,17 @@ MetricsMapI::getFailures()
MetricsMapI::EntryPtr
MetricsMapI::getMatching(const MetricsHelper& helper)
{
- for(map<string, string>::const_iterator p = _accept.begin(); p != _accept.end(); ++p)
+ for(vector<RegExpPtr>::const_iterator p = _accept.begin(); p != _accept.end(); ++p)
{
- if(!match(helper(p->first), p->second))
+ if(!(*p)->match(helper))
{
return 0;
}
}
- for(map<string, string>::const_iterator p = _reject.begin(); p != _reject.end(); ++p)
+ for(vector<RegExpPtr>::const_iterator p = _reject.begin(); p != _reject.end(); ++p)
{
- if(match(helper(p->first), p->second))
+ if((*p)->match(helper))
{
return 0;
}
@@ -380,61 +408,3 @@ MetricsAdminI::getMetricsFailures(const string& view, const string& map, const :
}
return p->second->getFailures(map);
}
-
-void
-MetricsAdminI::addMapToView(const string& view,
- const string& mapName,
- const string& groupBy,
- int retain,
- const NameValueDict& accept,
- const NameValueDict& reject,
- const ::Ice::Current&)
-{
- UpdaterPtr updater;
- {
- // TODO: XXX
- // Lock sync(*this);
- // map<string, MetricsViewIPtr>::const_iterator p = _views.find(view);
- // if(p == _views.end())
- // {
- // p = _views.insert(make_pair(view, new MetricsViewI(true))).first;
- // }
- // p->second->add(mapName, _factories[mapName]->create());
-
- // map<string, UpdaterPtr>::const_iterator q = _updaters.find(mapName);
- // if(q != _updaters.end())
- // {
- // updater = q->second;
- // }
- }
- if(updater)
- {
- updater->update();
- }
-}
-
-void
-MetricsAdminI::removeMapFromView(const string& view, const string& mapName, const ::Ice::Current&)
-{
- UpdaterPtr updater;
- {
- Lock sync(*this);
- map<string, MetricsViewIPtr>::const_iterator p = _views.find(view);
- if(p == _views.end())
- {
- throw UnknownMetricsView();
- }
- p->second->remove(mapName);
-
- map<string, UpdaterPtr>::const_iterator q = _updaters.find(mapName);
- if(q != _updaters.end())
- {
- updater = q->second;
- }
- }
- if(updater)
- {
- updater->update();
- }
-}
-
diff --git a/cpp/src/Ice/MetricsAdminI.h b/cpp/src/Ice/MetricsAdminI.h
index 3cf635b41a0..8609dc6a42f 100644
--- a/cpp/src/Ice/MetricsAdminI.h
+++ b/cpp/src/Ice/MetricsAdminI.h
@@ -14,6 +14,16 @@
#include <Ice/Properties.h>
#include <Ice/Initialize.h>
+#ifdef _MSC_VER
+# define ICE_CPP11_REGEXP
+#endif
+
+#ifdef ICE_CPP11_REGEXP
+# include <regex>
+#else
+# include <regex.h>
+#endif
+
namespace IceMX
{
@@ -23,12 +33,29 @@ typedef IceUtil::Handle<Updater> UpdaterPtr;
class MetricsHelper;
template<typename T> class MetricsHelperT;
-typedef std::map<std::string, std::string> NameValueDict;
-
class MetricsMapI : public IceUtil::Shared, public IceUtil::Mutex
{
public:
+ class RegExp : public IceUtil::Shared
+ {
+ public:
+
+ RegExp(const std::string&, const std::string&);
+ ~RegExp();
+
+ bool match(const MetricsHelper&);
+
+ private:
+ const std::string _attribute;
+#ifdef ICE_CPP11_REGEXP
+ std::regex _regex;
+#else
+ regex_t _preg;
+#endif
+ };
+ typedef IceUtil::Handle<RegExp> RegExpPtr;
+
class Entry : public Ice::LocalObject, public IceUtil::Mutex
{
public:
@@ -149,8 +176,8 @@ private:
std::vector<std::string> _groupByAttributes;
std::vector<std::string> _groupBySeparators;
const int _retain;
- const NameValueDict _accept;
- const NameValueDict _reject;
+ const std::vector<RegExpPtr> _accept;
+ const std::vector<RegExpPtr> _reject;
std::map<std::string, EntryPtr> _objects;
std::deque<Entry*> _detachedQueue;
@@ -308,13 +335,6 @@ public:
private:
- virtual void addMapToView(const std::string&, const std::string&, const std::string&, int, const NameValueDict&,
- const NameValueDict&, const ::Ice::Current& = ::Ice::Current());
-
- virtual void removeMapFromView(const std::string&, const std::string&, const ::Ice::Current&);
-
- void setViewEnabled(const std::string&, bool);
-
std::map<std::string, MetricsViewIPtr> _views;
std::map<std::string, UpdaterPtr> _updaters;
std::map<std::string, MetricsMapFactoryPtr> _factories;