當前位置: 首頁>>代碼示例>>Golang>>正文


Golang GetTribblesReply.Tribbles方法代碼示例

本文整理匯總了Golang中github.com/cmu440/tribbler/rpc/tribrpc.GetTribblesReply.Tribbles方法的典型用法代碼示例。如果您正苦於以下問題:Golang GetTribblesReply.Tribbles方法的具體用法?Golang GetTribblesReply.Tribbles怎麽用?Golang GetTribblesReply.Tribbles使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/cmu440/tribbler/rpc/tribrpc.GetTribblesReply的用法示例。


在下文中一共展示了GetTribblesReply.Tribbles方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: GetTribblesBySubscription

func (ts *tribServer) GetTribblesBySubscription(args *tribrpc.GetTribblesArgs, reply *tribrpc.GetTribblesReply) error {
	if ts.userExist(args.UserID) == false {
		reply.Status = tribrpc.NoSuchUser
		return nil
	}
	subscriptions, err := ts.ls.GetList(util.FormatSubListKey(args.UserID))
	if err != nil {
		reply.Status = tribrpc.OK
		reply.Tribbles = make([]tribrpc.Tribble, 0)
		return nil
	}
	reply.Tribbles = make([]tribrpc.Tribble, 0)
	mychan := make(chan []tribrpc.Tribble, 1000)
	go func() {
		for i := 0; i < len(subscriptions); i++ {
			user := subscriptions[i]
			go func() {
				tribbles, _ := ts.GetAllTribblesByUser(user)
				mychan <- tribbles
			}()
		}
	}()
	for i := 0; i < len(subscriptions); i++ {
		tribbles := <-mychan
		reply.Tribbles = append(reply.Tribbles, tribbles...)
	}
	reply.Status = tribrpc.OK
	reply.Tribbles = prepareTribbles(reply.Tribbles)
	return nil
}
開發者ID:thuhujin,項目名稱:Tribbler,代碼行數:30,代碼來源:tribserver_impl.go

示例2: GetTribblesBySubscription

func (ts *tribServer) GetTribblesBySubscription(args *tribrpc.GetTribblesArgs, reply *tribrpc.GetTribblesReply) error {
	user := args.UserID

	_, err := ts.Libstore.Get(user)
	switch err {
	case nil: // expected case, do nothing
	case libstore.ErrorKeyNotFound:
		reply.Status = tribrpc.NoSuchUser
		return nil
	default:
		return err
	}

	subscListKey := makeSubscListKey(user)
	subscList, err := ts.Libstore.GetList(subscListKey)
	switch err {
	case nil:
	case libstore.ErrorKeyNotFound:
		reply.Tribbles = make([]tribrpc.Tribble, 0)
		reply.Status = tribrpc.OK
		return nil
	default:
		return err
	}

	tribbles, err := ts.getTribsFromSubs(subscList)
	if err != nil { // ignore error
		// return err
	}

	reply.Tribbles = tribbles
	reply.Status = tribrpc.OK
	return nil
}
開發者ID:oldady,項目名稱:ds_p2,代碼行數:34,代碼來源:tribserver_impl.go

示例3: GetTribbles

func (ts *tribServer) GetTribbles(args *tribrpc.GetTribblesArgs, reply *tribrpc.GetTribblesReply) error {
	//fmt.Println("get tribble begin!")
	UserKey := GenerateUserKey(args.UserID)

	_, err := ts.lib.Get(UserKey)
	if err != nil {
		reply.Status = tribrpc.NoSuchUser
		reply.Tribbles = nil
		return nil
	}

	TribListKey := GenerateTribListKey(args.UserID)
	TribIDs, err := ts.lib.GetList(TribListKey)
	if err != nil {
		//reply.Status = tribrpc.NoSuchUser
		//return nil
		reply.Status = tribrpc.OK
		return nil
	}

	//for i := 0; i < len(TribIDs); i++ {
	//	fmt.Println(TribIDs[i])
	//}

	var length int
	length = len(TribIDs)
	//fmt.Println("actual length:",length)
	//log.Print(length)
	if length > 100 {
		length = 100
	}
	reply.Tribbles = make([]tribrpc.Tribble, length)

	for i := 0; i < length; i++ {
		//TribIDKey := GenerateTribIDKey(args.UserID, TribIDs[len(TribIDs)-1-i])
		TribIDKey := TribIDs[len(TribIDs)-1-i]
		val, err := ts.lib.Get(TribIDKey)
		if err != nil {
			//	continue
			reply.Status = tribrpc.NoSuchUser
			return errors.New("get invalid tribble")
		}
		if val == "" {
			return errors.New("empty string!!!!")
		}
		json.Unmarshal([]byte(val), &(reply.Tribbles[i]))
	}

	reply.Status = tribrpc.OK
	//for i := 0; i < len(reply.Tribbles); i++ {
	//	fmt.Println("result of getting tribbles")
	//	fmt.Print(reply.Tribbles[i].UserID+" ")
	//	//fmt.Print(reply.Tribbles[i].Posted)
	//	fmt.Print(reply.Tribbles[i].Contents)
	//	fmt.Println()
	//}
	return nil
}
開發者ID:oldady,項目名稱:Tribbler,代碼行數:58,代碼來源:tribserver_impl.go

示例4: GetTribblesBySubscription

func (ts *tribServer) GetTribblesBySubscription(args *tribrpc.GetTribblesArgs, reply *tribrpc.GetTribblesReply) error {
	if args == nil {
		return errors.New("ts: Can't getSubscription nil")
	}
	if reply == nil {
		return errors.New("ts: Can't reply with nil in getSubscription")
	}

	_, err := ts.ls.Get(util.FormatUserKey(args.UserID))
	if err != nil {
		reply.Status = tribrpc.NoSuchUser
		reply.Tribbles = make([]tribrpc.Tribble, 0, 0)
		return nil
	}

	users, err := ts.ls.GetList(util.FormatSubListKey(args.UserID))
	if err != nil {
		reply.Status = tribrpc.OK
		reply.Tribbles = make([]tribrpc.Tribble, 0, 0)
		return nil
	}

	postIDs := make([]string, 0)
	for _, userID := range users {
		lst, err := ts.ls.GetList(util.FormatTribListKey(userID))
		if err == nil {
			postIDs = append(postIDs, lst...)
		}
	}

	tmp := tribbleIDs(postIDs)

	sort.Sort(tmp)
	tribbleIdsChrono := []string(tmp)

	length := 100
	if len(tribbleIdsChrono) < 100 {
		length = len(tribbleIdsChrono)
	}

	tribbles := make([]tribrpc.Tribble, length)
	var tribTmp tribrpc.Tribble
	i := 0
	for i < length {
		trib, err := ts.ls.Get(tribbleIdsChrono[i])
		if err == nil {
			json.Unmarshal([]byte(trib), &tribTmp)
			tribbles[i] = tribTmp
			i += 1 // If error occurs, we do NOT increment i
		}
	}
	reply.Status = tribrpc.OK
	reply.Tribbles = tribbles
	return nil
}
開發者ID:iedwardwangi,項目名稱:Tribbler,代碼行數:55,代碼來源:tribserver_impl.go

示例5: GetTribbles

/*
-getList, formatTribListKey to get all the post keys
-Slice it off at 100
-reverse it or wtv (if needed)
-Get() with that post key, and get the marshalled tribble
*/
func (ts *tribServer) GetTribbles(args *tribrpc.GetTribblesArgs, reply *tribrpc.GetTribblesReply) error {

	if DBG {
		fmt.Println("-----> GetTribbles")
	}
	var usrID string = args.UserID

	//check if user present in server
	_, err := ts.libStore.Get(util.FormatUserKey(usrID))

	if err != nil {
		switch err.Error() {
		case WRONG_SERVER:
			fmt.Println("ERROR: WRONG SERVER in tribserver")
			return errors.New("Wrong server contacted!")

		case KEY_NOT_FOUND:
			reply.Status = tribrpc.NoSuchUser
			return nil

		default:
			fmt.Println("ERROR in tribserver: wrong error message received")
		}
	}

	postKeysList, err := ts.libStore.GetList(util.FormatTribListKey(usrID))

	if err != nil {
		//fmt.Println("Could not get list of postKeys for user")
		//return empty tribble list, as the list is not yet created (0 tribbles)

		switch err.Error() {
		case KEY_NOT_FOUND:
			reply.Status = tribrpc.OK
			reply.Tribbles = make([]tribrpc.Tribble, 0)
			return nil
		case WRONG_SERVER:
			fmt.Println("WRONG SERVER CONTACTED!")
			return nil
		default:
			fmt.Println("ERROR in tribserver: wrong error message received!")
			return nil
		}

	}

	reply.Status = tribrpc.OK
	reply.Tribbles = ts.getTribbleList(postKeysList)

	return nil
}
開發者ID:aditij1,項目名稱:p2aditijakkamat,代碼行數:57,代碼來源:tribserver_impl.go

示例6: GetTribbles

func (ts *tribServer) GetTribbles(args *tribrpc.GetTribblesArgs, reply *tribrpc.GetTribblesReply) error {
	if ts.userExist(args.UserID) == false {
		reply.Status = tribrpc.NoSuchUser
		return nil
	}
	tribbles, err := ts.GetAllTribblesByUser(args.UserID)
	if err != nil {
		reply.Status = tribrpc.OK
		reply.Tribbles = make([]tribrpc.Tribble, 0)
		return nil
	}
	reply.Status = tribrpc.OK
	reply.Tribbles = prepareTribbles(tribbles)
	return nil
}
開發者ID:thuhujin,項目名稱:Tribbler,代碼行數:15,代碼來源:tribserver_impl.go

示例7: GetTribblesBySubscription

func (ts *tribServer) GetTribblesBySubscription(args *tribrpc.GetTribblesArgs, reply *tribrpc.GetTribblesReply) error {
	userkey := util.FormatUserKey(args.UserID)
	_, userErr := ts.libstore.Get(userkey)

	if userErr != nil {
		reply.Status = tribrpc.NoSuchUser
	} else {
		reply.Status = tribrpc.OK
		subskey := util.FormatSubListKey(args.UserID)
		subsList, _ := ts.libstore.GetList(subskey)

		totalTribList := make(Tribbles, 0)
		for i := 0; i < len(subsList); i++ {
			curUser := subsList[i]
			curtribList := ts.GetTribblesOneUser(curUser)

			for j := 0; j < len(curtribList); j++ {
				totalTribList = append(totalTribList, curtribList[j])
			}
			//totalTribList = append(totalTribList, curtribList)
		}

		sort.Sort(totalTribList)
		totalLen := len(totalTribList)
		if totalLen > 100 {
			totalLen = 100
		}
		reply.Tribbles = make(Tribbles, totalLen)
		for j := 0; j < totalLen; j++ {
			reply.Tribbles[j] = totalTribList[j]
		}
	}
	return nil

}
開發者ID:wentianqi7,項目名稱:15640-distributed-systems,代碼行數:35,代碼來源:tribserver_impl.go

示例8: GetTribblesBySubscription

/*
-format sublist
*/
func (ts *tribServer) GetTribblesBySubscription(args *tribrpc.GetTribblesArgs, reply *tribrpc.GetTribblesReply) error {

	if DBG {
		fmt.Println("-----> GetTribblesBySubscription")
	}
	var usrID string = args.UserID

	//check if user present in server
	_, err := ts.libStore.Get(util.FormatUserKey(usrID))

	if err != nil {
		switch err.Error() {
		case WRONG_SERVER:
			fmt.Println("ERROR: WRONG SERVER in tribserver")
			return errors.New("Wrong server contacted!")

		case KEY_NOT_FOUND:
			reply.Status = tribrpc.NoSuchUser
			return nil

		default:
			fmt.Println("ERROR in tribserver: wrong error message received")
		}
	}

	//get list of subscribers
	subscrList, err := ts.libStore.GetList(util.FormatSubListKey(usrID))

	if err != nil {
		//return err
		fmt.Println("No subscribers, or error getting list of subscribers")
		reply.Status = tribrpc.OK
		return nil
	}

	//initialise empty slice of all postKeys from subscribers
	var allPostKeys []string = make([]string, 0)

	//populate allPostKeys
	for _, currUser := range subscrList {
		currPostKeys, err := ts.libStore.GetList(util.FormatTribListKey(currUser))

		if err == nil {
			allPostKeys = append(allPostKeys, currPostKeys...)

		} else {
			//fmt.Println("0 tribs for user detected")
		}
	}

	sort.Sort(PostByTime(allPostKeys))

	//choose most recent posts, and get tribbles
	var tribList []tribrpc.Tribble = ts.getTribbleList(allPostKeys)

	reply.Tribbles = tribList
	reply.Status = tribrpc.OK
	return nil

}
開發者ID:aditij1,項目名稱:p2aditijakkamat,代碼行數:63,代碼來源:tribserver_impl.go

示例9: GetTribbles

func (ts *tribServer) GetTribbles(args *tribrpc.GetTribblesArgs, reply *tribrpc.GetTribblesReply) error {
	key := util.FormatUserKey(args.UserID)
	if ts.checkIfKnown(key) {
		triblist_key := util.FormatTribListKey(args.UserID)
		post_ids, err := ts.storage.GetList(triblist_key)
		if err != nil {
			post_ids = []string{}
		}
		sort.Sort(ByChrono(post_ids))
		bound := min(100, len(post_ids))
		tribs := make([]tribrpc.Tribble, bound)
		for i, v := range post_ids[0:bound] {
			postStr, err := ts.storage.Get(v)
			if err != nil {
				return err
			}
			trib := tribrpc.Tribble{}
			json.Unmarshal([]byte(postStr), &trib)
			tribs[i] = trib
		}
		reply.Tribbles = tribs
		reply.Status = tribrpc.OK
	} else {
		reply.Status = tribrpc.NoSuchUser
	}
	return nil
}
開發者ID:jbuckman,項目名稱:p2-440,代碼行數:27,代碼來源:tribserver_impl.go

示例10: GetTribbles

func (ts *tribServer) GetTribbles(args *tribrpc.GetTribblesArgs, reply *tribrpc.GetTribblesReply) error {
	userid := args.UserID
	useridkey := util.FormatUserKey(userid)

	_, userExists := ts.ls.Get(useridkey)

	if userExists != nil {
		reply.Status = tribrpc.NoSuchUser
		return nil
	}

	userTribListKey := util.FormatTribListKey(userid)
	tribbleIdList, err := ts.ls.GetList(userTribListKey)

	if err != nil {
		reply.Status = tribrpc.OK
		reply.Tribbles = nil
		return nil
	}

	tmp := tribbleIDs(tribbleIdList)
	sort.Sort(tmp)
	tribbleIdsChrono := []string(tmp)

	// Calculate the length of the tribbles we want to get
	length := 100
	if len(tribbleIdsChrono) < 100 {
		length = len(tribbleIdsChrono)
	}
	allTribbles := make([]tribrpc.Tribble, length)
	var tribTmp tribrpc.Tribble
	i := 0
	for i < length {
		trib, err := ts.ls.Get(tribbleIdsChrono[i])
		if err == nil {
			json.Unmarshal([]byte(trib), &tribTmp)
			allTribbles[i] = tribTmp
			i += 1 // If error occurs, we do NOT increment i
		}
	}

	reply.Status = tribrpc.OK
	reply.Tribbles = allTribbles

	return nil

}
開發者ID:iedwardwangi,項目名稱:Tribbler,代碼行數:47,代碼來源:tribserver_impl.go

示例11: GetTribblesBySubscription

func (ts *tribServer) GetTribblesBySubscription(args *tribrpc.GetTribblesArgs, reply *tribrpc.GetTribblesReply) error {
	UserKey := GenerateUserKey(args.UserID)

	_, err := ts.lib.Get(UserKey)
	if err != nil {
		reply.Status = tribrpc.NoSuchUser
		reply.Tribbles = nil
		return nil
	}

	SubsKey := GenerateSubsKey(args.UserID)
	SubsList, err := ts.lib.GetList(SubsKey)
	if err != nil {
		//reply.Status = tribrpc.NoSuchUser
		reply.Status = tribrpc.OK
		reply.Tribbles = nil
		return nil
	}

	for i := 0; i < len(SubsList); i++ {
		var Subargs tribrpc.GetTribblesArgs
		var Subreply tribrpc.GetTribblesReply

		Subargs.UserID = SubsList[i]
		err = ts.GetTribbles(&Subargs, &Subreply)
		if err != nil {
			return err
		}

		reply.Tribbles = append(reply.Tribbles, Subreply.Tribbles...)
	}

	var tempTrib Tribs
	tempTrib = reply.Tribbles
	sort.Sort(tempTrib)
	if len(tempTrib) > 100 {
		reply.Status = tribrpc.OK
		reply.Tribbles = tempTrib[:100]
	} else {
		reply.Status = tribrpc.OK
		reply.Tribbles = tempTrib
	}

	return nil
}
開發者ID:oldady,項目名稱:Tribbler,代碼行數:45,代碼來源:tribserver_impl.go

示例12: GetTribblesBySubscription

func (ts *tribServer) GetTribblesBySubscription(args *tribrpc.GetTribblesArgs, reply *tribrpc.GetTribblesReply) error {
	LOGE.Printf("GetTribblesBySubscription:: args=%s\n", string(marshal(*args)))
	userIDKey := GetUserKey(args.UserID)
	_, err := ts.lib.Get(userIDKey)
	if err != nil {
		reply.Status = tribrpc.NoSuchUser
		reply.Tribbles = nil
		return nil
	}

	userTribleListKey := GetsSubsKey(args.UserID)
	subsList, err := ts.lib.GetList(userTribleListKey)
	if err != nil {
		reply.Status = tribrpc.OK
		reply.Tribbles = nil
		return nil
	}

	for i := 0; i < len(subsList); i++ {
		var subArgs tribrpc.GetTribblesArgs
		var subReply tribrpc.GetTribblesReply

		subArgs.UserID = subsList[i]

		err = ts.GetTribbles(&subArgs, &subReply)
		if err != nil {
			return err
		}
		reply.Tribbles = append(reply.Tribbles, subReply.Tribbles...)
	}

	var tempTribbles Tribs
	tempTribbles = reply.Tribbles
	sort.Sort(tempTribbles)
	if len(tempTribbles) > 100 {
		reply.Status = tribrpc.OK
		reply.Tribbles = tempTribbles[:100]
	} else {
		reply.Status = tribrpc.OK
		reply.Tribbles = tempTribbles
	}
	LOGE.Printf("GetTribblesBySubscription:: reply=%s\n", string(marshal(reply)))
	return nil
}
開發者ID:201101050424,項目名稱:Tribbler,代碼行數:44,代碼來源:tribserver_impl.go

示例13: GetTribbles

func (ts *tribServer) GetTribbles(args *tribrpc.GetTribblesArgs, reply *tribrpc.GetTribblesReply) error {
	user := args.UserID

	_, err := ts.Libstore.Get(user)
	switch err {
	case nil: // expected case, do nothing
	case libstore.ErrorKeyNotFound:
		reply.Status = tribrpc.NoSuchUser
		return nil
	default:
		return err
	}

	tribListKey := makeTribListKey(user)

	totalHashIds, err := ts.Libstore.GetList(tribListKey)
	switch err {
	case nil:
	case libstore.ErrorKeyNotFound:
		reply.Tribbles = make([]tribrpc.Tribble, 0)
		reply.Status = tribrpc.OK
		return nil
	default:
		return err
	}

	// reverse hash Id to achieve most recent tribbles first.
	length := Min(len(totalHashIds), maxGetTribbleNum)
	hashIds := make([]string, length)
	for i := range hashIds {
		hashIds[i] = totalHashIds[len(totalHashIds)-i-1]
	}

	tribValues, err := ts.getTribValuesFromHashIds(user, hashIds)
	if err != nil { // ignore error
		// return err
	}

	reply.Tribbles = makeTribbles(user, tribValues)
	reply.Status = tribrpc.OK
	return nil
}
開發者ID:oldady,項目名稱:ds_p2,代碼行數:42,代碼來源:tribserver_impl.go

示例14: GetTribblesBySubscription

func (ts *tribServer) GetTribblesBySubscription(args *tribrpc.GetTribblesArgs, reply *tribrpc.GetTribblesReply) error {
	// Getsublist by key
	// Get tribble list by user_ids in sublist
	// sort the tribble list by the timestamp
	// retrive the first 100 tribble (Be careful about the delete operation)
	user_id := util.FormatUserKey(args.UserID)

	// If the user_id doesn't exist
	// Reture NoSuchUser
	_, err := ts.lib_store.Get(user_id)
	if err != nil {
		reply.Status = tribrpc.NoSuchUser
		return nil
	}

	// Get user's subscription_list
	user_id_list := util.FormatSubListKey(args.UserID)
	// list of IDs
	user_list, _ := ts.lib_store.GetList(user_id_list)

	if user_list == nil {
		reply.Status = tribrpc.OK
		return nil
	}

	// Get tribble_ids from the user_ids in the subscription list
	tribble_id_list := make([]string, 0)
	for _, usr_id := range user_list {
		t_id_list, err := ts.lib_store.GetList(util.FormatTribListKey(usr_id))
		if err == nil {
			tribble_id_list = append(tribble_id_list, t_id_list...)
		}
	}

	sort.Sort(SortTribbleByTimestamp(tribble_id_list))

	counter := 0
	tribble_list := make([]tribrpc.Tribble, 100)
	for _, tid := range tribble_id_list {
		tribble, err := ts.lib_store.Get(tid)
		if err == nil {
			json.Unmarshal([]byte(tribble), &tribble_list[counter])
			counter += 1
		}
		if counter >= 100 {
			break
		}
	}

	reply.Status = tribrpc.OK
	reply.Tribbles = tribble_list[:counter]
	return nil
}
開發者ID:mallocanswer,項目名稱:Tribbler,代碼行數:53,代碼來源:tribserver_impl.go

示例15: GetTribbles

func (ts *tribServer) GetTribbles(args *tribrpc.GetTribblesArgs, reply *tribrpc.GetTribblesReply) error {
	userkey := util.FormatUserKey(args.UserID)

	// Make sure user exists
	if _, eu := ts.ls.Get(userkey); eu != nil {
		reply.Status = tribrpc.NoSuchUser
		return nil
	}

	// Store list of marshalled Tribbles in lst.  Return empty list if user had no subscriptions.
	var lst []string
	var err error
	if lst, err = ts.ls.GetList(util.FormatTribListKey(args.UserID)); err != nil {
		reply.Status = tribrpc.OK
		reply.Tribbles = make([]tribrpc.Tribble, 0)
		return nil
	}

	// Find out how many posts we will return
	var recentPosts []string
	if len(lst) > 100 {
		recentPosts = lst[len(lst)-100:]
	} else {
		recentPosts = lst
	}

	// Loop through this users Tribbles in reverse order and grab up to 100
	tribbles := make([]tribrpc.Tribble, len(recentPosts))
	var mtribble string
	var tribble tribrpc.Tribble
	for i := 0; i < len(tribbles); i++ {
		mtribble, _ = ts.ls.Get(recentPosts[len(tribbles)-1-i])
		json.Unmarshal([]byte(mtribble), &tribble)
		tribbles[i] = tribble
	}
	reply.Status = tribrpc.OK
	reply.Tribbles = tribbles
	return nil
}
開發者ID:pyurky,項目名稱:p2,代碼行數:39,代碼來源:tribserver_impl.go


注:本文中的github.com/cmu440/tribbler/rpc/tribrpc.GetTribblesReply.Tribbles方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。