当前位置: 首页>>代码示例>>Python>>正文


Python EventBus.link方法代码示例

本文整理汇总了Python中synapse.eventbus.EventBus.link方法的典型用法代码示例。如果您正苦于以下问题:Python EventBus.link方法的具体用法?Python EventBus.link怎么用?Python EventBus.link使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在synapse.eventbus.EventBus的用法示例。


在下文中一共展示了EventBus.link方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Cortex

# 需要导入模块: from synapse.eventbus import EventBus [as 别名]
# 或者: from synapse.eventbus.EventBus import link [as 别名]
class Cortex(EventBus):
    '''
    Top level Cortex key/valu storage object.
    '''
    def __init__(self, link, model=None):
        EventBus.__init__(self)

        self.link = link

        self.lock = threading.Lock()
        self.statfuncs = {}

        self.model = model
        self.sizebymeths = {}
        self.rowsbymeths = {}

        self.savebus = EventBus()
        self.loadbus = EventBus()

        self.loadbus.on('core:save:add:rows', self._loadAddRows)

        self.loadbus.on('core:save:del:rows:by:iden', self._loadDelRowsById)
        self.loadbus.on('core:save:del:rows:by:prop', self._loadDelRowsByProp)

        self.loadbus.on('core:save:set:rows:by:idprop', self._loadSetRowsByIdProp)
        self.loadbus.on('core:save:del:rows:by:idprop', self._loadDelRowsByIdProp)

        self.onfini( self.savebus.fini )
        self.onfini( self.loadbus.fini )

        self.addStatFunc('any',self._calcStatAny)
        self.addStatFunc('all',self._calcStatAll)
        self.addStatFunc('min',self._calcStatMin)
        self.addStatFunc('max',self._calcStatMax)
        self.addStatFunc('sum',self._calcStatSum)
        self.addStatFunc('count',self._calcStatCount)
        self.addStatFunc('histo',self._calcStatHisto)
        self.addStatFunc('average',self._calcStatAverage)

        self._initCortex()

        self.isok = True

    def setSaveFd(self, fd, load=True):
        '''
        Set a save fd for the cortex and optionally load.

        Example:

            core.setSaveFd(fd)

        '''
        if load:
            for mesg in msgpackfd(fd):
                self.loadbus.dist(mesg)

        def savemesg(mesg):
            fd.write( msgenpack(mesg) )

        self.savebus.link(savemesg)

    def setDataModel(self, model):
        '''
        Set a DataModel instance to enforce when using Tufo API.

        Example:

            core.setDataModel(model)

        '''
        self.model = model

    def getDataModel(self):
        '''
        Return the DataModel instance for this Cortex.

        Example:

            model = core.getDataModel()
            if model != None:
                dostuff(model)

        '''
        return self.model

    def genDataModel(self):
        '''
        Return (and create if needed) the DataModel instance for this Cortex.

        Example:

            model = core.genDataModel()

        '''
        if self.model == None:
            self.model = s_datamodel.DataModel()
        return self.model

    def getDataModelDict(self):
        '''
#.........这里部分代码省略.........
开发者ID:imjonsnooow,项目名称:synapse,代码行数:103,代码来源:common.py

示例2: Cortex

# 需要导入模块: from synapse.eventbus import EventBus [as 别名]
# 或者: from synapse.eventbus.EventBus import link [as 别名]
class Cortex(EventBus):
    '''
    Top level Cortex key/valu storage object.
    '''
    def __init__(self, link):
        EventBus.__init__(self)

        self._link = link

        self.lock = threading.Lock()
        self.statfuncs = {}

        self.auth = None
        self.tagcache = {}
        self.splicefuncs = {}

        self.model = s_datamodel.DataModel()

        self.sizebymeths = {}
        self.rowsbymeths = {}

        #############################################################
        # buses to save/load *raw* save events
        #############################################################
        self.savebus = EventBus()
        self.loadbus = EventBus()

        self.loadbus.on('core:save:add:rows', self._loadAddRows)
        self.loadbus.on('core:save:del:rows:by:iden', self._loadDelRowsById)
        self.loadbus.on('core:save:del:rows:by:prop', self._loadDelRowsByProp)
        self.loadbus.on('core:save:set:rows:by:idprop', self._loadSetRowsByIdProp)
        self.loadbus.on('core:save:del:rows:by:idprop', self._loadDelRowsByIdProp)

        #############################################################
        # bus for model layer sync
        # sync events are fired on the cortex and may be ingested
        # into another coretx using the sync() method.
        #############################################################
        self.on('tufo:add', self._fireCoreSync )
        self.on('tufo:del', self._fireCoreSync )
        self.on('tufo:tag:add', self._fireCoreSync )
        self.on('tufo:tag:del', self._fireCoreSync )

        self.syncact = s_reactor.Reactor()
        self.syncact.act('tufo:add', self._actSyncTufoAdd )
        self.syncact.act('tufo:del', self._actSyncTufoDel )
        self.syncact.act('tufo:tag:add', self._actSyncTufoTagAdd )
        self.syncact.act('tufo:tag:del', self._actSyncTufoTagDel )

        #############################################################

        self.onfini( self.savebus.fini )
        self.onfini( self.loadbus.fini )

        self.addStatFunc('any',self._calcStatAny)
        self.addStatFunc('all',self._calcStatAll)
        self.addStatFunc('min',self._calcStatMin)
        self.addStatFunc('max',self._calcStatMax)
        self.addStatFunc('sum',self._calcStatSum)
        self.addStatFunc('count',self._calcStatCount)
        self.addStatFunc('histo',self._calcStatHisto)
        self.addStatFunc('average',self._calcStatAverage)

        self._initCortex()

        self.model.addTufoForm('syn:tag', ptype='str:lwr')
        self.model.addTufoProp('syn:tag','up',ptype='str:lwr')
        self.model.addTufoProp('syn:tag','doc',defval='',ptype='str')
        self.model.addTufoProp('syn:tag','depth',defval=0,ptype='int')
        self.model.addTufoProp('syn:tag','title',defval='',ptype='str')

        #self.model.addTufoForm('syn:model',ptype='str')

        #self.model.addTufoForm('syn:type',ptype='str')
        #self.model.addTufoProp('syn:type','base',ptype='str',doc='what base type does this type extend?')
        #self.model.addTufoProp('syn:type','baseinfo',ptype='str',doc='Base type specific info (for example, a regex)')

        #self.model.addTufoForm('syn:form',ptype='str:prop')
        #self.model.addTufoProp('syn:form','doc',ptype='str')

        #self.model.addTufoForm('syn:prop',ptype='str:prop')
        #self.model.addTufoProp('syn:prop','doc',ptype='str')
        #self.model.addTufoProp('syn:prop','form',ptype='str:syn:prop')

        #self.model.addTufoProp('syn:prop','ptype',ptype='str')
        #self.model.addTufoProp('syn:prop','title',ptype='str')
        #self.model.addTufoProp('syn:prop','defval') # ptype='any'

        #self.model.addTufoForm('syn:splice',ptype='guid')
        #self.model.addTufoProp('syn:splice','date',ptype='time:epoch',doc='Time that the splice was requested')
        #self.model.addTufoProp('syn:splice','user',ptype='str',doc='Time user/system which requested the splice')
        #self.model.addTufoProp('syn:splice','note',ptype='str',doc='Filthy humon notes about the change')
        #self.model.addTufoProp('syn:splice','status',ptype='str',doc='Enum for init,done,deny to show the splice status')
        #self.model.addTufoProp('syn:splice','action',ptype='str:lwr',doc='The requested splice action')

        # FIXME load forms / props / etc

        self.model.addTufoForm('syn:splice', ptype='guid')

        self.model.addTufoGlob('syn:splice','on:*')     # syn:splice:on:fqdn=woot.com
#.........这里部分代码省略.........
开发者ID:jhsmith,项目名称:synapse,代码行数:103,代码来源:common.py


注:本文中的synapse.eventbus.EventBus.link方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。