Beispiel #1
0
 def ecome_to_life(self, mbox, life_of_universe, thermobox, heaterbox, envirotomotdet, lit_bubtoenviro, clockboxes, berkeley_or_lamport):
     if berkeley_or_lamport == "berkeley":
         neighbors = create_edges("enviro",6,clockboxes)
         parent, children, status = find_MST("enviro", neighbors)
         self.time=berkeley_clock_synch("enviro", self.offset, parent, children, status)
     mbox.wait_on_mail("enviro")
     time_until_we_all_die = 0
     while time_until_we_all_die < life_of_universe:
         self.temperature_change(time_until_we_all_die)
         temp = message("thermo","enviro", "", self.temperature, thermobox.timestamp(self.offset))
         thermobox.deliver_mail(self.offset,temp)
         x = heaterbox.wait_on_mail(self.offset)
         if berkeley_or_lamport == "lamport":                                 #This performs the Lamport logical clocks algorithm: everytime the process
             current_time = heaterbox.timestamp(self.offset)                  #recieves a new message it compares it's own clock time to that of the
             if x.time > current_time :                                       #timestamp in the message; if the time in the timestamp is larger than the
                 self.offset = x.time - current_time + 1                      #time in its own logical clock then it knows that it is a contradicton and
         if x.data == "on":                                                   #it must add the difference between (plus 1) to its current offset
             self.is_heater_on = "yes"
         else:
             self.is_heater_on = "no"
         time_until_we_all_die = time_until_we_all_die + 1
         self.intruder_change(time_until_we_all_die)
         isthereintruder = message("mot_det","enviro", "", self.intruder, envirotomotdet.timestamp(self.offset))
         envirotomotdet.deliver_mail(self.offset,isthereintruder)
         x = lit_bubtoenviro.wait_on_mail(self.offset)
         if berkeley_or_lamport == "lamport":                                 #This performs the Lamport logical clocks algorithm: everytime the process
             current_time = lit_bubtoenviro.timestamp(self.offset)            #recieves a new message it compares it's own clock time to that of the
             if x.time > current_time :                                       #timestamp in the message; if the time in the timestamp is larger than the
                 self.offset = x.time - current_time + 1                      #time in its own logical clock then it knows that it is a contradicton and
         if x.data == "on":                                                   #it must add the difference between (plus 1) to its current offset 
             self.is_light_on = "yes"
         else:
             self.is_light_on = "no"
         if berkeley_or_lamport == "berkeley":
             self.time=berkeley_clock_synch("enviro", self.offset, parent, children, status)
Beispiel #2
0
 def tcome_to_life(self, rbox, life_of_universe, envirobox, pipeboxes,
                   clockboxes, berkeley_or_lamport):
     if berkeley_or_lamport == "berkeley":
         neighbors = create_edges("thermo", 7, clockboxes)
         parent, children, status = find_MST("thermo", neighbors)
         self.time = berkeley_clock_synch("thermo", self.offset, parent,
                                          children, status)
     time_until_we_all_die = 0
     self.register_self(rbox)
     while time_until_we_all_die < life_of_universe:
         x = pipeboxes[self.idnum].wait_on_query(self.offset, self.idnum)
         if berkeley_or_lamport == "lamport":  #This performs the Lamport logical clocks algorithm: everytime the process
             current_time = pipeboxes[self.idnum].timestamp(
                 self.offset
             )  #recieves a new message it compares it's own clock time to that of the
             if x.time > current_time:  #timestamp in the message; if the time in the timestamp is larger than the
                 self.offset = x.time - current_time + 1  #time in its own logical clock then it knows that it is a contradicton and
         if x.command == "query":  #it must add the difference between (plus 1) to its current offset
             self.query_response(pipeboxes)
         temp = envirobox.wait_on_mail(self.offset)
         if berkeley_or_lamport == "lamport":  #This performs the Lamport logical clocks algorithm: everytime the process
             current_time = envirobox.timestamp(
                 self.offset
             )  #recieves a new message it compares it's own clock time to that of the
             if temp.time > current_time:  #timestamp in the message; if the time in the timestamp is larger than the
                 self.offset = temp.time - current_time + 1  #time in its own logical clock then it knows that it is a contradicton and
         self.state = temp.data  #it must add the difference between (plus 1) to its current offset
         time_until_we_all_die = time_until_we_all_die + 1
         if berkeley_or_lamport == "berkeley":
             self.time = berkeley_clock_synch("thermo", self.offset, parent,
                                              children, status)
