10 from __future__
import division, absolute_import, print_function, unicode_literals
12 from logging
import getLogger
17 collections_abc = collections.abc
18 except AttributeError:
19 collections_abc = collections
22 logger = getLogger(__name__)
26 """This class keeps the latest TransferEvent of a given message type categorized by specified key.
27 The stored items can be automatically removed if they were not updated in a specified time interval.
29 Defaults are as follows:
30 - Categorization key: source node ID
31 - Entry timeout: infinite
34 def __init__(self, node, data_type, key=None, timeout=None):
36 :param node: Node instance.
38 :param data_type: Data type to subscribe to.
40 :param key: A callable that accepts a TransferEvent instance and returns a hashable.
41 The returned hashable will be used as categorization key.
42 If this argument is not provided, the messages will be categorized by source node ID.
44 :param timeout: Entry timeout. If an entry was not updated in this time, it will be removed.
45 By default entry lifetime is not limited.
57 if (self.
_storage[key].transfer.ts_monotonic + self.
_timeout) < time.monotonic():
62 for x
in list(self.
_storage.keys())[:]: