def get_result(self, skipCache=0, **keywords): if not skipCache: dt = now() - self.__cached_result.timestamp if dt > self.__cache_ttl: skipCache = 1 if skipCache: value = self.__agent.snmp_get(self.__var_name)[1] result = Result(value, now(), 0, self.__cached_result.changes+1) self.__cached_result = Result(result.value, result.timestamp, 1, result.changes) return result return self.__cached_result
def _set(self, value, asyncOK=0): self.__cached_result = Result(None, 0, 0, 0) if not isinstance(value, base.Asn1Item): asn1_value = self.__smi.syntax.clone(value) else: asn1_value = value self.__agent.snmp_set(self.__var_name, asn1_value) return
def get_batch(self): timestamp = now() if timestamp >= self.expires_at: results = {} for oid, value in self.agent.snmp_get_multiple(*self.oid_list): result = Result(value, timestamp, 0) sm_key = self.batch_map[oid].sm_key results[sm_key] = result self.results = results self.expires_at = timestamp + self.ttl return self.results
def update_value(self, value): if self._cached_result: previous = self._cached_result.value if value == previous: return False changes = self._cached_result.changes + 1 else: changes = 1 previous = None self._cached_result = Result(value, uptime.secs(), 1, changes) self._trigger_cov(previous, value, time.time()) return True
def as_result(value): if isinstance(value, Exception): value = error_dictionary(value) if isinstance(value, dict): if value.has_key('edt__typ'): value = edtlib.edt_decode(value) elif (value.get('__base__') == 'Result' or all(value.has_key(key) for key in ["cached", "changes", "timestamp", "value"])): value = Result.from_dict(value) if not isinstance(value, Result): msglog.log("broadway", msglog.types.WARN, "Unable to convert %r to Result." % (value,)) return value
def update(self, msg): self._last_rcvd = uptime.secs() if self._cached_result is None: change_count = 1 last_value = None else: change_count = self._cached_result.changes + 1 last_value = self._cached_result.value if isinstance(msg, Exception): value = msg else: value = getattr(msg, self.prop_name) self._cached_result = Result(value, time.time(), changes=change_count) self._trigger_cov(last_value)
def __init__(self, parent=None, info=None): super(ScalarInstance, self).__init__() self.__cache_ttl = -1 self.__agent = None self.__smi = None self.__var_name = None # By using a valid, but expired __cached_result the number of checks # can be reduced. self.__cached_result = Result(None, 0, 0, 0) self.index = REQUIRED # Both parent and info must be None, or both must NOT be None assert (parent is None) == (info is None) if parent is not None: self.__cfg_from_info(parent, info) return
def update(self, value): ts = time.time() if self._last_result is None: last_ts = ts changes = 0 else: last_ts = self._last_result.timestamp changes = self._last_result.changes if not isinstance(value, Exception): # we've found that different servers # ie. pg&e vs sce, despite sharing wsdl's # have different return values. :( value = self._get_value(value) self._last_result = Result(value, ts, 0, changes) return
def update_cache(self): self.updated(True) fwstatus = self.fw_node.get() netstatus = int(bool(self.net_node.get())) value = {"net": netstatus, "framework": fwstatus} if self._cached_result: previous = self._cached_result.value if value == previous: return changes = self._cached_result.changes + 1 else: changes = 1 previous = None self._cached_result = Result(value, self.refreshed(), 1, changes) event = ChangeOfValueEvent(self, previous, value, time.time()) self.event_generate(event) self.state_changed(True)
def update_cache(self, value): now = uptime.secs() if isinstance(value, ValueObj): value = value.get(self.prop_name) if value is None or isinstance(value, Exception): value = ETimeout() if value != self._cached_value: if self.event_has_subscribers(): self._trigger_cov(self._cached_value, value, time.time()) self._cached_value = value if self._cached_result is None: changes = 0 else: changes = self._cached_result.changes + 1 self._cached_result = Result(self._cached_value, self._last_rcvd, changes) self._last_rcvd = now return
def update(self, result): if not isinstance(result, Result): if isinstance(result, dict): result = Result.from_dict(result) else: message = "update() expects Result instance, not: %r" raise ValueError(message % result) self.synclock.acquire() try: if self.initialized(): previous = self.get_value() else: previous = None self.result = result value = self.get_value() self.updated = uptime.secs() finally: self.synclock.release() if self.support_cov: self.event_generate(COVEvent(self, previous, value, time.time())) if self.debug: msglog.debug("%s updated: %r" % (self, result))
def get_result(self, skipCache=False): return Result(self.get(skipCache), time.time(), cached=False)
def get_result(self, skipCache=0, **keywords): return Result(self.get(), time.time())
def get_result(self, skipCache=0): return Result(self.get(), time.time(), 0, 0)
def as_result(self): answer = self.value if not isinstance(answer, Result): answer = Result(answer, self.timestamp) return answer
def _update_cached_value(self, value): self.__cached_result = Result(value, now(), 1, self.__cached_result.changes+1) return
def _reset_result(self): result = Result({"net": None, "framework": None}, 0, 1, 0) self.last_update = 0 self.last_refresh = 0 self._cached_result = result