*** empty log message ***

This commit is contained in:
Jesse Schell 2001-03-21 17:29:27 +00:00
parent 3a1b23c391
commit 7cb262f959
3 changed files with 84 additions and 73 deletions

View File

@ -1,70 +1,70 @@
"""CRCache module: contains the CRCache class"""
import DirectNotifyGlobal
import DistributedObject
class CRCache:
notify = DirectNotifyGlobal.directNotify.newCategory("CRCache")
def __init__(self, maxCacheItems=50):
self.maxCacheItems = maxCacheItems
self.dict = {}
self.fifo = []
return None
def cache(self, distObj):
# Only distributed objects are allowed in the cache
assert(isinstance(distObj, DistributedObject.DistributedObject))
# Get the doId
doId = distObj.getDoId()
# Error check
if self.dict.has_key(doId):
CRCache.notify.warning("Double cache attempted for distObj "
+ str(doId))
else:
# Call disable on the distObj
distObj.disable()
# Put the distObj in the fifo and the dict
self.fifo.append(distObj)
self.dict[doId] = distObj
if len(self.fifo) > self.maxCacheItems:
# if the cache is full, pop the oldest item
oldestDistObj = self.fifo.pop(0)
# and remove it from the dictionary
del(self.dict[oldestDistObj.getDoId()])
# and delete it
oldestDistObj.delete()
# Make sure that the fifo and the dictionary are sane
assert(len(self.dict) == len(self.fifo))
return None
def retrieve(self, doId):
if self.dict.has_key(doId):
# Find the object
distObj = self.dict[doId]
# Remove it from the dictionary
del(self.dict[doId])
# Remove it from the fifo
self.fifo.remove(distObj)
# return the distObj
return distObj
else:
# If you can't find it, return None
return None
def contains(self, doId):
return self.dict.has_key(doId)
def delete(self, doId):
assert(self.dict.has_key(doId))
# Look it up
distObj = self.dict[doId]
# Remove it from the dict and fifo
del(self.dict[doId])
self.fifo.remove(distObj)
# and delete it
oldestDistObj.delete()
"""CRCache module: contains the CRCache class"""
import DirectNotifyGlobal
import DistributedObject
class CRCache:
notify = DirectNotifyGlobal.directNotify.newCategory("CRCache")
def __init__(self, maxCacheItems=50):
self.maxCacheItems = maxCacheItems
self.dict = {}
self.fifo = []
return None
def cache(self, distObj):
# Only distributed objects are allowed in the cache
assert(isinstance(distObj, DistributedObject.DistributedObject))
# Get the doId
doId = distObj.getDoId()
# Error check
if self.dict.has_key(doId):
CRCache.notify.warning("Double cache attempted for distObj "
+ str(doId))
else:
# Call disable on the distObj
distObj.disableAndAnnounce()
# Put the distObj in the fifo and the dict
self.fifo.append(distObj)
self.dict[doId] = distObj
if len(self.fifo) > self.maxCacheItems:
# if the cache is full, pop the oldest item
oldestDistObj = self.fifo.pop(0)
# and remove it from the dictionary
del(self.dict[oldestDistObj.getDoId()])
# and delete it
oldestDistObj.delete()
# Make sure that the fifo and the dictionary are sane
assert(len(self.dict) == len(self.fifo))
return None
def retrieve(self, doId):
if self.dict.has_key(doId):
# Find the object
distObj = self.dict[doId]
# Remove it from the dictionary
del(self.dict[doId])
# Remove it from the fifo
self.fifo.remove(distObj)
# return the distObj
return distObj
else:
# If you can't find it, return None
return None
def contains(self, doId):
return self.dict.has_key(doId)
def delete(self, doId):
assert(self.dict.has_key(doId))
# Look it up
distObj = self.dict[doId]
# Remove it from the dict and fifo
del(self.dict[doId])
self.fifo.remove(distObj)
# and delete it
oldestDistObj.delete()

View File

@ -202,7 +202,6 @@ class ClientRepository(DirectObject.DirectObject):
doId = di.getArg(STUint32)
# disable it.
self.disableDoId(doId)
return None
def disableDoId(self, doId):
@ -233,8 +232,9 @@ class ClientRepository(DirectObject.DirectObject):
del(self.doId2cdc[doId])
# Sanity check the dictionaries
assert(len(self.doId2do) == len(self.doId2cdc))
# Disable and Delete the object itself
obj.disable()
# Disable the object itself
obj.disableAndAnnounce()
# Delete the object itself
obj.delete()
# If it is in the cache, remove it.
elif self.cache.contains(doId):

View File

@ -24,6 +24,14 @@ class DistributedObject(PandaObject):
def getNeverDisable(self):
return self.neverDisable
def disableAndAnnounce(self):
"""disableAndAnnounce(self)
Inheritors should *not* redefine this function.
"""
self.disable()
messenger.send(self.uniqueName("disable"))
return None
def disable(self):
"""disable(self)
Inheritors should redefine this to take appropriate action on disable
@ -73,5 +81,8 @@ class DistributedObject(PandaObject):
def taskName(self, taskString):
return (taskString + "-" + str(self.getDoId()))
def uniqueName(self, idString):
return (idString + "-" + str(self.getDoId()))