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


Python Message.referenceId方法代码示例

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


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

示例1: signal

# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import referenceId [as 别名]
 def signal(self, cv):
     self.log("INFO", "("+str(cv.id)+") signaling")
     cv.conditionVariable.acquire()
     sigmes = Message()
     sigmes.referenceId = cv.id
     sigmes.type = "SIGNAL"
     if len(cv.waitingProcesses) >0:
         sigmes.recipientId = cv.waitingProcesses[0]
         self.communicationManager.send_message(sigmes)
     cv.conditionVariable.release()
开发者ID:chris710,项目名称:distributedmonitor,代码行数:12,代码来源:monitor.py

示例2: signal_all

# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import referenceId [as 别名]
 def signal_all(self, cv):
     self.log("INFO", "("+str(cv.id)+") signaling to all")
     cv.conditionVariable.acquire()
     sigmes = Message()
     sigmes.referenceId = cv.id
     sigmes.type = "SIGNAL"
     for proc in cv.waitingProcesses:
         sigmes.recipientId = proc
         self.communicationManager.send_message(sigmes)
     cv.conditionVariable.release()
开发者ID:chris710,项目名称:distributedmonitor,代码行数:12,代码来源:monitor.py

示例3: wait

# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import referenceId [as 别名]
 def wait(self, cv, mux):
     cv.conditionVariable.acquire()
     cv.waiting = True
     retmes = Message()
     retmes.referenceId = cv.id
     retmes.type = "WAIT"
     self.communicationManager.send_broadcast(retmes)
     self.log("INFO", "("+str(cv.id)+")"+" waiting...")
     while cv.waiting:
         self.unlock(mux)
         cv.conditionVariable.wait()
         cv.conditionVariable.release()
         self.log("INFO", "("+str(cv.id)+") Reaquiring lock...")
         self.lock(mux)
     self.log("INFO", "("+str(cv.id)+") Received signal")
     retmes = Message()
     retmes.referenceId = cv.id
     retmes.type = "WAIT_RETURN"
     self.communicationManager.send_broadcast(retmes)
开发者ID:chris710,项目名称:distributedmonitor,代码行数:21,代码来源:monitor.py

示例4: set_data_for_return

# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import referenceId [as 别名]
 def set_data_for_return(self, data, size):
     if self.previousReturn is not None:
         del self.previousReturn
     m = Message()
     m.type = "DATA"
     m.referenceId = self.id
     m.hasData = True
     m.dataSize = size
     m.data = data
     self.previousReturn = m
开发者ID:chris710,项目名称:distributedmonitor,代码行数:12,代码来源:mutex.py

示例5: lock

# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import referenceId [as 别名]
 def lock(self, mux):
     mux.operationMutex.acquire()
     mux.requesting = True       # set mux to wait for CS
     mux.keepAlive = False
     if mux.agreeVector is not None:     # reset agreeVector
         del mux.agreeVector
     mux.agreeVector = [False]*self.communicationManager.processCount      # agree vector init
     for i in range(0, self.communicationManager.processCount):
         mux.agreeVector[i] = (i == self.communicationManager.processId)     # set every entry to false except requesting process
     reqmes = Message()
     reqmes.type = "REQUEST"
     reqmes.referenceId = mux.id
     self.communicationManager.send_broadcast(reqmes)        # send requests to everybody
     mux.requestClock = reqmes.clock
     mux.locked = True
     mux.criticalSectionCondition.acquire()
     mux.operationMutex.release()
     while mux.requesting:
         mux.criticalSectionCondition.wait()
     mux.criticalSectionCondition.release()
     self.log("INFO", "("+str(mux.id)+") locked")
开发者ID:chris710,项目名称:distributedmonitor,代码行数:23,代码来源:monitor.py

示例6: unlock

# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import referenceId [as 别名]
 def unlock(self, mux):
     mux.operationMutex.acquire()
     if not mux.locked:
         mux.operationMutex.release()
         return
     retmes = Message()
     retmes.type = "RETURN"
     retmes.referenceId = mux.id
     if len(mux.heldUpRequests) == 0:
         mux.keepAlive = True    # respond with RETURN instead of AGREE (after CS)
     for proc in mux.heldUpRequests:
         retmes.recipientId = proc
         self.communicationManager.send_message(retmes)
     del mux.heldUpRequests[:]
     mux.requesting = False
     mux.locked = False
     self.communicationManager.get_communication_mutex().acquire()  # create new agreeVector
     mux.agreeVector = dict()
     for i in range(0, self.communicationManager.processCount):
         mux.agreeVector[i] = (i == self.communicationManager.processId)     # set every entry to false except requesting process
     self.communicationManager.get_communication_mutex().release()
     mux.operationMutex.release()
     self.log("INFO", "("+str(mux.id)+") unlocked and leaving CS")
