Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
Archetypes.AggregatedStorage.AggregatedStorage Class Reference
Inheritance diagram for Archetypes.AggregatedStorage.AggregatedStorage:
Inheritance graph
[legend]
Collaboration diagram for Archetypes.AggregatedStorage.AggregatedStorage:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def __getstate__
def __setstate__
def registerAggregator
def registerDisaggregator
def get
def set
def unset

Public Attributes

 cache

Private Member Functions

def _cache_get
 A very basic cache implementation to cache the result dictionaries returned by the aggregators.
def _cache_put
def _cache_remove

Private Attributes

 _reg_ag
 _reg_dag
 _caching
 _lock

Detailed Description

Implementation of the AggregatedStorage proposal as described in http://plone.org/development/teams/developer/AggregatedStorage 

Definition at line 20 of file AggregatedStorage.py.


Constructor & Destructor Documentation

Definition at line 23 of file AggregatedStorage.py.

00023 
00024     def __init__(self, caching=0):
00025         self._reg_ag = Registry(StringType)  # registry for aggregators
00026         self._reg_dag = Registry(StringType) # registry for disaggregators
00027         self.cache = {}                      # map (objId, aggregator) -> (timestamp, result_dict)
00028         self._caching = caching
00029         self._lock = Lock()
        

Here is the caller graph for this function:


Member Function Documentation

Override __getstate__ used for copy operations

Required to fix the copy problem with the lock

Definition at line 30 of file AggregatedStorage.py.

00030 
00031     def __getstate__(self):
00032         """Override __getstate__ used for copy operations
00033         
00034         Required to fix the copy problem with the lock
00035         """
00036         state = self.__dict__
00037         state['_lock'] = None
00038         return state

Override __setstate__ used for copy operations

Required to fix the copy problem with the lock

Definition at line 39 of file AggregatedStorage.py.

00039 
00040     def __setstate__(self, state):
00041         """Override __setstate__ used for copy operations
00042         
00043         Required to fix the copy problem with the lock
00044         """
00045         state['_lock'] = Lock()
00046         self.__dict__.update(state)

def Archetypes.AggregatedStorage.AggregatedStorage._cache_get (   self,
  objId,
  methodname 
) [private]

A very basic cache implementation to cache the result dictionaries returned by the aggregators.

retrieve the result dictionary for (objId, methodname) 

Definition at line 114 of file AggregatedStorage.py.

00114 
00115     def _cache_get(self, objId, methodname):
00116         """ retrieve the result dictionary for (objId, methodname) """
00117         self._lock.acquire()
00118         entry = self.cache.get((objId, methodname))
00119         if entry is None: 
00120             self._lock.release()
00121             return None
00122         if time.time() - entry[0] > CACHE_TIMEOUT: 
00123             del self.cache[(objId, methodname)]
00124             self._lock.release()
00125             return None
00126         self._lock.release()
00127         return entry[1]

Here is the caller graph for this function:

def Archetypes.AggregatedStorage.AggregatedStorage._cache_put (   self,
  objId,
  methodname,
  result 
) [private]
store (objId, methodname) : (current_time, result) in cache 

Definition at line 128 of file AggregatedStorage.py.

00128 
00129     def _cache_put(self, objId, methodname, result):
00130         """ store (objId, methodname) : (current_time, result) in cache """
00131         self._lock.acquire()
00132         self.cache[(objId, methodname)] = (time.time(), result)
00133         self._lock.release()

Here is the caller graph for this function:

def Archetypes.AggregatedStorage.AggregatedStorage._cache_remove (   self,
  objId,
  methodname 
) [private]
remove (objId, methodname) from cache 

Definition at line 134 of file AggregatedStorage.py.

