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


Golang Messages.SetMessageTerm方法代碼示例

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


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

示例1: Queue

/*
Queue is used to append client messages when the node is a leader.

NOTE: The lock is not held in this method as we do not touch commitIndex or waitingReaders
*/
func (clog *CommitLog) Queue(term int64, modelMsgs model.Messages) (IDs []int64, err error) {
	//clog.node_log("Queueing messages: %v\n", msgs)

	//modelMsgs := model.MessagesFromClientData(msgs)

	if modelMsgs.GetCount() == 0 {
		clog.node_log("No messages found from client for Queue.")
		return nil, errors.New("No messages found to be Queued.")
	}

	err = modelMsgs.SetMessageTerm(term)
	if err != nil {
		clog.node_log("Error setting terms for messages: %v\n", err)
		return nil, err
	}

	// Stick them on the end of the log
	lastIndex, err := clog.log.AppendMessages(modelMsgs)
	if err != nil {
		clog.node_log("Error writing message to log in Queue: %v\n", err)
		return nil, err
	} else if clog.syncPolicy == WRITE_SYNC {
		err = clog.log.Sync()
		if err != nil {
			clog.node_log("Error syncing written message to log in Queue: %v\n", err)
			return nil, err
		}
	}

	//time.Sleep(time.Millisecond * 500)

	numMessages := modelMsgs.GetCount()
	results := make([]int64, numMessages)

	// If log has one message, and two are added: lastIndex (3) - len (modelMsgs (2)) + 1 = 2
	index := lastIndex - int64(numMessages) + 1
	for i := 0; i < numMessages; i++ {
		results[i] = index
		index++
	}

	return results, nil
}
開發者ID:owlfish,項目名稱:forestbus-server,代碼行數:48,代碼來源:commitlog.go


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