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
04ee0b96
Commit
04ee0b96
authored
4 years ago
by
fangyincheng
Browse files
Options
Downloads
Patches
Plain Diff
Mod: fix comments
parent
4657f3d1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
common/rpc_service.go
+36
-21
36 additions, 21 deletions
common/rpc_service.go
with
36 additions
and
21 deletions
common/rpc_service.go
+
36
−
21
View file @
04ee0b96
...
...
@@ -153,6 +153,7 @@ type serviceMap struct {
interfaceMap
map
[
string
][]
*
Service
// interface -> service
}
// GetService get a service defination by protocol and name
func
(
sm
*
serviceMap
)
GetService
(
protocol
,
name
string
)
*
Service
{
sm
.
mutex
.
RLock
()
defer
sm
.
mutex
.
RUnlock
()
...
...
@@ -175,6 +176,7 @@ func (sm *serviceMap) GetInterface(interfaceName string) []*Service {
return
nil
}
// Register register a service by @interfaceName and @protocol
func
(
sm
*
serviceMap
)
Register
(
interfaceName
,
protocol
string
,
rcvr
RPCService
)
(
string
,
error
)
{
if
sm
.
serviceMap
[
protocol
]
==
nil
{
sm
.
serviceMap
[
protocol
]
=
make
(
map
[
string
]
*
Service
)
...
...
@@ -222,33 +224,46 @@ func (sm *serviceMap) Register(interfaceName, protocol string, rcvr RPCService)
return
strings
.
TrimSuffix
(
methods
,
","
),
nil
}
// UnRegister cancel a service by @interfaceName, @protocol and @serviceId
func
(
sm
*
serviceMap
)
UnRegister
(
interfaceName
,
protocol
,
serviceId
string
)
error
{
if
protocol
==
""
||
serviceId
==
""
{
return
perrors
.
New
(
"protocol or serviceName is nil"
)
}
sm
.
mutex
.
RLock
()
svcs
,
ok
:=
sm
.
serviceMap
[
protocol
]
if
!
ok
{
sm
.
mutex
.
RUnlock
()
return
perrors
.
New
(
"no services for "
+
protocol
)
}
s
,
ok
:=
svcs
[
serviceId
]
if
!
ok
{
sm
.
mutex
.
RUnlock
()
return
perrors
.
New
(
"no service for "
+
serviceId
)
}
svrs
,
ok
:=
sm
.
interfaceMap
[
interfaceName
]
if
!
ok
{
sm
.
mutex
.
RUnlock
()
return
perrors
.
New
(
"no service for "
+
interfaceName
)
}
index
:=
-
1
for
i
,
svr
:=
range
svrs
{
if
svr
==
s
{
index
=
i
var
(
err
error
index
=
-
1
svcs
map
[
string
]
*
Service
svrs
[]
*
Service
ok
bool
)
f
:=
func
()
error
{
sm
.
mutex
.
RLock
()
defer
sm
.
mutex
.
RUnlock
()
svcs
,
ok
=
sm
.
serviceMap
[
protocol
]
if
!
ok
{
return
perrors
.
New
(
"no services for "
+
protocol
)
}
s
,
ok
:=
svcs
[
serviceId
]
if
!
ok
{
return
perrors
.
New
(
"no service for "
+
serviceId
)
}
svrs
,
ok
=
sm
.
interfaceMap
[
interfaceName
]
if
!
ok
{
return
perrors
.
New
(
"no service for "
+
interfaceName
)
}
for
i
,
svr
:=
range
svrs
{
if
svr
==
s
{
index
=
i
}
}
return
nil
}
if
err
=
f
();
err
!=
nil
{
return
err
}
sm
.
mutex
.
RUnlock
()
sm
.
mutex
.
Lock
()
defer
sm
.
mutex
.
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