()
| 24 | } |
| 25 | |
| 26 | func InitController() error { |
| 27 | protocol := &tcp.DefaultProtocol{} |
| 28 | protocol.SetMaxPacketSize(uint32(GlobalConfig.MAX_PACKET_SIZE)) |
| 29 | server := tcp.NewAsyncTCPServer(GlobalConfig.TCP_BIND, &callback{}, protocol) |
| 30 | if err := server.ListenAndServe(); err != nil { |
| 31 | return err |
| 32 | } |
| 33 | lg.Info("Start listen: %v", GlobalConfig.TCP_BIND) |
| 34 | |
| 35 | controller = &Controller{server, |
| 36 | NewTaskPool(GlobalConfig.TASK_POOL_SIZE), |
| 37 | NewResultPool(GlobalConfig.RESULT_POOL_SIZE), |
| 38 | NewNodePool(), |
| 39 | make(map[int]*EventPool), |
| 40 | new(sync.RWMutex), |
| 41 | cache.New(time.Duration(GlobalConfig.LOAD_STRATEGIES_INTERVAL)*time.Second, 30*time.Second), |
| 42 | cache.New(10*time.Minute, 10*time.Minute)} |
| 43 | |
| 44 | go controller.processStrategyResultForever() |
| 45 | go controller.processStrategyEventForever() |
| 46 | go controller.checkNodesForever() |
| 47 | go controller.startHttpServer() |
| 48 | go controller.loadStrategiesForever() |
| 49 | |
| 50 | return nil |
| 51 | } |
| 52 | |
| 53 | //checkNodesForever 持续运行检查节点函数,并维护节点数组 |
| 54 | func (c *Controller) checkNodesForever() { |
no test coverage detected