Source code for distlock2.imp_0.checker

"""
Module **distlock2.imp_0.checker** has class Checker, a skeleton checker
for a distlock2 implementation, to be fleshed out by you.
"""

[docs]class Checker(): """ Maintain global state of a distributed system of two distlock2.imp_0 nodes. Receive updates from the nodes and check that the updated global state satisfies desired global assertions. Instantiated by distlock2.servicetester when testing the distributed system. """ def __init__(self, tester, argv): """Example global state: - tester: the tester that started this instance; allows access to tester.service variables. - status[j]: current value of node j's status variable; 'T' (thinking), 'H' (hungry), or 'E' (eating) """ self.tester = tester self.status = ['T', 'T'] def handle_event(self, event): """ RPC-called by a node to convey event e. Update global state according to e and check whether it still statisfies desired assertions. - Example event: (j, new_value_of_status[j]). - Example assertion: Inv(status[0] == 'E' and status[1] == 'E') """ # print("handle_event called:", event, flush=True) j, st = event self.status[j] = st # check assertion if self.status[0] == 'E' and self.status[1] == 'E': print("distlock2.imp_0.node", j, "event invalid", flush=True) else: print("distlock2.imp_0.node", j, "event valid", flush=True)
###### end class Checker ######################