示例#1
0
func RunAgentLocal(a agent.Agent, x, y, energy int) *AgentProxy {
	p2a := make(chan link.Message, 10)
	a2p := make(chan link.Message, 10)

	proxy := NewAgentProxy(p2a, a2p)
	proxy.SetState(cagent.NewAgentState(a.Id(), 0, *geo.NewPoint(x, y), Energy(energy)))
	go func() {
		agent.Run(a, a2p, p2a)
	}()
	return proxy
}
示例#2
0
func NewSendMachine(freq uint8, agent agent.Agent) *SendMachine {
	self := &SendMachine{
		freq:       freq,
		logger:     logflow.NewSource(fmt.Sprintf("agent/wifi/send/%d", agent.Id())),
		agent:      agent,
		backoff:    BACKOFF,
		wait:       ROUTE_HOLDTIME,
		state:      2,
		next_state: 0,
		sendq:      NewDataGramQueue(),
	}
	return self
}
示例#3
0
func (ri *ReportInfo) MonitorHandler(ag agent.Agent, conn net.Conn, msg map[string]interface{}) {
	log.Println("MonitorHandler is called")
	rwLock.Lock()
	defer rwLock.Unlock()
	// msg == nil表示是定期执行的任务.
	if msg == nil {
		if ag.IsMaster() {
			return
		}
		monitorAgent, ok := ag.(*agent.MonitorAgent)
		if ok == false {
			seelog.Criticalf("MonitorHandler: Fail to convert to MonitorAgent,exit...")
			os.Exit(0)
		}
		serverInfo := monitorAgent.GetServerInfo()
		if serverInfo != nil {
			infoAsString := ri.getServerInfoAsString(serverInfo)
			ri.client.Sadd(serverInfo["serverType"].(string), []byte(serverInfo["id"].(string)))
			ri.client.Set(serverInfo["id"].(string), []byte(infoAsString))
			ri.client.Expire(serverInfo["id"].(string), int64(2*ri.interval))
		}

	}
}