コード例 #1
0
/******************************************************************************
* 概述:     判断并创建一个新的sds socket
* 函数名:    insertSocket
* 返回值:
* 参数列表:  参数名          参数类型      取值范围     描述
*            pp             *dzhyun.SDSEndpoint
*
*******************************************************************************/
func (this *DataCache) insertSocket(pp *dzhyun.SDSEndpoint) {
	if pp == nil || pp.GetBusiPath() != DEFAULT_SdsServicepath {
		return
	}
	this.msocMutex.Lock()
	defer this.msocMutex.Unlock()
	if _, ok := this.mSocketGroup[(*pp).GetNodeName()]; !ok {
		newZmqSocket := &ZmqSocket{}
		if reqUrl, subUrl, err := this.getSdsAddr((*pp).GetInterface()); err == nil {
			this.msocketSerial++
			if err := newZmqSocket.Init(reqUrl, subUrl, this.mzmq, this.msocketSerial, this.mSocketsStateCh); err == nil {
				this.mSocketGroup[(*pp).GetNodeName()] = newZmqSocket
				log4.Debug("insertSocket size=%d nodename=%s %s %s", len(this.mSocketGroup), (*pp).GetNodeName(), reqUrl, subUrl)
			}
		}

	}
}
コード例 #2
0
/******************************************************************************
* 概述:     按序插入数组
* 函数名:   SortMinPoints
* 返回值:
* 参数列表:  参数名          参数类型                取值范围       描述
*           arr            []*dzhyun.SDSEndpoint               操作的数组
*           arrSize        *int                                数组当前元素个数
*           arrCap         int                                 数组的总容量大小
*           insertData     *dzhyun.SDSEndpoint                 被插入的元素
*
*******************************************************************************/
func SortMinPoints(arr *[]*dzhyun.SDSEndpoint, arrSize *int, arrCap int, insertData *dzhyun.SDSEndpoint) {
	pos := *arrSize
	for i := *arrSize - 1; i >= 0; i-- {
		if insertData.GetLoading() < (*arr)[i].GetLoading() {
			if i+1 < arrCap {
				(*arr)[i+1] = (*arr)[i]
			}
			pos = i
		} else {
			break
		}
	}

	if pos <= arrCap-1 {
		(*arr)[pos] = insertData
	}
	if (*arrSize) < arrCap {
		(*arrSize)++
	}
}