예제 #1
0
    def collect(self, req, msgid, message, data):
        ts, dest_ts, template = str(data[0]), str(data[1]), data[2]

        try:
            ts = local_ts[ts]
        except KeyError:
            req.send(msgid, 0)
            return

        try:
            dest_ts = local_ts[dest_ts]
        except KeyError:
            local_ts.newTupleSpace(dest_ts)
            dest_ts = local_ts[dest_ts]
            new = True
        else:
            new = False

        tups = ts.collect(template)
        if tups != []:
            for t in tups:
                utils.changeOwner(t, ts, dest_ts._id)
                local_ts[dest_ts._id]._out(t)

        if req.type != "SERVER":
            r = broadcast_tonodes(ts.partitions, False, collect, ts._id, dest_ts._id, template)
            total = sum([x[1] for x in r]) + len(tups)
        else:
            total = len(tups)

        if new:
            local_ts.garbage(dest_ts)

        req.send(msgid, ("RESULT_INT", total))
예제 #2
0
    def collect(self, req, msgid, message, data):
        ts, dest_ts, template = str(data[0]), str(data[1]), data[2]

        try:
            ts = local_ts[ts]
        except KeyError:
            req.send(msgid, 0)
            return

        try:
            dest_ts = local_ts[dest_ts]
        except KeyError:
            local_ts.newTupleSpace(dest_ts)
            dest_ts = local_ts[dest_ts]
            new = True
        else:
            new = False

        tups = ts.collect(template)
        if tups != []:
            for t in tups:
                utils.changeOwner(t, ts, dest_ts._id)
                local_ts[dest_ts._id]._out(t)

        if req.type != "SERVER":
            r = broadcast_tonodes(ts.partitions, False, collect, ts._id,
                                  dest_ts._id, template)
            total = sum([x[1] for x in r]) + len(tups)
        else:
            total = len(tups)

        if new:
            local_ts.garbage(dest_ts)

        req.send(msgid, ("RESULT_INT", total))
예제 #3
0
    def in_tuple(self, req, msgid, message, data):
        ts, template, tid = str(data[0]), data[1], str(data[2])
        unblockable = message == inp_tuple

        blocked_threads[tid] = (req, ts)

        assert utils.isTupleSpaceId(ts), "%s is not a tuplespace id" % (ts, )
        assert local_ts.has_key(ts)

        r = local_ts[ts]._in(tid, template, unblockable)
        stats.inc_stat("message_in_total")

        if r is not None:
            del blocked_threads[tid]
            utils.changeOwner(r, ts, utils.getProcessIdFromThreadId(tid))
            req.send(msgid, ("RESULT_TUPLE", r))
        else:
            pass # this thread is now blocked
예제 #4
0
    def in_tuple(self, req, msgid, message, data):
        ts, template, tid = str(data[0]), data[1], str(data[2])
        unblockable = message == inp_tuple

        blocked_threads[tid] = (req, ts)

        assert utils.isTupleSpaceId(ts), "%s is not a tuplespace id" % (ts, )
        assert local_ts.has_key(ts)

        r = local_ts[ts]._in(tid, template, unblockable)
        stats.inc_stat("message_in_total")

        if r is not None:
            del blocked_threads[tid]
            utils.changeOwner(r, ts, utils.getProcessIdFromThreadId(tid))
            req.send(msgid, ("RESULT_TUPLE", r))
        else:
            pass  # this thread is now blocked