def parseMessageBCS(msg): # Forward messages if type(msg) == messages.Register: backup_servers.backupQueueAppend(copy.deepcopy(msg)) else: backup_servers.registerQueueAppend(copy.deepcopy(msg)) # Parse if type(msg) == messages.Register: if not msg.Deregister: print("% -> Register component #{:d} - {:s}".format(msg.Id, msg.Type)) components.add(msg) else: print("% -> Deregister component #{:d} - {:s}".format(msg.Id, msg.Type)) component = components.get(msg.Id) component.dead = True problems.release(component.id) elif type(msg) == messages.SolveRequest: print("% -> SolveRequest") problems.add(msg) elif type(msg) == messages.SolvePartialProblems: print("% -> SolvePartialProblems") problem = problems.list[msg.Id] problem.updateWithDivide(msg) elif type(msg) == messages.Solutions: print("% -> Solutions") problem = problems.list[msg.Id] problem.updateWithSolutions(msg) elif type(msg) == messages.NoOperation: print("% -> NoOperation") # update backup server list else: print("% ? {:s}".format(str(msg)))
def messageSolveRequest(conn, msg): id = problems.add(msg) print("-> AddProblem :: #{id:d} Type: {type:s} Timeout: {timeout:d}".format(type=msg.ProblemType, timeout=msg.SolvingTimeout, id=id)) problemStartTime[id] = current_time_ms() response = messages.SolveRequestResponse(id) conn.send(response) backup_msg = copy.deepcopy(msg) backup_msg.Id = id backup_servers.backupQueueAppend(backup_msg)