Beispiel #3
0
 def dcome_to_life(self, rbox, life_of_universe, pipeboxes, usertodoortdet,
                   clockboxes, berkeley_or_lamport):
     if berkeley_or_lamport == "berkeley":
         neighbors = create_edges("doorboy", 9, clockboxes)
         parent, children, status = find_MST("doorboy", neighbors)
         self.time = berkeley_clock_synch("doorboy", self.offset, parent,
                                          children, status)
     time_until_we_all_die = 0
     self.register_self(rbox)
     while time_until_we_all_die < life_of_universe:
         isdooropen = usertodoortdet.wait_on_mail(self.offset)
         if berkeley_or_lamport == "lamport":  #This performs the Lamport logical clocks algorithm: everytime the process
             current_time = usertodoortdet.timestamp(
                 self.offset
             )  #recieves a new message it compares it's own clock time to that of the
             if isdooropen.time > current_time:  #timestamp in the message; if the time in the timestamp is larger than the
                 self.offset = isdooropen.time - current_time + 1  #time in its own logical clock then it knows that it is a contradicton and
         self.state = isdooropen.command  #it must add the difference between (plus 1) to its current offset
         time_until_we_all_die = time_until_we_all_die + 1
         self.report_state(pipeboxes)
         if berkeley_or_lamport == "berkeley":
             self.time = berkeley_clock_synch("doorboy", self.offset,
                                              parent, children, status)
Beispiel #4
0
 def ucome_to_life(self, mbox, life_of_universe, usertogate, usertodoor,
                   clockboxes, berkeley_or_lamport):
     if berkeley_or_lamport == "berkeley":
         neighbors = create_edges("user", 4, clockboxes)
         parent, children, status = find_MST("user", neighbors)
         self.time = berkeley_clock_synch("user", self.offset, parent,
                                          children, status)
     mbox.wait_on_mail("user")
     time_until_we_all_die = 0
     self.name = "home"
     while time_until_we_all_die < life_of_universe:
         x = usertogate.wait_on_query(self.offset, "user")
         if berkeley_or_lamport == "lamport":  #This performs the Lamport logical clocks algorithm: everytime the process
             current_time = usertogate.timestamp(
                 self.offset
             )  #recieves a new message it compares it's own clock time to that of the
             if x.time > current_time:  #timestamp in the message; if the time in the timestamp is larger than the
                 self.offset = x.time - current_time + 1  #time in its own logical clock then it knows that it is a contradicton and
         time_until_we_all_die = time_until_we_all_die + 1  #it must add the difference between (plus 1) to its current offset
         if x.data == "yes" and self.name == "away":
             print(
                 "      A        L            EEEEEEEEEEE    RRRRRRRR    TTTTTTTTTTTTT"
             )
             print(
                 "     A A       L            E              R       R         T     "
             )
             print(
                 "    A   A      L            E              R       R         T     "
             )
             print(
                 "   AAAAAAA     L            EEEEEEEEEEE    R RRRRRR          T     "
             )
             print(
                 "  A       A    L            E              R       R         T     "
             )
             print(
                 " A         A   L            E              R        R        T     "
             )
             print(
                 "A           A  LLLLLLLLLLL  EEEEEEEEEEE    R         R       T     "
             )
         else:
             pass
         prevstate = self.name
         home_or_not = input('')
         if home_or_not == "away":
             self.name = "away"
         elif home_or_not == "home":
             self.name = "home"
         report = message("gate", "user", "", self.name,
                          usertogate.timestamp(self.offset))
         usertogate.deliver_mail(self.offset, report)
         if self.name != prevstate:
             door = message("door", "user", "statechange", self.name,
                            usertodoor.timestamp(self.offset))
             usertodoor.deliver_mail(self.offset, door)
         else:
             door = message("door", "user", "nochange", "",
                            usertodoor.timestamp(self.offset))
             usertodoor.deliver_mail(self.offset, door)
         if berkeley_or_lamport == "berkeley":
             self.time = berkeley_clock_synch("user", self.offset, parent,
                                              children, status)
