Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions addresspool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ type Pool struct {

status map[string]string
onceMonitor sync.Once
quit chan struct{}
onceQuit sync.Once
}

func (p *Pool) Close() {
p.onceQuit.Do(func() {
close(p.quit)
})
}

// NewPool Get registry pool instance
Expand All @@ -57,6 +65,16 @@ func (p *Pool) appendAddressToStatus(addresses []string) {
}
}

func (p *Pool) ResetAddress(addresses []string) {
p.mutex.Lock()
defer p.mutex.Unlock()
p.defaultAddress = removeDuplicates(addresses)
p.diffAzAddress = []string{}
p.sameAzAddress = []string{}
p.status = make(map[string]string)
p.appendAddressToStatus(addresses)
}

func (p *Pool) SetAddressByInstances(instances []*discovery.MicroServiceInstance) error {
p.mutex.Lock()
defer p.mutex.Unlock()
Expand Down Expand Up @@ -179,14 +197,14 @@ func (p *Pool) monitor() {
}
}
ticker := time.NewTicker(interval * time.Second)
quit := make(chan struct{})
p.quit = make(chan struct{})

go func() {
for {
select {
case <-ticker.C:
p.checkConnectivity()
case <-quit:
case <-p.quit:
ticker.Stop()
return
}
Expand Down
Loading