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-17 08:31:15 +08:00
|
|
|
func (dnll *DataNodeLocationList) Head() *DataNode {
|
|
|
|
return dnll.list[0]
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dnll *DataNodeLocationList) Add(loc *DataNode) bool {
|
2012-09-11 08:08:52 +08:00
|
|
|
for _, dnl := range dnll.list {
|
2012-09-12 16:07:23 +08:00
|
|
|
if loc.Ip == dnl.Ip && loc.Port == dnl.Port {
|
2012-09-17 08:31:15 +08:00
|
|
|
return false
|
2012-09-11 08:08:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
dnll.list = append(dnll.list, loc)
|
2012-09-17 08:31:15 +08:00
|
|
|
return true
|
2012-09-11 08:08:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|