class CoordClass(NodeClass): """ simulates the coordinator. """ NodeList = [] mean_waiting_time = 0 total_waiting_time = 0 def __init__(self, name, weight, protocol, sources, network): """ simulates a node instance for centralized protocol. """ Process.__init__(self) self.node = Node(name, weight, protocol, sources, network) self.waiting_time = 0 # waiting time for this particular node self.msg_number = 0 # messages this node sent self.busy_cpu = 0 # time the cpu is busy # signal for knowing if this simulation event is passive or not self.sleeping = False CoordClass.NodeList.append(self) def run(self): while True: # create the simulation objects self.cdj = CoordDataJob() self.cim = CoordIncomingMsgs() # this class has been imported from nodecoordclass.py self.to = TimeOut() # wait for a while before generating new data for current node yield hold, self, 0.1 # generate new data and assign to new_data a true/false value: # if new_data = True then no action is taken, else send message # to coordinator. new_data = self.cdj.recvEnvironmentData(self.node) # and activate them activate(self.cdj, self.cdj.run(self.node, new_data)) activate(self.cim, self.cim.run(self.to, self.node)) activate(self.to, self.to.run(self.cim))
def run(self): while True: # create the simulation objects self.cdj = CoordDataJob() self.cim = CoordIncomingMsgs() # this class has been imported from nodecoordclass.py self.to = TimeOut() # wait for a while before generating new data for current node yield hold, self, 0.1 # generate new data and assign to new_data a true/false value: # if new_data = True then no action is taken, else send message # to coordinator. new_data = self.cdj.recvEnvironmentData(self.node) # and activate them activate(self.cdj, self.cdj.run(self.node, new_data)) activate(self.cim, self.cim.run(self.to, self.node)) activate(self.to, self.to.run(self.cim))