func (this *InspectorHandle) Handle(sess *tcp.Session, data []byte) { defer func() { if err := recover(); err != nil { lg.Error("Recovered in HandleMessage", err) } }() mt := types.AlarmMessageType(data[0]) lg.Debug("Receive %v %v", types.AlarmMessageTypeText[mt], string(data[1:])) switch mt { case types.ALAR_MESS_GET_INSPECTOR_TASK_RESP: get_task_resp := &types.GetTasksResp{} if err := get_task_resp.Decode(data[1:]); err != nil { lg.Error(err.Error()) return } inspector.taskPool.PutTasks(get_task_resp.AlarmTasks) default: lg.Error("Unknown option: %v", mt) } }
func (this *ControllerHandle) Handle(sess *tcp.Session, data []byte) { defer func() { if err := recover(); err != nil { lg.Error("Recovered in HandleMessage", err) } }() mt := types.AlarmMessageType(data[0]) switch mt { case types.ALAR_MESS_INSPECTOR_HEARTBEAT: lg.Info("Receive %v %v", types.AlarmMessageTypeText[mt], string(data[1:])) heartbeat := &types.HeartBeat{} if err := heartbeat.Decode(data[1:]); err != nil { lg.Error(err.Error()) return } controller.refreshNode(heartbeat) case types.ALAR_MESS_INSPECTOR_TASK_REQUEST: tasks_resp := getInspectorTask() sess.Send(types.AlarmPack(types.ALAR_MESS_INSPECTOR_TASKS, tasks_resp)) case types.ALAR_MESS_INSPECTOR_RESULT: lg.Info("Receive %v %v", types.AlarmMessageTypeText[mt], string(data[1:])) result := &types.StrategyResult{} if err := result.Decode(data[1:]); err != nil { lg.Error(err.Error()) return } switch result.Priority { case types.PRIORITY_HIGH_LEVEL: controller.highResultPool.PutResult(result) case types.PRIORITY_MIDDLE_LEVEL: controller.lowResultPool.PutResult(result) case types.PRIORITY_LOW_LEVEL: controller.lowResultPool.PutResult(result) default: lg.Error("Unknown priority: %v", result.Priority) } default: lg.Error("Unknown option: %v", mt) } }