Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
22a7f0099
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2022
22a7f0099
Commits
0703cedf
Commit
0703cedf
authored
5 years ago
by
vito.he
Browse files
Options
Downloads
Patches
Plain Diff
Add: more comment
parent
2fd25ffb
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
registry/base_registry.go
+11
-4
11 additions, 4 deletions
registry/base_registry.go
with
11 additions
and
4 deletions
registry/base_registry.go
+
11
−
4
View file @
0703cedf
...
@@ -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
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment