You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2021/06/14 11:04:02 UTC

[dubbo-go] branch 1.5 updated: Fix: add listen routerChain when NewBaseDirectory (#1250)

This is an automated email from the ASF dual-hosted git repository.

alexstocks pushed a commit to branch 1.5
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git


The following commit(s) were added to refs/heads/1.5 by this push:
     new 695ff65  Fix: add listen routerChain when NewBaseDirectory (#1250)
695ff65 is described below

commit 695ff6526066abeebf57e59ceef1b28b232d053b
Author: 氕氘氚 <cj...@163.com>
AuthorDate: Mon Jun 14 19:03:54 2021 +0800

    Fix: add listen routerChain when NewBaseDirectory (#1250)
    
    * listen routerChain when NewBaseDirectory
    
    * fix add start loop by goroutine
    
    * fix golangci-lint err
    
    Co-authored-by: 氕氘氚 <ch...@bilibili.com>
---
 cluster/directory/base_directory.go | 7 +++++--
 cluster/router/chain.go             | 2 ++
 cluster/router/chain/chain.go       | 4 ++--
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/cluster/directory/base_directory.go b/cluster/directory/base_directory.go
index 0d530d9..8e3039f 100644
--- a/cluster/directory/base_directory.go
+++ b/cluster/directory/base_directory.go
@@ -44,12 +44,15 @@ type BaseDirectory struct {
 }
 
 // NewBaseDirectory Create BaseDirectory with URL
-func NewBaseDirectory(url *common.URL) BaseDirectory {
-	return BaseDirectory{
+func NewBaseDirectory(url *common.URL) (dir BaseDirectory) {
+	dir = BaseDirectory{
 		url:         url,
 		destroyed:   atomic.NewBool(false),
 		routerChain: &chain.RouterChain{},
 	}
+	// start to listen notify
+	go dir.routerChain.Loop()
+	return
 }
 
 // RouterChain Return router chain in directory
diff --git a/cluster/router/chain.go b/cluster/router/chain.go
index 3c6da4d..384fece 100644
--- a/cluster/router/chain.go
+++ b/cluster/router/chain.go
@@ -33,6 +33,8 @@ type Chain interface {
 	GetNotifyChan() chan struct{}
 	// Detect Route State
 	DetectRoute() (RouteSnapshot, error)
+	// listens on events to update the address cache
+	Loop()
 }
 
 // RouteSnapshot is the snapshot of Route
diff --git a/cluster/router/chain/chain.go b/cluster/router/chain/chain.go
index f573c68..1be7242 100644
--- a/cluster/router/chain/chain.go
+++ b/cluster/router/chain/chain.go
@@ -185,7 +185,7 @@ func (c *RouterChain) printRouteSnapshot(cache *InvokerCache, url *common.URL, i
 
 // loop listens on events to update the address cache  when it receives notification
 // from address update,
-func (c *RouterChain) loop() {
+func (c *RouterChain) Loop() {
 	ticker := time.NewTicker(timeInterval)
 	for {
 		select {
@@ -318,7 +318,7 @@ func NewRouterChain(url *common.URL) (*RouterChain, error) {
 		chain.url = url
 	}
 
-	go chain.loop()
+	go chain.Loop()
 	return chain, nil
 }