Exemplo n.º 1
0
func (this *Inspector) GetInspectorTasksForever() {
	for {
		if len(this.taskPool.tasks) == 0 && this.session != nil {
			this.session.Send(types.AlarmPack(types.ALAR_MESS_GET_INSPECTOR_TASK, types.NewHeartBeat(this.session.LocalAddr(), GetHostName())))
		}
		time.Sleep(time.Millisecond * 100)
	}
}
Exemplo n.º 2
0
func (this *Inspector) HeartBeatForever() {
	for {
		if this.session != nil {
			this.session.Send(types.AlarmPack(types.ALAR_MESS_HEARTBEAT, types.NewHeartBeat(this.session.LocalAddr(), GetHostName())))
		}
		time.Sleep(time.Second * 30)
	}
}
Exemplo n.º 3
0
func (this *Inspector) SendResultForever() {
	for {
		select {
		case result := <-this.resultPool.results:
			this.session.Send(types.AlarmPack(types.ALAR_MESS_SEND_RESULT, result))
		default:
			time.Sleep(time.Millisecond * 100)
		}
	}
}
Exemplo n.º 4
0
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)
	}
}