import time import datetime import multiprocessing import json #import numpy as np from concurrent import futures from Util import setup_logger, MyLog, sg, get_operation, get_operation_name, get_result_name, WriteSet, Set_WriteSet_Executed import grpc import banking_pb2 import banking_pb2_grpc ONE_DAY = datetime.timedelta(days=1) logger = setup_logger("Customer") client_lock = multiprocessing.Lock() class Customer: """ Customer class definition """ def __init__(self, _id, events): # unique ID of the Customer self.id = _id # events from the input self.events = events # a list of received messages used for debugging purpose self.recvMsg = list() # pointer for the stub self.stub = None
import time import datetime import sys import multiprocessing import json from concurrent import futures from Util import setup_logger, MyLog, sg, get_operation, get_operation_name, get_result_name, SLEEP_SECONDS import grpc import banking_pb2 import banking_pb2_grpc ONE_DAY = datetime.timedelta(days=1) logger = setup_logger("Branch") # A constant used to indicate that the Branch must not propagate an operation. This is because a Branch receiving a message # cannot distinguish between an operation is coming from a client or another branch or it has been received already. # Without this control, the branches would keep propagating operations in an infinite loop. By setting this value after # the first propagation, it is not spread further. DO_NOT_PROPAGATE = -1 class Branch(banking_pb2_grpc.BankingServicer): """ Branch class definition """ def __init__(self, ID, balance, branches): # unique ID of the Branch self.id = ID # replica of the Branch's balance self.balance = balance
event_dict["eventid"] = curr_event_id event_dict["data"] = [] event_dict["data"].append({ 'clock': curr_record['clock'], 'name': curr_record['name'], }) try: if (PRETTY_JSON): if any((event_dict.get('data'))): json.dump(event_dict, outfile, indent=2) else: if any((event_dict.get('data'))): json.dump(event_dict, outfile) except TypeError: pass outfile.close() # Just in case for worker in workers: worker.terminate() MyLog(logger, f'[Main] Program Ended successfully.') logger = setup_logger("Main") if __name__ == '__main__': MyLog(logger, "[Main] Logger initialised") main()