本文整理汇总了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
}
示例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
}
}