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


Golang PeerPipe.Send方法代碼示例

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


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

示例1: send

func send(packet common.Packet, pipe *common.PeerPipe) error {

	log.Current.Tracef("SyncProxy.send(): sending packet %s to peer (TCP %s)", packet.Name(), pipe.GetAddr())
	if !pipe.Send(packet) {
		return common.NewError(common.SERVER_ERROR, fmt.Sprintf("SyncProxy.listen(): Fail to send packet %s to peer (TCP %s)",
			packet.Name(), pipe.GetAddr()))
	}

	return nil
}
開發者ID:couchbase,項目名稱:gometa,代碼行數:10,代碼來源:discovery.go

示例2: AddFollower

//
// Add a follower and starts a listener for the follower.
// If the leader is terminated, the pipe between leader
// and follower will also be closed.
//
func (l *Leader) AddFollower(fid string,
	peer *common.PeerPipe,
	o *observer) {
	l.mutex.Lock()
	defer l.mutex.Unlock()

	// AddFollower requires holding the mutex such that the leader thread
	// will not be sending new proposal or commit (see sendProposal() and
	// sendCommit()) to followers.  This allow this function to copy the
	// proposals and commits from the observer queue into the pipe, before
	// the leader has a chance to send new messages.
	for packet := o.getNext(); packet != nil; packet = o.getNext() {

		switch request := packet.(type) {
		case ProposalMsg:
			txid := common.Txnid(request.GetTxnid())
			log.Current.Debugf("Leader.AddFollower() : send observer's packet %s, txid %d", packet.Name(), txid)
		case CommitMsg:
			txid := common.Txnid(request.GetTxnid())
			log.Current.Debugf("Leader.AddFollower() : send observer's packet %s, txid %d", packet.Name(), txid)
		}

		peer.Send(packet)
	}

	// Rememeber the old message listener and start a new one.
	oldListener, ok := l.followers[fid]

	listener := newListener(fid, peer, l)
	l.followers[fid] = listener
	go listener.start()

	// kill the old message listener
	if ok && oldListener != nil {
		log.Current.Debugf("Leader.AddFollower() : old Listener found for follower %s.  Terminating old listener", fid)
		oldListener.terminate()
	} else {
		// notify a brand new follower (not just replacing an existing one)
		l.changech <- true
	}
}
開發者ID:couchbase,項目名稱:gometa,代碼行數:46,代碼來源:leader.go


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