Ejemplo n.º 1
0
class StoreOutput(Output):

    implements(IOutput, ISearchable)

    def __init__(self, plugin, name, fieldstore):
        self._plugin = plugin
        self.setName(name)
        self._fieldstore = fieldstore
        self._index = None
        self._contract = Contract().sign()

    def configure(self, section):
        self._indexName = section.getString("index name", self.name)
        if self._indexName in self._plugin._outputs:
            raise Exception("[output:%s] index '%s' is already open" % (self.name,self._indexName))
        self._plugin._outputs[self._indexName] = self
        self._segRotation = section.getInt("segment rotation policy", 0)
        self._segRetention = section.getInt("segment retention policy", 0)
        self._segOptimize = section.getBoolean("optimize segments", False)
        
    def startService(self):
        self._task = getUtility(IScheduler).addTask("output:%s" % self.name)
        self._index = Index(self)
        logger.debug("[output:%s] opened index '%s'" % (self.name,self._indexName))
        Output.startService(self)

    def stopService(self):
        if self._index != None:
            self._index.close()
        logger.debug("[output:%s] closed index '%s'" % (self.name,self._indexName))
        self._index = None
        return Output.stopService(self)

    def getContract(self):
        return self._contract

    def receiveEvent(self, event):
        # if the output is not running, discard any received events
        if not self.running:
            return
        # store the event in the index
        worker = self._task.addWorker(WriterWorker(event, self._index))
        # rotate the index segments if necessary
        d = worker.whenDone()
        d.addCallbacks(self._rotateSegments, self._writeError)
    
    def _rotateSegments(self, worker):
        logger.debug("[output:%s] wrote event to index" % self.name)
        try:
            self._index.rotateSegments(self._segRotation, self._segRetention)
        except Exception, e:
            logger.exception(e)
Ejemplo n.º 2
0
class StoreOutput(Output):

    implements(IOutput, ISearchable)

    def __init__(self, plugin, name, fieldstore):
        self._plugin = plugin
        self.setName(name)
        self._fieldstore = fieldstore
        self._index = None
        self._contract = Contract().sign()

    def configure(self, section):
        self._indexName = section.getString("index name", self.name)
        if self._indexName in self._plugin._outputs:
            raise Exception("[output:%s] index '%s' is already open" % (self.name,self._indexName))
        self._plugin._outputs[self._indexName] = self
        self._segRotation = section.getInt("segment rotation policy", 0)
        self._segRetention = section.getInt("segment retention policy", 0)
        self._segOptimize = section.getBoolean("optimize segments", False)
        
    def startService(self):
        self._index = Index(self._plugin._env, self._indexName, self._fieldstore)
        logger.debug("[output:%s] opened index '%s'" % (self.name,self._indexName))
        Output.startService(self)

    def stopService(self):
        if self._index != None:
            self._index.close()
        logger.debug("[output:%s] closed index '%s'" % (self.name,self._indexName))
        self._index = None
        return Output.stopService(self)

    def getContract(self):
        return self._contract

    def receiveEvent(self, event):
        # if the output is not running, discard any received events
        if not self.running:
            return
        # store the event in the index
        writeEventToIndex(event, self._index)
        # rotate the index segments if necessary
        self._index.rotateSegments(self._segRotation, self._segRetention)
    
    def getIndex(self):
        return self._index
Ejemplo n.º 3
0
 def startService(self):
     self._index = Index(self._plugin._env, self._indexName, self._fieldstore)
     logger.debug("[output:%s] opened index '%s'" % (self.name,self._indexName))
     Output.startService(self)
Ejemplo n.º 4
0
 def startService(self):
     self._task = getUtility(IScheduler).addTask("output:%s" % self.name)
     self._index = Index(self)
     logger.debug("[output:%s] opened index '%s'" % (self.name,self._indexName))
     Output.startService(self)