Beispiel #5
0
 def bcome_to_life(self, rbox, life_of_universe, gatetobackend, clockboxes,
                   berkeley_or_lamport):
     if berkeley_or_lamport == "berkeley":
         neighbors = create_edges("backend", 3, clockboxes)
         parent, children, status = find_MST("backend", neighbors)
         self.time = berkeley_clock_synch("backend", self.offset, parent,
                                          children, status)
     addressbook = rbox.wait_on_mail("backend")
     self.registry = addressbook.data
     for j, x in enumerate(self.registry):
         if x[1] == "sensor" and x[2] == "temperature":
             self.thermoidnum = j
         elif x[1] == "device" and x[2] == "temperature":
             self.heateridnum = j
         elif x[1] == "sensor" and x[2] == "motion":
             self.mot_detidnum = j
         elif x[1] == "device" and x[2] == "motion":
             self.lit_bubidnum = j
         elif x[1] == "sensor" and x[2] == "door":
             self.door_detidnum = j
     security_beacon = ["", "sensor", "security"]
     self.sec_beaconidnum = len(self.registry)
     self.registry.append(security_beacon)
     time_until_we_all_die = 0
     while time_until_we_all_die < life_of_universe - 2:
         time_until_we_all_die = time_until_we_all_die + 1
         for q in range(6):
             christmastime = gatetobackend.wait_on_mail(self.offset)
             if berkeley_or_lamport == "lamport":  #This performs the Lamport logical clocks algorithm: everytime the process
                 current_time = gatetobackend.timestamp(
                     self.offset
                 )  #recieves a new message it compares it's own clock time to that of the
                 if christmastime.time > current_time:  #timestamp in the message; if the time in the timestamp is larger than the
                     self.offset = christmastime.time - current_time + 1  #time in its own logical clock then it knows that it is a contradicton and
             if christmastime.command == "no_change":  #it must add the difference between (plus 1) to its current offset
                 pass
             else:
                 if christmastime.command == "temp_change":
                     if self.registry[
                             self.thermoidnum][0] != christmastime.data:
                         self.database.append(christmastime)
                         self.registry[
                             self.thermoidnum][0] = christmastime.data
                 elif christmastime.command == "heater_change":
                     self.database.append(christmastime)
                     self.registry[self.heateridnum][0] = christmastime.data
                 elif christmastime.command == "motion_change":
                     self.database.append(christmastime)
                     self.registry[
                         self.mot_detidnum][0] = christmastime.data
                 elif christmastime.command == "bulb_change":
                     self.database.append(christmastime)
                     self.registry[
                         self.lit_bubidnum][0] = christmastime.data
                 elif christmastime.command == "door_change":
                     self.database.append(christmastime)
                     self.registry[
                         self.door_detidnum][0] = christmastime.data
                 elif christmastime.command == "presence_change":
                     self.database.append(christmastime)
                     self.registry[
                         self.sec_beaconidnum][0] = christmastime.data
         if berkeley_or_lamport == "berkeley":
             self.time = berkeley_clock_synch("backend", self.offset,
                                              parent, children, status)
     if berkeley_or_lamport == "berkeley":
         self.time = berkeley_clock_synch("backend", self.offset, parent,
                                          children, status)
         self.time = berkeley_clock_synch("backend", self.offset, parent,
                                          children, status)
     for q in range(8):
         christmastime = gatetobackend.wait_on_mail(self.offset)
         if berkeley_or_lamport == "lamport":  #This performs the Lamport logical clocks algorithm: everytime the process
             current_time = gatetobackend.timestamp(
                 self.offset
             )  #recieves a new message it compares it's own clock time to that of the
             if christmastime.time > current_time:  #timestamp in the message; if the time in the timestamp is larger than the
                 self.offset = christmastime.time - current_time + 1  #time in its own logical clock then it knows that it is a contradicton and
         if christmastime.command == "no_change":  #it must add the difference between (plus 1) to its current offset
             pass
         else:
             if christmastime.command == "temp_change":
                 if self.registry[
                         self.thermoidnum][0] != christmastime.data:
                     self.database.append(christmastime)
                     self.registry[self.thermoidnum][0] = christmastime.data
             elif christmastime.command == "heater_change":
                 self.database.append(christmastime)
                 self.registry[self.heateridnum][0] = christmastime.data
             elif christmastime.command == "motion_change":
                 self.database.append(christmastime)
                 self.registry[self.mot_detidnum][0] = christmastime.data
             elif christmastime.command == "bulb_change":
                 self.database.append(christmastime)
                 self.registry[self.lit_bubidnum][0] = christmastime.data
             elif christmastime.command == "door_change":
                 self.database.append(christmastime)
                 self.registry[self.door_detidnum][0] = christmastime.data
             elif christmastime.command == "presence_change":
                 self.database.append(christmastime)
                 self.registry[self.sec_beaconidnum][0] = christmastime.data
     for q in self.registry:
         print(q)
     for z in self.database:
         z.printmessage(self.offset, "reader")
