2012-09-10 15:18:07 +08:00
|
|
|
package topology
|
|
|
|
|
2012-09-11 08:08:52 +08:00
|
|
|
import ()
|
2012-09-10 15:18:07 +08:00
|
|
|
|
|
|
|
type DataNodeLocationList struct {
|
2012-09-11 08:08:52 +08:00
|
|
|
list []*DataNode
|
2012-09-10 15:18:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewDataNodeLocationList() *DataNodeLocationList {
|
2012-09-11 08:08:52 +08:00
|
|
|
return &DataNodeLocationList{}
|
2012-09-10 15:18:07 +08:00
|
|
|
}
|
|
|
|
|
2012-09-11 08:08:52 +08:00
|
|
|
func (dnll *DataNodeLocationList) Add(loc *DataNode) {
|
|
|
|
for _, dnl := range dnll.list {
|
2012-09-12 16:07:23 +08:00
|
|
|
if loc.Ip == dnl.Ip && loc.Port == dnl.Port {
|
2012-09-11 08:08:52 +08:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dnll.list = append(dnll.list, loc)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dnll *DataNodeLocationList) Refresh(freshThreshHold int64) {
|
|
|
|
var changed bool
|
|
|
|
for _, dnl := range dnll.list {
|
|
|
|
if dnl.lastSeen < freshThreshHold {
|
|
|
|
changed = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if changed {
|
|
|
|
var l []*DataNode
|
|
|
|
for _, dnl := range dnll.list {
|
|
|
|
if dnl.lastSeen >= freshThreshHold {
|
|
|
|
l = append(l, dnl)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dnll.list = l
|
|
|
|
}
|
2012-09-10 15:18:07 +08:00
|
|
|
}
|