Example #1
0
func addPeer(def *coredef.PeerDefine) {

	switch def.GetType() {
	case "connector":
		if def.GetPeerCount() > 1 {

			var i int32
			for i = 1; i <= def.GetPeerCount(); i++ {
				rawAddPeer(def, i)
			}

		} else {

			rawAddPeer(def, def.GetPeerIndex())
		}

	case "acceptor":
		rawAddPeer(def, SvcIndex)
	}

}
Example #2
0
func rawAddPeer(def *coredef.PeerDefine, peerIndex int32) {
	/// 运行时信息
	peer := NewPeerData(def, pbcodec.GetInterface())
	peer.Address = def.GetAddress()
	peer.NotifyAddress = def.GetNotifyAddress()
	peer.Index = peerIndex
	peer.ID = MakeServiceID(def.GetType(), def.GetName(), peerIndex)

	// 创建peer实现
	p := CreatePeer(def.GetImplementor(), def.GetType(), peer)

	if p == nil {
		log.Printf("peer %s implementor not found, %s", peer.ID, def.GetImplementor())
		return
	}

	// 记录
	peerMap[peer.ID] = p.(IPeer)

	log.Printf("peer %s ready", peer.ID)
}