Skip to content
Snippets Groups Projects
Commit dea76beb authored by aliiohs's avatar aliiohs
Browse files

fix cycle import bug

parent 50e42d0a
No related branches found
No related tags found
No related merge requests found
......@@ -21,7 +21,7 @@ import (
"github.com/apache/dubbo-go/cluster"
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/config"
"github.com/dubbogo/gost/container"
"go.uber.org/atomic"
"sync"
)
......@@ -29,13 +29,14 @@ import (
"github.com/apache/dubbo-go/common"
)
var RouterUrlSet = container.NewSet()
type BaseDirectory struct {
url *common.URL
ConsumerUrl *common.URL
destroyed *atomic.Bool
routers []cluster.Router
mutex sync.Mutex
once sync.Once
}
func NewBaseDirectory(url *common.URL) BaseDirectory {
......@@ -67,15 +68,18 @@ func (dir *BaseDirectory) SetRouters(routers []cluster.Router) {
dir.routers = routers
}
func (dir *BaseDirectory) Routers() []cluster.Router {
dir.once.Do(func() {
var routers []cluster.Router
rs := RouterUrlSet.Values()
for _, r := range rs {
factory := extension.GetRouterFactory(dir.GetUrl().Protocol)
router, err := factory.Router(config.GetRouterUrl())
router, err := factory.Router(r.(*common.URL))
if err == nil {
dir.routers = append(dir.routers, router)
}
})
return dir.routers
routers = append(routers, router)
}
return append(dir.routers, routers...)
}
func (dir *BaseDirectory) Destroy(doDestroy func()) {
......
......@@ -18,6 +18,7 @@ package config
import (
"encoding/base64"
"github.com/apache/dubbo-go/cluster/directory"
"io/ioutil"
"os"
"path"
......@@ -79,10 +80,11 @@ func RouterInit(confRouterFile string) error {
}
logger.Debugf("provider config{%#v}\n", providerConfig)
directory.RouterUrlSet.Add(initRouterUrl())
return nil
}
func GetRouterUrl() *common.URL {
func initRouterUrl() *common.URL {
mutex.Lock()
if routerConfig == nil {
confRouterFile := os.Getenv(constant.CONF_ROUTER_FILE_PATH)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment