def disable(self):
"""disables incrementing/decrementing counters"""
- self._disabled = True
+ with self._rlock:
+ self._disabled = True
def enable(self):
"""enables incrementing/decrementing counters"""
- self._disabled = False
+ with self._rlock:
+ self._disabled = False
def inc(self, *args):
"""A incrementer for per-zone counter. Locks the thread
file."""
identifier = '/'.join(args)
step = 1
- if self._disabled: return
with self._rlock:
+ if self._disabled: return
_inc_counter(self._statistics._data,
self._statistics._spec,
identifier, step)
file."""
identifier = '/'.join(args)
step = -1
- if self._disabled: return
with self._rlock:
+ if self._disabled: return
_inc_counter(self._statistics._data,
self._statistics._spec,
identifier, step)
"""Sets the value returned from _start_timer() as a value of
the identifier in the self._start_time which is dict-type"""
identifier = '/'.join(args)
- isc.cc.data.set(self._start_time, identifier, _start_timer())
+ with self._rlock:
+ if self._disabled: return
+ isc.cc.data.set(self._start_time, identifier, _start_timer())
def stop(self, *args):
"""Sets duration time between corresponding time in
nothing. But in case of stopping the time which isn't defined
in the spec file, it raises DataNotFoundError"""
identifier = '/'.join(args)
- try:
- start_time = isc.cc.data.find(self._start_time,
- identifier)
- except isc.cc.data.DataNotFoundError:
- # do not set the end time if the timer isn't started
- pass
- else:
- # set the end time
- _stop_timer(
- start_time,
- self._statistics._data,
- self._statistics._spec,
- identifier)
- # delete the started timer
- del isc.cc.data.find(
- self._start_time,
- '/'.join(identifier.split('/')[0:-1]))\
- [identifier.split('/')[-1]]
+ with self._rlock:
+ if self._disabled: return
+ try:
+ start_time = isc.cc.data.find(self._start_time,
+ identifier)
+ except isc.cc.data.DataNotFoundError:
+ # do not set the end time if the timer isn't started
+ pass
+ else:
+ # set the end time
+ _stop_timer(
+ start_time,
+ self._statistics._data,
+ self._statistics._spec,
+ identifier)
+ # delete the started timer
+ del isc.cc.data.find(
+ self._start_time,
+ '/'.join(identifier.split('/')[0:-1]))\
+ [identifier.split('/')[-1]]
def dump_statistics(self):
"""Calculates an entire server counts, and returns statistics