def Run(): from SBPS import ProtocolReactor global socketSubscribe, socketPublish, MyServerType, context, countPendingCmd, lockPendingCmd context = zmq.Context() socketSubscribe = context.socket(zmq.SUB) socketPublish = context.socket(zmq.PUB) AddSubscribeServer(SBDB.GetServers(SBDB.CV_TYPE_SERVER_FUNCTION)) AddSubscribeServer(SBDB.GetServers(SBDB.CV_TYPE_SERVER_SUPERVISION), SBDB.CV_TYPE_SERVER_SUPERVISION) socketPublish.bind("tcp://*:%d" % (PORT_PUBSUB)) RegistFilter(TTYPE_SERVER, 0) RegistFilter(TTYPE_SERVER, MyServerID) if MyServerType == SBDB.CV_TYPE_SERVER_SUPERVISION: threading.Thread(target=ThreadCheckMaps).start() RegistFilter(TTYPE_ONLINEOFFLINE) while not ProtocolReactor.bReactorStopped: try: [head, from_filter, body] = socketSubscribe.recv_multipart() with lockPendingCmd: if countPendingCmd < Config.count_connection: countPendingCmd = countPendingCmd + 1 threads.deferToThread(ProcessMessage, head, from_filter, body) except: pass print("InternalMessage.Run() return")
def RunServerMessage(message): if message.operation==OPER_LOAD: AddSubscribeServer(SBDB.GetServers(SBDB.CV_TYPE_SERVER_FUNCTION)) AddSubscribeServer(SBDB.GetServers(SBDB.CV_TYPE_SERVER_SUPERVISION),SBDB.CV_TYPE_SERVER_SUPERVISION) if message.fromType==TTYPE_MANAGEMENT: message.fromType=TTYPE_SERVER message.Send() SBDB.UpdateActiveTimeServer(MyServerID)