summaryrefslogtreecommitdiffstats
path: root/Monitoring/src/main/python/DataProcessing/DataSource.py
diff options
context:
space:
mode:
authorpikusa <pikusa@man.poznan.pl>2013-04-03 13:18:17 (GMT)
committer pikusa <pikusa@man.poznan.pl>2013-04-03 13:18:17 (GMT)
commit2f2a3a129c91de540e66c3bfbe30b0df1942cd4b (patch)
tree2d313cdf0068af368d4de6067d676be16f6a6464 /Monitoring/src/main/python/DataProcessing/DataSource.py
parentff8aa232b071a9b54dff833714a870fd0aec0b30 (diff)
downloadnovi-public-2f2a3a129c91de540e66c3bfbe30b0df1942cd4b.zip
novi-public-2f2a3a129c91de540e66c3bfbe30b0df1942cd4b.tar.gz
novi-public-2f2a3a129c91de540e66c3bfbe30b0df1942cd4b.tar.bz2
project commit and dir tree change
Diffstat (limited to 'Monitoring/src/main/python/DataProcessing/DataSource.py')
-rw-r--r--Monitoring/src/main/python/DataProcessing/DataSource.py96
1 files changed, 96 insertions, 0 deletions
diff --git a/Monitoring/src/main/python/DataProcessing/DataSource.py b/Monitoring/src/main/python/DataProcessing/DataSource.py
new file mode 100644
index 0000000..0c66226
--- /dev/null
+++ b/Monitoring/src/main/python/DataProcessing/DataSource.py
@@ -0,0 +1,96 @@
+'''
+Created on Dec 10, 2012
+
+@author: steger
+'''
+from DataProcessing.DataHeader import DataError
+from DataProcessing.DataError import SamplerError
+
+class DataSource(object):
+ def __init__(self, datasource):
+ self._readers = set()
+ self._source = datasource
+ self._data = None
+ self.um = datasource.um
+
+ def _get_source(self):
+ return self._source
+
+ def _get_data(self):
+ self.process()
+ return self._data
+
+ def _get_name(self):
+ raise DataError("%s must implement name property" % self)
+
+ def _get_readlock(self):
+ return self.source.readlock
+
+ def _get_writelock(self):
+ return self.source.writelock
+
+ def __len__(self):
+ raise DataError("%s must implement __len__ method" % self)
+
+ def __getitem__(self, k):
+ raise DataError("%s must implement __getitem__ method" % self)
+
+ def process(self):
+ '''
+ @summary: recursively process data records of the source chain
+ '''
+ if self != self.source:
+ self.source.process()
+ self._process()
+
+ def _process(self):
+ raise DataError("%s must implement _process method" % self)
+
+ def _onclear(self):
+ for r in self._readers:
+ r.sourcecleared()
+
+ def _onexpand(self):
+ for r in self._readers:
+ r.sourceexpanded()
+
+ def registerReader(self, reader):
+ '''
+ @summary: registers a reader to catch clear and update events
+ @param reader: data consumer
+ @type reader: DataReader
+ @raise DataError: wrong argument
+ '''
+ try:
+ self._readers.add(reader)
+ try:
+ if len(self):
+ self._onexpand()
+ else:
+ self._onclear()
+ except SamplerError:
+ pass
+ except AttributeError:
+ self._readers.remove(reader)
+ raise DataError("Expecting a DataReader, got %s" % reader)
+
+ def deregisterReader(self, reader):
+ '''
+ @summary: removes a registered reader
+ @param reader: data consumer
+ @type reader: DataReader
+ '''
+ try:
+ self._readers.remove(reader)
+ except KeyError:
+ pass
+
+ readlock = property(_get_readlock,None,None)
+
+ source = property(_get_source,None,None)
+
+ data = property(_get_data,None,None)
+
+ name = property(_get_name,None,None)
+
+ writelock = property(_get_writelock,None,None)