예제 #1
0
    def test_eventbus_busref_gen(self):

        with s_eventbus.BusRef() as refs:
            self.raises(NoSuchCtor, refs.gen, 'woot')

        def ctor(name):
            return s_eventbus.EventBus()

        with s_eventbus.BusRef(ctor=ctor) as refs:

            self.none(refs.get('woot'))

            woot = refs.gen('woot')
            self.eq(1, woot._syn_refs)

            self.nn(woot)
            self.true(refs.gen('woot') is woot)
            self.eq(2, woot._syn_refs)

            woot.fini()
            self.false(woot.isfini)
            self.true(refs.get('woot') is woot)
            self.eq(1, woot._syn_refs)

            woot.fini()
            self.eq(0, woot._syn_refs)

            self.true(woot.isfini)
            self.false(refs.get('woot') is woot)
            self.eq(0, woot._syn_refs)
예제 #2
0
파일: fifo.py 프로젝트: mari0d/synapse
    def __init__(self, conf, xmit=None):

        s_config.Config.__init__(self)
        self.setConfOpts(conf)
        self.reqConfOpts()

        self.lock = threading.Lock()
        self.winds = s_eventbus.BusRef()

        self.atoms = s_eventbus.BusRef(ctor=self._brefAtomCtor)
        self.onfini(self.atoms.fini)

        self.seqs = self._getFifoSeqs()
        if not self.seqs:
            self.seqs.append(0)

        # open our append atom
        lseq = self.seqs[-1]
        self.atom = self.atoms.gen(lseq)

        # our next expected sequence num
        self.nseq = lseq + self.atom.size

        # open our "default" state file
        path = self._getPathJoin('default.state')
        self.wind = Window(self, path, xmit=xmit)
        self.onfini(self.wind.fini)

        task = s_glob.sched.loop(2, self.flush)
        self.onfini(task.fini)

        self._cullAtomBase(self.wind.bseq)
예제 #3
0
    def test_eventbus_busref_items(self):

        bref = s_eventbus.BusRef()

        bus0 = s_eventbus.EventBus()
        bus1 = s_eventbus.EventBus()
        bus2 = s_eventbus.EventBus()

        bref.put('foo', bus0)
        bref.put('bar', bus1)
        bref.put('baz', bus2)

        items = bref.items()
        self.isin(('foo', bus0), items)
        self.isin(('bar', bus1), items)
        self.isin(('baz', bus2), items)

        bus1.fini()
        items = bref.items()
        self.isin(('foo', bus0), items)
        self.isin(('baz', bus2), items)

        bus2.fini()
        items = bref.items()
        self.isin(('foo', bus0), items)

        bus0.fini()
        items = bref.items()
        self.eq(items, [])

        bref.fini()
        items = bref.items()
        self.eq(items, [])
예제 #4
0
    def __init__(self, onchan=None):

        Link.__init__(self)

        self.onchan = onchan
        self.chans = s_eventbus.BusRef()
        # TODO: chan timeouts... (maybe add to BusRef?)

        self.onfini(self.chans.fini)
예제 #5
0
    def postCell(self):
        '''
        CryoCell initialization routines.
        '''
        self.names = self.getCellDict('cryo:names')
        self.confs = self.getCellDict('cryo:confs')
        self.tanks = s_eventbus.BusRef()

        for name, iden in self.names.items():
            path = self.getCellPath('tanks', iden)
            conf = self.confs.get(name)
            tank = CryoTank(path, conf)
            self.tanks.put(name, tank)
예제 #6
0
    def __init__(self, auth, neuraddr, neurfunc=None):
        s_eventbus.EventBus.__init__(self)

        self.neur = None
        self.neuraddr = neuraddr
        self.neurfunc = neurfunc

        self.auth = auth
        self.user = CellUser(auth)
        self.names = collections.deque()  # used for round robin..

        self.ctors = {}
        self.cells = s_eventbus.BusRef()
        self.neurok = threading.Event()

        self._fireNeurLink()
        self.onfini(self.cells.fini)
예제 #7
0
    def test_eventbus_busref(self):

        bref = s_eventbus.BusRef()

        bus0 = s_eventbus.EventBus()
        bus1 = s_eventbus.EventBus()
        bus2 = s_eventbus.EventBus()

        bref.put('foo', bus0)
        bref.put('bar', bus1)
        bref.put('baz', bus2)

        bus1.fini()
        self.nn(bref.get('foo'))
        self.none(bref.get('bar'))

        self.len(2, list(bref))

        self.true(bref.pop('baz') is bus2)
        self.len(1, list(bref))

        bref.fini()
        self.true(bus0.isfini)