开发者ID:chris710,项目名称:distributedmonitor,代码行数:25,代码来源:monitor.py

示例7: communication_loop

# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import referenceId [as 别名]
 def communication_loop(self):
     while True:
         msg = self.communicationManager.recv_message()      # blocking
         if msg is None:
             break
         if msg.type == "REQUEST":    # requesting CS access
             mux = Mutex.get_mutex(msg.referenceId)
             if mux is not None:
                 mux.operationMutex.acquire()
                 if mux.requesting:        # if REQUEST has earlier time then send AGREE
                     if mux.requestClock < msg.clock:  # add to queue
                         mux.heldUpRequests.append(msg.senderId)
                     else:
                         if mux.requestClock == msg.clock and self.communicationManager.processId < msg.senderId:
                             mux.heldUpRequests.append(msg.senderId)
                         else:
                             agreeReply = Message()
                             agreeReply.referenceId = msg.referenceId
                             agreeReply.recipientId = msg.senderId
                             if mux.keepAlive:
                                 agreeReply.type = "RETURN"
                                 if mux.get_data_size() > 0:
                                     agreeReply.hasData = True
                             else:
                                 agreeReply.type = "AGREE"
                             self.communicationManager.send_message(agreeReply)
                 else:
                     if not mux.locked:
                         agreeReply = Message()
                         agreeReply.referenceId = msg.referenceId
                         agreeReply.recipientId = msg.senderId
                         if mux.keepAlive:
                             agreeReply.type = "RETURN"
                         else:
                             agreeReply.type = "AGREE"
                         self.communicationManager.send_message(agreeReply)
                     else:
                         mux.heldUpRequests.append(msg.senderId)
                 mux.operationMutex.release()
         elif msg.type == "RETURN":  # when leaving CS
             mux = Mutex.get_mutex(msg.referenceId)
             if mux is not None:
                 mux.operationMutex.acquire()
                 mux.agreeVector[msg.senderId] = True
                 mux.keepAlive = False
                 if mux.previousReturn is not None:
                     del mux.previousReturn
                 mux.previousReturn = msg
                 mux.operationMutex.release()
                 self.enter_critical_section(mux)
         elif msg.type == "AGREE":           # process agrees to request for CS
             mux = Mutex.get_mutex(msg.referenceId)
             mux.operationMutex.acquire()
             if mux is not None and mux.requesting:
                 mux.agreeVector[msg.senderId] = True       # sender agreed
                 mux.keepAlive = False                      # sb tries to acquire CS
                 mux.operationMutex.release()
                 self.enter_critical_section(mux)       # try to enter CS
             else:
                 mux.operationMutex.release()
         elif msg.type == "WAIT":        # process is waiting
             cv = ConditionVariable.get_condition_variable(msg.referenceId)
             cv.conditionVariable.acquire()
             cv.waitingProcesses.append(msg.senderId)
             cv.conditionVariable.release()
         elif msg.type == "WAIT_RETURN":     # process is not waiting anymore
             cv = ConditionVariable.get_condition_variable(msg.referenceId)
             cv.conditionVariable.acquire()
             cv.waitingProcesses.remove(msg.senderId)
             cv.conditionVariable.release()
         elif msg.type == "SIGNAL":          # wake up waiting process
             cv = ConditionVariable.get_condition_variable(msg.referenceId)
             cv.conditionVariable.acquire()
             cv.waiting = False
             cv.conditionVariable.notify()
             cv.conditionVariable.release()
         elif msg.type == "QUIT":            # process will no longer communicate
             self.quitMessages += 1
             if self.quitMessages == self.communicationManager.processCount:
                 self.communicationManager.initialized = False
                 return
开发者ID:chris710,项目名称:distributedmonitor,代码行数:83,代码来源:monitor.py


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