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 deregisterBCS(conn, msg): print("-> Deregister BCS :: #{id:d}".format(id=msg.Id)) component = components.get(msg.Id) component.dead = True if config.is_backup: # Notify upstream server about deregistering backup_msg = copy.deepcopy(msg) backup_servers.parentQueueAppend(backup_msg)
def messageStatus(conn, msg): component = components.get(msg.Id) assert component != None, "component id not registered" assert not component.dead, "component already dead" print("-> Status :: #{id:d} ({type:s})".format(type=component.type, id=component.id)) component.touch() component.parseStatus(msg) component.sendMessages(conn)
def removeInactiveBackup(): if config.child_id != None: component = components.get(config.child_id) if not component.isAlive(2 * config.timeout * 1000): config.child_id = None config.child_address = None config.child_port = None deregister_msg = copy.deepcopy(component.registerMessage) deregister_msg.Id = component.id deregister_msg.Deregister = True if config.is_backup: backup_servers.parentQueueAppend(deregister_msg) else: backup_servers.registerQueueAppend(deregister_msg)