mirror of https://github.com/craigerl/aprsd.git
Fixed PacketList maxlen
This patch removes the MutableMapping from PacketList and fixes the code that keeps the max packets in the internal dict.
This commit is contained in:
parent
5fa4eaf909
commit
5ff62c9bdf
|
@ -1,5 +1,4 @@
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from collections.abc import MutableMapping
|
|
||||||
import logging
|
import logging
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
|
@ -14,7 +13,7 @@ CONF = cfg.CONF
|
||||||
LOG = logging.getLogger("APRSD")
|
LOG = logging.getLogger("APRSD")
|
||||||
|
|
||||||
|
|
||||||
class PacketList(MutableMapping, objectstore.ObjectStoreMixin):
|
class PacketList(objectstore.ObjectStoreMixin):
|
||||||
_instance = None
|
_instance = None
|
||||||
lock = threading.Lock()
|
lock = threading.Lock()
|
||||||
_total_rx: int = 0
|
_total_rx: int = 0
|
||||||
|
@ -57,10 +56,14 @@ class PacketList(MutableMapping, objectstore.ObjectStoreMixin):
|
||||||
self._add(packet)
|
self._add(packet)
|
||||||
|
|
||||||
def _add(self, packet):
|
def _add(self, packet):
|
||||||
|
if packet.key in self.data["packets"]:
|
||||||
|
self.data["packets"].move_to_end(packet.key)
|
||||||
|
elif len(self.data["packets"]) == self.maxlen:
|
||||||
|
self.data["packets"].popitem(last=False)
|
||||||
self.data["packets"][packet.key] = packet
|
self.data["packets"][packet.key] = packet
|
||||||
|
|
||||||
def copy(self):
|
def copy(self):
|
||||||
return self.d.copy()
|
return self.data.copy()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def maxlen(self):
|
def maxlen(self):
|
||||||
|
@ -68,24 +71,7 @@ class PacketList(MutableMapping, objectstore.ObjectStoreMixin):
|
||||||
|
|
||||||
@wrapt.synchronized(lock)
|
@wrapt.synchronized(lock)
|
||||||
def find(self, packet):
|
def find(self, packet):
|
||||||
return self.get(packet.key)
|
return self.data["packets"][packet.key]
|
||||||
|
|
||||||
def __getitem__(self, key):
|
|
||||||
# self.d.move_to_end(key)
|
|
||||||
return self.data["packets"][key]
|
|
||||||
|
|
||||||
def __setitem__(self, key, value):
|
|
||||||
if key in self.data["packets"]:
|
|
||||||
self.data["packets"].move_to_end(key)
|
|
||||||
elif len(self.data["packets"]) == self.maxlen:
|
|
||||||
self.data["packets"].popitem(last=False)
|
|
||||||
self.data["packets"][key] = value
|
|
||||||
|
|
||||||
def __delitem__(self, key):
|
|
||||||
del self.data["packets"][key]
|
|
||||||
|
|
||||||
def __iter__(self):
|
|
||||||
return self.data["packets"].__iter__()
|
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(self.data["packets"])
|
return len(self.data["packets"])
|
||||||
|
|
Loading…
Reference in New Issue