00134 
00135     def _cache_remove(self, objId, methodname):
00136         """ remove (objId, methodname) from cache """
00137         
00138         self._lock.acquire()
00139         key = (objId, methodname)
00140         if self.cache.has_key(key):
00141             del self.cache[key] 
00142         self._lock.release()

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.AggregatedStorage.AggregatedStorage.get (   self,
  name,
  instance,
  kwargs 
)

Definition at line 58 of file AggregatedStorage.py.

00058 
00059     def get(self, name, instance, **kwargs):
00060         methodname = self._reg_ag.get(name)
00061         if not methodname:
00062             raise KeyError('No aggregator registered for field "%s"' % name)
00063         method = getattr(instance, methodname)
00064         if not method:
00065             raise KeyError('Aggregator "%s" for field "%s" not found' % (methodname, name))
00066         result = method(name, instance, **kwargs)
00067         if not isinstance(result, DictType):
00068             raise TypeError('Result returned from an aggregator must be DictType')
00069         return result[name]
00070 
00071         if self._caching:
00072             cache_entry = self._cache_get(instance.getId(), methodname)
00073         else:
00074             cache_entry = None
00075 
00076         if cache_entry is None:
00077             method = getattr(instance, methodname)
00078             if not method:
00079                 raise KeyError('Aggregator "%s" for field "%s" not found' % (methodname, name))
00080             result = method(name, instance, **kwargs)
00081             if not isinstance(result, DictType):
00082                 raise TypeError('Result returned from an aggregator must be DictType')
00083 
00084             if self._caching:
00085                 self._cache_put(instance.getId(), methodname, result)
00086 
00087             if not result.has_key(name):
00088                 raise KeyError('result dictionary returned from "%s"'
00089                                ' does not contain an key for "%s"' % 
00090                                (methodname, name))
00091             return result[name]
00092         else:
00093             return cache_entry[name]
        

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.AggregatedStorage.AggregatedStorage.registerAggregator (   self,
  fieldname,
  methodname 
)

Definition at line 47 of file AggregatedStorage.py.

00047 
00048     def registerAggregator(self, fieldname, methodname):
00049         if self._reg_ag.get(fieldname):
00050             raise KeyError('Aggregator for field "%s" already registered' % fieldname)
00051         self._reg_ag.register(fieldname, methodname)
00052 

def Archetypes.AggregatedStorage.AggregatedStorage.registerDisaggregator (   self,
  fieldname,
  methodname 
)

Definition at line 53 of file AggregatedStorage.py.

00053 
00054     def registerDisaggregator(self, fieldname, methodname):
00055         if self._reg_dag.get(fieldname):
00056             raise KeyError('Disaggregator for field "%s" already registered' % fieldname)
00057         self._reg_dag.register(fieldname, methodname)

def Archetypes.AggregatedStorage.AggregatedStorage.set (   self,
  name,
  instance,
  value,
  kwargs 
)

Definition at line 94 of file AggregatedStorage.py.

00094 
00095     def set(self, name, instance, value, **kwargs):
00096         methodname = self._reg_dag.get(name)
00097         if not methodname:
00098             raise KeyError('No disaggregator registered for field "%s"' % name)
00099 
00100         method = getattr(instance, methodname)
00101         if not method:
00102             raise KeyError('Disaggregator "%s" for field "%s" not found' % (methodname, name))
00103         if self._caching:
00104             self._cache_remove(instance.getId(), methodname)
00105         method(name, instance, value, **kwargs)

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.AggregatedStorage.AggregatedStorage.unset (   self,
  name,
  instance,
  kwargs 
)

Definition at line 106 of file AggregatedStorage.py.

00106 
00107     def unset(self, name, instance, **kwargs):
00108         pass


Member Data Documentation

Definition at line 27 of file AggregatedStorage.py.

Definition at line 28 of file AggregatedStorage.py.

Definition at line 24 of file AggregatedStorage.py.

Definition at line 25 of file AggregatedStorage.py.

Definition at line 26 of file AggregatedStorage.py.


The documentation for this class was generated from the following file: