Skip to content
Snippets Groups Projects
Commit 91ccf0aa authored by 邹毅贤's avatar 邹毅贤
Browse files

fix test case and add some comment

parent e2366847
No related branches found
No related tags found
No related merge requests found
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
package directory package directory
import ( import (
"github.com/apache/dubbo-go/common/logger"
"sync" "sync"
) )
...@@ -32,12 +31,13 @@ import ( ...@@ -32,12 +31,13 @@ import (
"github.com/apache/dubbo-go/common" "github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/constant" "github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/extension" "github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/common/logger"
"github.com/dubbogo/gost/container/set" "github.com/dubbogo/gost/container/set"
) )
var routerURLSet = gxset.NewSet() var routerURLSet = gxset.NewSet()
// BaseDirectory ... // BaseDirectory Abstract implementation of Directory: Invoker list returned from this Directory's list method have been filtered by Routers
type BaseDirectory struct { type BaseDirectory struct {
url *common.URL url *common.URL
destroyed *atomic.Bool destroyed *atomic.Bool
...@@ -57,7 +57,7 @@ func (dir *BaseDirectory) SetRouterChain(routerChain router.Chain) { ...@@ -57,7 +57,7 @@ func (dir *BaseDirectory) SetRouterChain(routerChain router.Chain) {
dir.routerChain = routerChain dir.routerChain = routerChain
} }
// NewBaseDirectory ... // NewBaseDirectory Create BaseDirectory with URL
func NewBaseDirectory(url *common.URL) BaseDirectory { func NewBaseDirectory(url *common.URL) BaseDirectory {
return BaseDirectory{ return BaseDirectory{
url: url, url: url,
...@@ -66,12 +66,12 @@ func NewBaseDirectory(url *common.URL) BaseDirectory { ...@@ -66,12 +66,12 @@ func NewBaseDirectory(url *common.URL) BaseDirectory {
} }
} }
// GetUrl ... // GetUrl Get URL
func (dir *BaseDirectory) GetUrl() common.URL { func (dir *BaseDirectory) GetUrl() common.URL {
return *dir.url return *dir.url
} }
// GetDirectoryUrl ... // GetDirectoryUrl Get URL instance
func (dir *BaseDirectory) GetDirectoryUrl() *common.URL { func (dir *BaseDirectory) GetDirectoryUrl() *common.URL {
return dir.url return dir.url
} }
...@@ -106,7 +106,7 @@ func (dir *BaseDirectory) SetRouters(urls []*common.URL) { ...@@ -106,7 +106,7 @@ func (dir *BaseDirectory) SetRouters(urls []*common.URL) {
rc.AddRouters(routers) rc.AddRouters(routers)
} }
// Destroy ... // Destroy Destroy
func (dir *BaseDirectory) Destroy(doDestroy func()) { func (dir *BaseDirectory) Destroy(doDestroy func()) {
if dir.destroyed.CAS(false, true) { if dir.destroyed.CAS(false, true) {
dir.mutex.Lock() dir.mutex.Lock()
...@@ -115,7 +115,7 @@ func (dir *BaseDirectory) Destroy(doDestroy func()) { ...@@ -115,7 +115,7 @@ func (dir *BaseDirectory) Destroy(doDestroy func()) {
} }
} }
// IsAvailable ... // IsAvailable Once directory init finish, it will change to true
func (dir *BaseDirectory) IsAvailable() bool { func (dir *BaseDirectory) IsAvailable() bool {
return !dir.destroyed.Load() return !dir.destroyed.Load()
} }
......
...@@ -27,7 +27,7 @@ type staticDirectory struct { ...@@ -27,7 +27,7 @@ type staticDirectory struct {
invokers []protocol.Invoker invokers []protocol.Invoker
} }
// NewStaticDirectory ... // NewStaticDirectory Create a new staticDirectory with invokers
func NewStaticDirectory(invokers []protocol.Invoker) *staticDirectory { func NewStaticDirectory(invokers []protocol.Invoker) *staticDirectory {
var url common.URL var url common.URL
...@@ -53,6 +53,7 @@ func (dir *staticDirectory) IsAvailable() bool { ...@@ -53,6 +53,7 @@ func (dir *staticDirectory) IsAvailable() bool {
return true return true
} }
// List List invokers
func (dir *staticDirectory) List(invocation protocol.Invocation) []protocol.Invoker { func (dir *staticDirectory) List(invocation protocol.Invocation) []protocol.Invoker {
l := len(dir.invokers) l := len(dir.invokers)
invokers := make([]protocol.Invoker, l, l) invokers := make([]protocol.Invoker, l, l)
...@@ -66,6 +67,7 @@ func (dir *staticDirectory) List(invocation protocol.Invocation) []protocol.Invo ...@@ -66,6 +67,7 @@ func (dir *staticDirectory) List(invocation protocol.Invocation) []protocol.Invo
return routerChain.Route(invokers, &dirUrl, invocation) return routerChain.Route(invokers, &dirUrl, invocation)
} }
// Destroy Destroy
func (dir *staticDirectory) Destroy() { func (dir *staticDirectory) Destroy() {
dir.BaseDirectory.Destroy(func() { dir.BaseDirectory.Destroy(func() {
for _, ivk := range dir.invokers { for _, ivk := range dir.invokers {
......
...@@ -40,7 +40,7 @@ const ( ...@@ -40,7 +40,7 @@ const (
listenableRouterDefaultPriority = ^int64(0) listenableRouterDefaultPriority = ^int64(0)
) )
//ListenableRouter Abstract router which listens to dynamic configuration // listenableRouter Abstract router which listens to dynamic configuration
type listenableRouter struct { type listenableRouter struct {
conditionRouters []*ConditionRouter conditionRouters []*ConditionRouter
routerRule *RouterRule routerRule *RouterRule
...@@ -49,6 +49,7 @@ type listenableRouter struct { ...@@ -49,6 +49,7 @@ type listenableRouter struct {
priority int64 priority int64
} }
// RouterRule Get RouterRule instance from listenableRouter
func (l *listenableRouter) RouterRule() *RouterRule { func (l *listenableRouter) RouterRule() *RouterRule {
return l.routerRule return l.routerRule
} }
...@@ -84,6 +85,7 @@ func newListenableRouter(url *common.URL, ruleKey string) (*AppRouter, error) { ...@@ -84,6 +85,7 @@ func newListenableRouter(url *common.URL, ruleKey string) (*AppRouter, error) {
return l, nil return l, nil
} }
// Process Process config change event , generate routers and set them to the listenableRouter instance
func (l *listenableRouter) Process(event *config_center.ConfigChangeEvent) { func (l *listenableRouter) Process(event *config_center.ConfigChangeEvent) {
logger.Infof("Notification of condition rule, change type is:[%s] , raw rule is:[%v]", event.ConfigType, event.Value) logger.Infof("Notification of condition rule, change type is:[%s] , raw rule is:[%v]", event.ConfigType, event.Value)
if remoting.EventTypeDel == event.ConfigType { if remoting.EventTypeDel == event.ConfigType {
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
package match package match
import ( import (
"context"
"testing" "testing"
) )
......
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