Beispiel #6
0
 def gcome_to_life(self, rbox, life_of_universe, num_of_devices, pipeboxes,
                   usertogate, gatetobackend, clockboxes,
                   berkeley_or_lamport):
     if berkeley_or_lamport == "berkeley":
         neighbors = create_edges("gate", 2, clockboxes)
         parent, children, status = find_MST("gate", neighbors)
         self.time = berkeley_clock_synch("gate", self.offset, parent,
                                          children, status)
     self.activate_devices(rbox, num_of_devices)
     activate_enviroment = message("enviro", "gate", "activate", "",
                                   rbox.timestamp(self.offset))
     rbox.deliver_mail(activate_enviroment)
     activate_user_interface = message("user", "gate", "activate", "",
                                       rbox.timestamp(self.offset))
     rbox.deliver_mail(activate_user_interface)
     activate_backend = message("backend", "gate", "activate",
                                self.registry, rbox.timestamp(self.offset))
     rbox.deliver_mail(activate_backend)
     time_until_we_all_die = 0
     oldmotdetdata = "no"
     while time_until_we_all_die < life_of_universe:
         time_until_we_all_die = time_until_we_all_die + 1
         self.change_state(self.heateridnum, self.alertheater, pipeboxes)
         self.query_state(self.thermoidnum, pipeboxes,
                          time_until_we_all_die, life_of_universe,
                          gatetobackend, berkeley_or_lamport)
         isthere_intruder = pipeboxes[self.mot_detidnum].wait_on_query(
             self.offset, "gate")
         if berkeley_or_lamport == "lamport":  #This performs the Lamport logical clocks algorithm: everytime the process
             current_time = pipeboxes[self.mot_detidnum].timestamp(
                 self.offset
             )  #recieves a new message it compares it's own clock time to that of the
             if isthere_intruder.time > current_time:  #timestamp in the message; if the time in the timestamp is larger than the
                 self.offset = isthere_intruder.time - current_time + 1  #time in its own logical clock then it knows that it is a contradicton and
         oldbulbstatus = self.should_i_turn_on_bulb  #it must add the difference between (plus 1) to its current offset
         if oldmotdetdata != isthere_intruder.data:
             newmotdetbstatus = message(
                 "backend", "gate", "motion_change", isthere_intruder.data,
                 gatetobackend.timestamp(self.offset))
             gatetobackend.deliver_mail(self.offset, newmotdetbstatus)
         else:
             oldstatus = message("backend", "gate", "no_change", "",
                                 gatetobackend.timestamp(self.offset))
             gatetobackend.deliver_mail(self.offset, oldstatus)
         oldmotdetdata = isthere_intruder.data
         if self.mode == "home":
             if isthere_intruder.data == "yes":
                 self.should_i_turn_on_bulb = "on"
                 self.time_since_last_intruder = 0
             else:
                 self.time_since_last_intruder = self.time_since_last_intruder + 1
                 if self.time_since_last_intruder == 5:
                     self.should_i_turn_on_bulb = "off"
             hola = message("user", "gate", "", "",
                            usertogate.timestamp(self.offset))
             usertogate.deliver_mail(self.offset, hola)
         elif self.mode == "away":
             self.should_i_turn_on_bulb = "off"
             intruder_alert = message("user", "gate", "",
                                      isthere_intruder.data,
                                      usertogate.timestamp(self.offset))
             usertogate.deliver_mail(self.offset, intruder_alert)
         self.change_state(self.lit_bubidnum, self.should_i_turn_on_bulb,
                           pipeboxes)
         if oldbulbstatus != self.should_i_turn_on_bulb:
             newbulbstatus = message("backend", "gate", "bulb_change",
                                     self.should_i_turn_on_bulb,
                                     gatetobackend.timestamp(self.offset))
             gatetobackend.deliver_mail(self.offset, newbulbstatus)
         else:
             oldstatus = message("backend", "gate", "no_change", "",
                                 gatetobackend.timestamp(self.offset))
             gatetobackend.deliver_mail(self.offset, oldstatus)
         userstatus = usertogate.wait_on_query(self.offset, "gate")
         if berkeley_or_lamport == "lamport":  #This performs the Lamport logical clocks algorithm: everytime the process
             current_time = usertogate.timestamp(
                 self.offset
             )  #recieves a new message it compares it's own clock time to that of the
             if userstatus.time > current_time:  #timestamp in the message; if the time in the timestamp is larger than the
                 self.offset = userstatus.time - current_time + 1  #time in its own logical clock then it knows that it is a contradicton and
         oldpresencestatus = self.mode  #it must add the difference between (plus 1) to its current offset
         if userstatus.data == "home":
             self.mode = "home"
         elif userstatus.data == "away":
             self.mode = "away"
         if oldpresencestatus != self.mode:
             newpresencestatus = message(
                 "backend", "gate", "presence_change", self.mode,
                 gatetobackend.timestamp(self.offset))
             gatetobackend.deliver_mail(self.offset, newpresencestatus)
         else:
             oldstatus = message("backend", "gate", "no_change", "",
                                 gatetobackend.timestamp(self.offset))
             gatetobackend.deliver_mail(self.offset, oldstatus)
         doorstatus = pipeboxes[self.door_detidnum].wait_on_query(
             self.offset, "gate")
         if berkeley_or_lamport == "lamport":  #This performs the Lamport logical clocks algorithm: everytime the process
             current_time = pipeboxes[self.door_detidnum].timestamp(
                 self.offset
             )  #recieves a new message it compares it's own clock time to that of the
             if doorstatus.time > current_time:  #timestamp in the message; if the time in the timestamp is larger than the
                 self.offset = doorstatus.time - current_time + 1  #time in its own logical clock then it knows that it is a contradicton and
         if doorstatus.data == "statechange":  #it must add the difference between (plus 1) to its current offset
             newdoorstatus = message("backend", "gate", "door_change",
                                     self.mode,
                                     gatetobackend.timestamp(self.offset))
             gatetobackend.deliver_mail(self.offset, newdoorstatus)
         else:
             oldstatus = message("backend", "gate", "no_change", "",
                                 gatetobackend.timestamp(self.offset))
             gatetobackend.deliver_mail(self.offset, oldstatus)
         if berkeley_or_lamport == "berkeley":
             self.time = berkeley_clock_synch("gate", self.offset, parent,
                                              children, status)