Skip to content
Snippets Groups Projects
Commit 0703cedf authored by vito.he's avatar vito.he
Browse files

Add: more comment

parent 2fd25ffb
No related branches found
No related tags found
No related merge requests found
...@@ -77,9 +77,7 @@ type FacadeBasedRegistry interface { ...@@ -77,9 +77,7 @@ type FacadeBasedRegistry interface {
InitListeners() InitListeners()
} }
/* // BaseRegistry is a common logic abstract for registry. It implement Registry interface.
* BaseRegistry is a common logic abstract for registry. It implement Registry interface.
*/
type BaseRegistry struct { type BaseRegistry struct {
context context.Context context context.Context
facadeBasedRegistry FacadeBasedRegistry facadeBasedRegistry FacadeBasedRegistry
...@@ -91,6 +89,7 @@ type BaseRegistry struct { ...@@ -91,6 +89,7 @@ type BaseRegistry struct {
services map[string]common.URL // service name + protocol -> service config, for store the service registered services map[string]common.URL // service name + protocol -> service config, for store the service registered
} }
// InitBaseRegistry for init some local variables and set BaseRegistry's subclass to it
func (r *BaseRegistry) InitBaseRegistry(url *common.URL, facadeRegistry FacadeBasedRegistry) Registry { func (r *BaseRegistry) InitBaseRegistry(url *common.URL, facadeRegistry FacadeBasedRegistry) Registry {
r.URL = url r.URL = url
r.birth = time.Now().UnixNano() r.birth = time.Now().UnixNano()
...@@ -100,6 +99,7 @@ func (r *BaseRegistry) InitBaseRegistry(url *common.URL, facadeRegistry FacadeBa ...@@ -100,6 +99,7 @@ func (r *BaseRegistry) InitBaseRegistry(url *common.URL, facadeRegistry FacadeBa
return r return r
} }
// GetUrl for get registry's url
func (r *BaseRegistry) GetUrl() common.URL { func (r *BaseRegistry) GetUrl() common.URL {
return *r.URL return *r.URL
} }
...@@ -116,6 +116,7 @@ func (r *BaseRegistry) Destroy() { ...@@ -116,6 +116,7 @@ func (r *BaseRegistry) Destroy() {
r.closeRegisters() r.closeRegisters()
} }
// Register implement interface registry to register
func (r *BaseRegistry) Register(conf common.URL) error { func (r *BaseRegistry) Register(conf common.URL) error {
var ( var (
ok bool ok bool
...@@ -148,6 +149,7 @@ func (r *BaseRegistry) service(c common.URL) string { ...@@ -148,6 +149,7 @@ func (r *BaseRegistry) service(c common.URL) string {
return url.QueryEscape(c.Service()) return url.QueryEscape(c.Service())
} }
// RestartCallBack for reregister when reconnect
func (r *BaseRegistry) RestartCallBack() bool { func (r *BaseRegistry) RestartCallBack() bool {
// copy r.services // copy r.services
...@@ -172,6 +174,7 @@ func (r *BaseRegistry) RestartCallBack() bool { ...@@ -172,6 +174,7 @@ func (r *BaseRegistry) RestartCallBack() bool {
return flag return flag
} }
// register for register url to registry, include init params
func (r *BaseRegistry) register(c common.URL) error { func (r *BaseRegistry) register(c common.URL) error {
var ( var (
err error err error
...@@ -213,6 +216,7 @@ func (r *BaseRegistry) register(c common.URL) error { ...@@ -213,6 +216,7 @@ func (r *BaseRegistry) register(c common.URL) error {
return nil return nil
} }
// providerRegistry for provider role do
func (r *BaseRegistry) providerRegistry(c common.URL, params url.Values) (string, string, error) { func (r *BaseRegistry) providerRegistry(c common.URL, params url.Values) (string, string, error) {
var ( var (
dubboPath string dubboPath string
...@@ -259,6 +263,7 @@ func (r *BaseRegistry) providerRegistry(c common.URL, params url.Values) (string ...@@ -259,6 +263,7 @@ func (r *BaseRegistry) providerRegistry(c common.URL, params url.Values) (string
return dubboPath, rawURL, nil return dubboPath, rawURL, nil
} }
// consumerRegistry for consumer role do
func (r *BaseRegistry) consumerRegistry(c common.URL, params url.Values) (string, string, error) { func (r *BaseRegistry) consumerRegistry(c common.URL, params url.Values) (string, string, error) {
var ( var (
dubboPath string dubboPath string
...@@ -293,6 +298,7 @@ func (r *BaseRegistry) consumerRegistry(c common.URL, params url.Values) (string ...@@ -293,6 +298,7 @@ func (r *BaseRegistry) consumerRegistry(c common.URL, params url.Values) (string
return dubboPath, rawURL, nil return dubboPath, rawURL, nil
} }
// sleepWait...
func sleepWait(n int) { func sleepWait(n int) {
wait := time.Duration((n + 1) * 2e8) wait := time.Duration((n + 1) * 2e8)
if wait > MaxWaitInterval { if wait > MaxWaitInterval {
...@@ -301,7 +307,7 @@ func sleepWait(n int) { ...@@ -301,7 +307,7 @@ func sleepWait(n int) {
time.Sleep(wait) time.Sleep(wait)
} }
//Subscribe :subscribe from registry, event will notify by notifyListener // Subscribe :subscribe from registry, event will notify by notifyListener
func (r *BaseRegistry) Subscribe(url *common.URL, notifyListener NotifyListener) { func (r *BaseRegistry) Subscribe(url *common.URL, notifyListener NotifyListener) {
n := 0 n := 0
for { for {
...@@ -337,6 +343,7 @@ func (r *BaseRegistry) Subscribe(url *common.URL, notifyListener NotifyListener) ...@@ -337,6 +343,7 @@ func (r *BaseRegistry) Subscribe(url *common.URL, notifyListener NotifyListener)
} }
} }
// closeRegisters close and remove registry client and reset services map
func (r *BaseRegistry) closeRegisters() { func (r *BaseRegistry) closeRegisters() {
r.cltLock.Lock() r.cltLock.Lock()
defer r.cltLock.Unlock() defer r.cltLock.Unlock()
......
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