def do_return_tuple(): req, ts = server.blocked_threads[tid] del server.blocked_threads[tid] utils.changeOwner(matched_tup, self._id, utils.getProcessIdFromThreadId(tid)) req.lock.acquire() req.send(None, ("RESULT_TUPLE", matched_tup)) req.lock.release() broadcast_tonodes(self.partitions, False, cancel_request, self._id, pattern)
def __del__(self): broadcast_tonodes(self.partitions, False, deleted_partition, self._id, server.node_id) if self.ts.count() > 0 and len(self.partitions) > 0: node = self.partitions[0] tups = list(self.ts.matchAllTuples()) map(lambda x: utils.changeOwner(x, self._id, self._id, node), tups) sendMessageToNode(node, None, multiple_in, self._id, tuple(tups)) else: tups = list(self.ts.matchAllTuples()) map(lambda x: utils.delReference(x, self._id), tups)
def copy_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.copy_collect(template) if tups != []: for t in tups: utils.addReference(t, ts, dest_ts._id) local_ts[dest_ts._id]._out(t) if req.type != "SERVER": r = broadcast_tonodes(ts.partitions, False, copy_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))
def isDeadLocked(self): if not self.isLocallyDeadlocked(): return False d = broadcast_tonodes(self.partitions, False, is_deadlocked, self._id) d = [x for x in d if d is not True] return len(d) == 0
def add_tuples(): for server in [x[1] for x in broadcast_tonodes(self.partitions, False, tuple_request, self._id, pattern)]: for t in range(len(server)): self._out(tuple(server[t])) # check if we have created a deadlock if self.isDeadLocked(): # if we have then unblock a random process self.unblockRandom()
def add_tuples(): for server in [ x[1] for x in broadcast_tonodes( self.partitions, False, tuple_request, self._id, pattern) ]: for t in range(len(server)): self._out(tuple(server[t])) # check if we have created a deadlock if self.isDeadLocked(): # if we have then unblock a random process self.unblockRandom()
def register(self): try: broadcast_message(register_partition, self._id, server.node_id) ps = broadcast_firstreplyonly(get_partitions, self._id) if ps != dont_know: self.partitions.extend([str(p) for p in ps[1] if str(p) != server.node_id]) r = broadcast_tonodes(self.partitions, True, get_requests, self._id) if r != dont_know: r = r[1] for i in range(len(r)): nid, template = r[i][0], interserver_types.getTypesFromServer(nid, r[i][1]) self.requests.append((str(nid), tuple(template))) finally: self.lock.release(msg=("end start", self._id))
def register(self): try: broadcast_message(register_partition, self._id, server.node_id) ps = broadcast_firstreplyonly(get_partitions, self._id) if ps != dont_know: self.partitions.extend( [str(p) for p in ps[1] if str(p) != server.node_id]) r = broadcast_tonodes(self.partitions, True, get_requests, self._id) if r != dont_know: r = r[1] for i in range(len(r)): nid, template = r[i][ 0], interserver_types.getTypesFromServer(nid, r[i][1]) self.requests.append((str(nid), tuple(template))) finally: self.lock.release(msg=("end start", self._id))