func (sv *FrontServer) initActors() error { config := sv.config //initialize actor system if err := yue.Init(&yue.Config{ DatabaseAddress: config.DBHost, CertPath: config.DBCertPath, HostAddress: config.NodeIpv4Address, }); err != nil { return err } yue.Register("/hello", yue.ActorConfig{ SpawnConfig: yue.SpawnConfig{ Factory: yue.InmemoryExecuterFactory{ Constructor: actors.NewHelloActor, }, }, Size: 1, }, "channer") go func() { var r string if err := yue.Call("/hello", "Hello", "actor-caller", &r); err != nil { log.Fatalf("err should not happen: %v %v", err) } else if r != "hello, actor-caller! from channer" { log.Fatalf("unexpected response: %v", r) } }() return nil }
func ListTopic(dbif Dbif, req *proto.TopicListRequest) ([]*proto.Model_Topic, error) { var limit int32 if req.Limit > 0 { limit = req.Limit if limit > TOPIC_FETCH_LIMIT { limit = TOPIC_FETCH_LIMIT } } else { limit = TOPIC_FETCH_LIMIT } locale := req.Locale if len(locale) <= 0 { locale = "all" } var entries []HotEntry if err := yue.Call(fmt.Sprintf("/hot/%s", locale), "Query", req.Bucket, req.Query, nil, req.OffsetScore, req.OffsetId, limit, &entries); err != nil { return nil, err } if len(entries) <= 0 { return make([]*proto.Model_Topic, 0), nil } ids := make([]string, len(entries)) for i, ent := range entries { ids[i] = strconv.FormatUint(uint64(ent.Id), 10) } tps, err := dbif.Select(Topic{}, dbm.Stmt(`select * from %s.topics where id in (%s)`, strings.Join(ids, ","))) if err != nil { return nil, err } ret := make([]*proto.Model_Topic, len(tps)) for i, tp := range tps { tpp := tp.(*Topic).Model_Topic tpp.Point = entries[i].Score tpp.Vote = entries[i].Vote ret[i] = &tpp } return ret, nil }