コード例 #1
0
/******************************************************************************
* 概述:     更新树的部分节点,如果是sds的就创建socket
* 函数名:    UpdatePoints
* 返回值:
* 参数列表:  参数名          参数类型      取值范围     描述
*            res            *dzhyun.SDSResponse
*
*******************************************************************************/
func (this *DataCache) UpdatePoints(res *dzhyun.SDSResponse) {
	if res.Endpoints == nil {
		return
	}
	ps := &res.Endpoints
	subName := res.GetSubName()
	mainregChans := make([]chan dzhyun.SDSEndpoint, 0)

	this.mregRWMutex.RLock()
	defer this.mregRWMutex.RUnlock()
	this.mpointGroup.GetRegChans(&mainregChans, subName)

	for i := 0; i < len(*ps); i++ {
		subregChans := make([]chan dzhyun.SDSEndpoint, 0)
		this.insertSocket((*ps)[i])
		if (*ps)[i].GetState() == DEFAULT_PointStateOk {
			this.mpointGroup.InsertPoint((*ps)[i], &subregChans, subName)
		} else {
			this.mpointGroup.DelPoint((*ps)[i], &subregChans, subName)
		}
		for j := 0; j < len(mainregChans); j++ {
			select {
			case mainregChans[j] <- *(*ps)[i]:
			default:
				{
					log4.Error("chan full, so lose data")
				}
			}
		}
		for k := 0; k < len(subregChans); k++ {
			select {
			case subregChans[k] <- *(*ps)[i]:
			default:
				{
					log4.Error("chan full, so lose data")
				}
			}
		}
	}
}
コード例 #2
0
/******************************************************************************
* 概述:     刷新树的一个分支,要与sds一致
* 函数名:    RefleshPoints
* 返回值:
* 参数列表:  参数名          参数类型      取值范围     描述
*            Servicepath    string
*            res            *dzhyun.SDSResponse
*
*******************************************************************************/
func (this *DataCache) RefleshPoints(Servicepath string, res *dzhyun.SDSResponse) {
	oldppoint := this.mpointGroup.SearchAll(Servicepath)
	var newppoint *[]*dzhyun.SDSEndpoint
	if res.Endpoints == nil {
		newppoint = nil
	} else {
		newppoint = &res.Endpoints
	}

	tmpMap := make(map[string]*dzhyun.SDSEndpoint)
	for j := 0; newppoint != nil && j < len(*newppoint); j++ {
		this.insertSocket((*newppoint)[j])
		tmpMap[(*newppoint)[j].GetBusiPath()+"/"+(*newppoint)[j].GetNodeName()] = (*newppoint)[j]
	}

	for i := 0; oldppoint != nil && i < len(*oldppoint); i++ {
		str := (*oldppoint)[i].GetBusiPath() + "/" + (*oldppoint)[i].GetNodeName()
		if value, ok := tmpMap[str]; ok {
			if value.GetLoading() == (*oldppoint)[i].GetLoading() && value.GetState() == (*oldppoint)[i].GetState() {
				delete(tmpMap, str)
			}
		} else {
			if (*oldppoint)[i].State == nil {
				(*oldppoint)[i].State = new(int32)
			}
			*(*oldppoint)[i].State = DEFAULT_PointStateDel
			tmpMap[str] = &(*oldppoint)[i]
		}
	}

	subName := res.GetSubName()
	mainregChans := make([]chan dzhyun.SDSEndpoint, 0)

	this.mregRWMutex.RLock()
	defer this.mregRWMutex.RUnlock()
	this.mpointGroup.GetRegChans(&mainregChans, subName)

	for _, value := range tmpMap {
		subregChans := make([]chan dzhyun.SDSEndpoint, 0)
		if value.GetState() == DEFAULT_PointStateOk {
			this.mpointGroup.InsertPoint(value, &subregChans, subName)
		} else {
			this.mpointGroup.DelPoint(value, &subregChans, subName)
		}
		for j := 0; j < len(mainregChans); j++ {
			select {
			case mainregChans[j] <- *value:
			default:
				{
					log4.Error("chan full, so lose data")
				}
			}

		}
		for k := 0; k < len(subregChans); k++ {
			select {
			case subregChans[k] <- *value:
			default:
				{
					log4.Error("chan full, so lose data")
				}
			}
		}
	}

}