def add_object(self, data):
"""
Attempt to insert a data object into the store. If it does not exist, it gets initialized. Otherwise the
statistics are updated by increasing the receive count and the time of the last reception if the message has
not been flagged as deleted.
:param data: data object to store
"""
idx = hash_string(data)
now = int(time.time())
with self.lock:
Stats = Query()
res = self.stats.search(Stats.idx == idx)
if len(res) == 0:
self.data.insert({'idx': idx, 'content': data})
self.stats.insert({'idx': idx,
'first_seen': now,
'receive_count': 0,
'send_count': 0,
'last_received': None,
'last_sent': None,
'deleted': False})
log_debug("Data object created: {}".format(data))
else:
deleted = res[0]['deleted']
if deleted:
log_debug("Received deleted data object: {}".format(data))
self.stats.update({'last_received': now}, Stats.idx == idx)
self.stats.update(increment('receive_count'), Stats.idx == idx)
log_debug("Data object updated: {}".format(data))
评论列表
文章目录