summaryrefslogtreecommitdiff
path: root/kafka/metrics/quota.py
diff options
context:
space:
mode:
authorZack Dever <zackdever@gmail.com>2016-04-14 11:02:01 -0700
committerZack Dever <zackdever@gmail.com>2016-04-14 11:02:01 -0700
commitcf679ae387519f658f17b2da2d05ff84834cb1f5 (patch)
tree5618627ab6919b6fd4cd476e801c0f9bf449d716 /kafka/metrics/quota.py
parent0c94b83a2dff8113b5fd7c16df8a11ca03c4377b (diff)
parente2b340c4408801515f5e924aec066af983aa5c57 (diff)
downloadkafka-python-cf679ae387519f658f17b2da2d05ff84834cb1f5.tar.gz
Merge pull request #637 from zackdever/metrics
Metrics java port
Diffstat (limited to 'kafka/metrics/quota.py')
-rw-r--r--kafka/metrics/quota.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/kafka/metrics/quota.py b/kafka/metrics/quota.py
new file mode 100644
index 0000000..0410e37
--- /dev/null
+++ b/kafka/metrics/quota.py
@@ -0,0 +1,39 @@
+class Quota(object):
+ """An upper or lower bound for metrics"""
+ def __init__(self, bound, is_upper):
+ self._bound = bound
+ self._upper = is_upper
+
+ @staticmethod
+ def upper_bound(upper_bound):
+ return Quota(upper_bound, True)
+
+ @staticmethod
+ def lower_bound(lower_bound):
+ return Quota(lower_bound, False)
+
+ def is_upper_bound(self):
+ return self._upper
+
+ @property
+ def bound(self):
+ return self._bound
+
+ def is_acceptable(self, value):
+ return ((self.is_upper_bound() and value <= self.bound) or
+ (not self.is_upper_bound() and value >= self.bound))
+
+ def __hash__(self):
+ prime = 31
+ result = prime + self.bound
+ return prime * result + self.is_upper_bound()
+
+ def __eq__(self, other):
+ if self is other:
+ return True
+ return (type(self) == type(other) and
+ self.bound == other.bound and
+ self.is_upper_bound() == other.is_upper_bound())
+
+ def __ne__(self, other):
+ return not self.__eq__(other)