def removeProcess(pid): """\internal \brief Called if a process leaves the system to ensure that no references that the process had remain in the system. If a process exits normally then all this should be unnessicary, however we can't trust user processes. """ # check it actually is a process and not another node if utils.isThreadId(pid): tid = pid pid = utils.getProcessIdFromThreadId(pid) del threads[tid] pthreads[pid].remove(tid) if len(pthreads[pid]) > 0: for ts in local_ts: if local_ts[ts].isDeadLocked(): local_ts[ts].unblockRandom() return if not utils.isProcessId(pid): return # check that it wasn't blocked when the connection was lost for tid in blocked_threads.keys(): if utils.getProcessIdFromThreadId(tid) == pid: del blocked_threads[tid] del pthreads[pid] if _linda_server.use_types and _linda_server.register_types: unregisterTypesFromProcess(pid) # remove any references the process may have had to our tuplespaces for ts in local_ts: local_ts.deleteAllReferences(ts, pid)
def create_tuplespace(self, req, msgid, message, data): # return a new tuplespace id ts = "S%s" % (guid.generate(), ) local_ts.newTupleSpace(ts) local_ts.addReference(ts, utils.getProcessIdFromThreadId(str(data[0]))) req.send(msgid, ("RESULT_STRING", ts))
def add_reference(self, req, msgid, message, data): ts, ref = str(data[0]), str(data[1]) if utils.isThreadId(ref): ref = utils.getProcessIdFromThreadId(ref) if not local_ts.has_key(ts): local_ts.newTupleSpace(ts) local_ts.addReference(ts, ref) req.send(msgid, (done, ))
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
def delete_reference(self, req, msgid, message, data): ts, ref = str(data[0]), str(data[1]) if ts == "UTS": req.send(msgid, (done, )) return if utils.isThreadId(ref): ref = utils.getProcessIdFromThreadId(ref) # see the note in the TupleSpace.removeallreference for an explanation of the killlock try: local_ts[ts].killlock.acquire() except KeyError: pass else: threading.Thread(target=local_ts.deleteReference, args=(ts, ref)).start() req.send(msgid, (done, ))
def read_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]._rd(tid, template, unblockable) stats.inc_stat("message_rd_total") if r is not None: del blocked_threads[tid] # we found a tuple so update the references and return it utils.addReference(r, utils.getProcessIdFromThreadId(tid)) req.send(msgid, ("RESULT_TUPLE", r)) else: pass # this thread is now blocked