in elastictransport/connection.go [221:282]
func (cp *statusConnectionPool) Update(connections []*Connection) error {
if len(connections) == 0 {
return errors.New("no connections provided, connection pool left untouched")
}
// Remove hosts that are no longer in the new list of connections
for i := 0; i < len(cp.live); i++ {
found := false
for _, c := range connections {
if cp.live[i].Cmp(c) {
found = true
break
}
}
if !found {
// Remove item; https://github.com/golang/go/wiki/SliceTricks
copy(cp.live[i:], cp.live[i+1:])
cp.live = cp.live[:len(cp.live)-1]
i--
}
}
// Remove hosts that are no longer in the dead list of connections
for i := 0; i < len(cp.dead); i++ {
found := false
for _, c := range connections {
if cp.dead[i].Cmp(c) {
found = true
break
}
}
if !found {
copy(cp.dead[i:], cp.dead[i+1:])
cp.dead = cp.dead[:len(cp.dead)-1]
i--
}
}
// Add new connections that are not already in the live or dead list
for _, c := range connections {
found := false
for _, conn := range cp.live {
if conn.Cmp(c) {
found = true
break
}
}
for _, conn := range cp.dead {
if conn.Cmp(c) {
found = true
break
}
}
if !found {
cp.live = append(cp.live, c)
}
}
return nil
}