Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ftr: Application-level Registry Model #604

Merged
merged 230 commits into from
Jul 12, 2020
Merged
Show file tree
Hide file tree
Changes from 156 commits
Commits
Show all changes
230 commits
Select commit Hold shift + click to select a range
6e574cc
Add:format dir
hxmhlt Mar 22, 2020
79218a1
Mod:resolve conflict
hxmhlt Mar 22, 2020
4cced63
Merge branch 'code_enhance_of_urlinit' into metadata_report
hxmhlt Mar 22, 2020
485cd5f
Mod:format mod
hxmhlt Mar 22, 2020
95b4658
align 2.7.8: direct event dispatcher
Patrick0308 Mar 24, 2020
259e3c1
dispatcher in extension
Patrick0308 Mar 26, 2020
8e2adc5
add unit test and move extension to observer
Patrick0308 Mar 29, 2020
357f536
fix import
Patrick0308 Mar 29, 2020
ea24b17
add default eventDispatch type and handle eventType is ptr
Patrick0308 Mar 30, 2020
690333b
Mod:resolve conflict
hxmhlt Apr 1, 2020
2925dd3
modify some comments and optimize code
Patrick0308 Apr 2, 2020
a782838
optimize some code and fix imports
Patrick0308 Apr 2, 2020
8cc8060
Merge branch 'feature/dubbo-2.7.5' into metadata_report
hxmhlt Apr 8, 2020
8c42b4c
In memory service discovery support
Apr 8, 2020
c15a725
Add in-memory service-discovery support
Apr 8, 2020
0b0fde8
Add: add exporter
hxmhlt Apr 9, 2020
8d3329f
Merge branch 'develop' into metadata_report
hxmhlt Apr 9, 2020
a594afd
Merge pull request #470 from apache/develop
hxmhlt Apr 9, 2020
6a9591a
Add:identifier ut
hxmhlt Apr 9, 2020
b3dddc8
Mod: move service name mapping
hxmhlt Apr 9, 2020
863dd0f
Mod:make ut run
hxmhlt Apr 9, 2020
207e246
Mod:resolve conflict
hxmhlt Apr 9, 2020
74d6dd9
Mod:format
hxmhlt Apr 9, 2020
dc405a7
Add:liscense
hxmhlt Apr 9, 2020
2622827
move global dispatcher to extension package
Patrick0308 Apr 10, 2020
ef06c72
Mod:dir rename
hxmhlt Apr 10, 2020
045f7f5
Merge remote-tracking branch 'upstream/feature/dubbo-2.7.5' into alig…
Patrick0308 Apr 11, 2020
b30bea6
Merge remote-tracking branch 'upstream/feature/dubbo-2.7.5' into alig…
Patrick0308 Apr 11, 2020
eca5628
fix imports
Patrick0308 Apr 11, 2020
a8871fd
modify and add licenses
Patrick0308 Apr 11, 2020
5d380d0
Mod:import pkg rename
hxmhlt Apr 11, 2020
a4ee287
Merge pull request #455 from Patrick0308/align-2.7.5
flycash Apr 13, 2020
7c20ad3
Merge branch 'feature/dubbo-2.7.5' of github.com:apache/dubbo-go into…
Apr 13, 2020
6707dfb
Fix format
Apr 13, 2020
f09c991
Add extensiong for metadata service
Apr 15, 2020
f580027
Mod:rw problem
hxmhlt Apr 17, 2020
851966e
Merge branch 'feature/dubbo-2.7.5' into metadata_report
hxmhlt Apr 17, 2020
ace7899
Mod:rw problem
hxmhlt Apr 17, 2020
4521e09
Mod:rw problem
hxmhlt Apr 17, 2020
66aa1a0
Mod:rw problem
hxmhlt Apr 17, 2020
422b678
Merge pull request #469 from flycash/inmemory-service-discovery
flycash Apr 19, 2020
ad995d8
Add:add for resolve rw
hxmhlt Apr 20, 2020
5067dae
Mod:treeset to skiplist
hxmhlt Apr 21, 2020
f595f50
Mod:resolve conflict
hxmhlt Apr 21, 2020
2ac672f
event_publishing_service_discovery.go init
Patrick0308 Apr 21, 2020
370681a
Merge pull request #471 from hxmhlt/metadata_report
flycash Apr 21, 2020
5b10451
implement GetConfigKeysByGroup
Apr 13, 2020
c8920d3
Fix travis
Apr 21, 2020
ad18357
Merge pull request #1 from apache/feature/dubbo-2.7.5
lzp0412 Apr 22, 2020
5811136
Merge remote-tracking branch 'origin/feature/dubbo-2.7.5' into featur…
Apr 22, 2020
ae7d706
support service discovery registry
Apr 24, 2020
8022392
fix synthesizer bug
Apr 24, 2020
c556232
Merge pull request #475 from flycash/nacos-batch-bk
flycash Apr 26, 2020
839e0dd
add EventPublishingServiceDiscovery constructor
Patrick0308 Apr 28, 2020
3189b65
Merge remote-tracking branch 'upstream/feature/dubbo-2.7.5' into even…
Patrick0308 Apr 28, 2020
530f563
Implement event dispatcher
Apr 28, 2020
71326c9
Merge branch 'feature/dubbo-2.7.5' of https://github.com/lzp0412/dubb…
May 1, 2020
9b41e95
Merge pull request #497 from flycash/2.7.5
flycash May 1, 2020
682f405
Add dynamic
May 1, 2020
a5da721
rename service => service discovery
May 1, 2020
8b720aa
Merge develop
May 1, 2020
3aa0082
Merge pull request #2 from flycash/2.7.5-bk
lzp0412 May 1, 2020
569e2b6
1、add comments
May 1, 2020
59365ec
Merge develop
May 2, 2020
212d886
merge develop
May 2, 2020
6a558d8
Merge pull request #500 from flycash/2.7.5
zouyx May 2, 2020
ffe69ca
Merge branch 'feature/dubbo-2.7.5' of github.com:apache/dubbo-go into…
May 2, 2020
08eb340
Export get BaseConfig
May 2, 2020
bcda4de
fix review comments
May 2, 2020
698c2b2
Merge remote-tracking branch 'remotes/dubbo-go/feature/dubbo-2.7.5' i…
May 2, 2020
4b8b4d7
Refactor service-discovery
May 4, 2020
1113bf1
Merge 2.7.5
May 4, 2020
3f1a52b
Merge pull request #4 from flycash/2.7.5-bk
lzp0412 May 4, 2020
62b3787
add interface for unregister and unsubscribe
zouyx May 4, 2020
a784557
Add tests
May 5, 2020
266e0b6
Add extensiong for metadata service
Apr 15, 2020
ed5693f
Merge pull request #5 from flycash/2.7.5-bk
lzp0412 May 5, 2020
a4cef09
Merge remote-tracking branch 'upstream/feature/dubbo-2.7.5' into even…
Patrick0308 May 6, 2020
99ac8c5
add Event
Patrick0308 May 6, 2020
b87dbe2
Add:metadata report delegate & remote metadata service
hxmhlt May 6, 2020
73f21fa
Mod:for ut
hxmhlt May 6, 2020
f7dd531
Mod:resolve conflict
hxmhlt May 6, 2020
2938f51
optimize code
Patrick0308 May 6, 2020
ada27e2
add unit tests and modify event struct
Patrick0308 May 8, 2020
9f7e1f3
fix imports
Patrick0308 May 8, 2020
3e81841
add unregister for Registry and FacadeBasedRegistry
zouyx May 10, 2020
df74f8d
add test case for Registry unregister
zouyx May 10, 2020
4970301
modify test case for Registry unregister
zouyx May 11, 2020
69ace5e
modify test case for Registry unregister
zouyx May 11, 2020
e73f3bf
fix impl_test error
May 11, 2020
322eb5f
add Registry unsubscribe
zouyx May 11, 2020
c958389
Merge pull request #487 from Patrick0308/eventDispatchServiceDiscovery
zouyx May 12, 2020
393d12a
fix import error
May 12, 2020
31f8663
change lock granularity
zouyx May 12, 2020
341bc5f
add panic for not support implement
zouyx May 12, 2020
aaeabc6
fix import error
May 12, 2020
f1d5aa4
fix review problems
zouyx May 13, 2020
1b55d1e
Merge branch 'develop' into feature/addRegistryUnpub
zouyx May 15, 2020
ce89e9b
fix review comments
zouyx May 15, 2020
50c24b1
fix review comments
zouyx May 16, 2020
f3a7845
add comment and test case
zouyx May 16, 2020
9788244
Merge remote-tracking branch 'apache/feature/dubbo-2.7.5' into metada…
hxmhlt May 17, 2020
0048609
Mod:resolve pr review
hxmhlt May 17, 2020
235edf5
Mod:resolve pr review
hxmhlt May 17, 2020
7a87b5a
fix review comments
zouyx May 18, 2020
ab046ef
fix review comments
zouyx May 18, 2020
2699fcc
fix review problems
zouyx May 19, 2020
f0c9c8f
fix review problems
zouyx May 19, 2020
df1a43d
Finish code
May 19, 2020
7e7db7b
fix review problems
zouyx May 19, 2020
9026120
Merge pull request #510 from zouyx/feature/addRegistryUnpub
AlexStocks May 20, 2020
5c767f4
change subscribe service key in registrydatalistener
zouyx May 21, 2020
c21d928
change to service key
zouyx May 22, 2020
3094ef8
Merge pull request #535 from zouyx/feature/addRegistryUnpub
zouyx May 22, 2020
c312cc8
Mod:modify for code review
hxmhlt May 23, 2020
0d78b2a
Mod:for code review
hxmhlt May 24, 2020
c024ce1
Mod:code review
hxmhlt May 24, 2020
d4c83fb
Merge pull request #505 from hxmhlt/metadata_report
AlexStocks May 25, 2020
b364f31
change test case method
zouyx May 25, 2020
9578fc0
Merge pull request #542 from zouyx/feature/addRegistryUnpub
Patrick0308 May 26, 2020
7c87c2a
Merge branch 'feature/dubbo-2.7.5' of https://github.com/apache/dubbo…
flycash May 29, 2020
bdd9b71
Add UT
flycash May 29, 2020
198ddc3
Merge nacos-meta
flycash May 29, 2020
7e912e7
Merge pull request #6 from flycash/2.7.5
lzp0412 May 30, 2020
b968f7b
Add unregiste implementation
flycash May 30, 2020
cc4d563
server start successfully
flycash May 30, 2020
bfb89b5
Merge pull request #8 from flycash/2.7.5
lzp0412 May 30, 2020
035d7d9
Fix bug: using EventPublishServiceDiscovery
flycash May 31, 2020
f993803
Merge develop
flycash May 31, 2020
34775e5
Merge pull request #9 from flycash/2.7.5-bk
lzp0412 May 31, 2020
e499d1c
lock optimize
zouyx Jun 1, 2020
3ae2a82
revert changes for CloseAndNilClient
zouyx Jun 1, 2020
977fffa
lock optimize
zouyx Jun 1, 2020
9c623ec
revert changes for registerTempZookeeperNode
zouyx Jun 1, 2020
f7ea5f2
lock optimize
zouyx Jun 1, 2020
db059d3
lock optimize : change to rwlock
zouyx Jun 1, 2020
1d1bbe0
lock optimize : change to rwlock
zouyx Jun 1, 2020
5f0084a
Fix review
flycash Jun 2, 2020
b760621
Add events and eventListener
flycash Jun 2, 2020
9ae184f
extract method for get zookeeper connection
zouyx Jun 2, 2020
ff9eec7
Merge pull request #578 from zouyx/feature/addRegistryUnpub
AlexStocks Jun 2, 2020
ed6b59b
Add events and eventListener
flycash Jun 2, 2020
e2da137
Add customizer
flycash Jun 3, 2020
59eee39
Add customizer
flycash Jun 3, 2020
d997d51
fix review
flycash Jun 4, 2020
b815070
code clean
Jun 5, 2020
efd2305
fix
Jun 5, 2020
2398d20
fix log
Jun 5, 2020
2997c11
refactor MetadataService
flycash Jun 5, 2020
4f382b0
test: assert --> require to use fail now
Jun 6, 2020
a7c2c8b
add lock for event registry map to avoid concurrent read write
Jun 6, 2020
669301f
Merge pull request #522 from flycash/nacos-meta
flycash Jun 7, 2020
16b6500
it can be found by java consumer
flycash Jun 7, 2020
a7d16a0
Resolve conflict
flycash Jun 7, 2020
3984ffa
Merge branch 'feature/dubbo-2.7.5' into 2.7.5-bk
lzp0412 Jun 7, 2020
066dcdd
Add metadata service factory
flycash Jun 8, 2020
61a5188
Merge branch '2.7.5-bk' of github.com:flycash/dubbo-go into 2.7.5-bk
flycash Jun 8, 2020
9d5d9e3
Invoke dubbo client success
flycash Jun 10, 2020
e6c92b9
Merge branch 'feature/dubbo-2.7.5' into zk_client
Jun 11, 2020
c6e8b0c
Fix BUG
flycash Jun 13, 2020
ca020d2
Fix BUG
flycash Jun 13, 2020
9eddc5c
Merge 2.7.5
flycash Jun 13, 2020
e8ca163
Merge 2.7.5
flycash Jun 13, 2020
8793dab
add code for etcd metadata report
pantianying Jun 15, 2020
287da82
Merge develop
flycash Jun 15, 2020
d6a68d5
Fix Review And Add UT
flycash Jun 15, 2020
94636fc
add test code
pantianying Jun 16, 2020
05a6146
fix go fmt
pantianying Jun 16, 2020
df758dc
require --> assert
Jun 16, 2020
0965296
Merge pull request #1 from pantianying/etcd_metadata_report
flycash Jun 16, 2020
760fc22
Fix Review And UT
flycash Jun 16, 2020
c19f65b
Merge branch '2.7.5-bk' of github.com:flycash/dubbo-go into 2.7.5-bk
flycash Jun 16, 2020
024f7b2
Merge pull request #601 from dubbo-x/zk_client
AlexStocks Jun 17, 2020
85607f2
Merge pull request #4 from flycash/2.7.5-bk
xianlezheng Jun 17, 2020
b83f86a
Fix Review And Add UT
flycash Jun 17, 2020
904bbdb
Merge develop
flycash Jun 17, 2020
0b6cbef
Ftr:EtcdServiceDiscovery #423
xianlezheng Jun 20, 2020
8eb8caa
Ftr: add EtcdServiceDiscovery
xianlezheng Jun 20, 2020
b242ae3
Merge pull request #7 from flycash/2.7.5-bk
xianlezheng Jun 20, 2020
819d092
fix:merge update dubbo-2.7.5 branch to feature/etcd-service-discovery
xianlezheng Jun 20, 2020
28057ed
Merge pull request #3 from xianlezheng/feature/etcd-service-discovery
flycash Jun 21, 2020
e3d7770
Fix UT
flycash Jun 21, 2020
80411a4
Merge develop
flycash Jun 21, 2020
facab2b
Fix Etcd BUG
flycash Jun 22, 2020
e91bf07
Merge pull request #8 from flycash/2.7.5-bk
xianlezheng Jun 22, 2020
5aaee6d
Fix: EtcdServiceDiscovery replace put with temp kv.
xianlezheng Jun 22, 2020
be56ab1
Merge pull request #5 from xianlezheng/feature/etcd-service-discovery
flycash Jun 23, 2020
3d0b1c9
modify metareport interface
Jun 26, 2020
b08b8fc
zookeeper's service_discovery
Patrick0308 Jun 26, 2020
b8f5346
fix bug
Jun 26, 2020
b2a04fd
consul metadata report
Jun 26, 2020
117f85f
zookeeper metadata report
Jun 26, 2020
f1576d1
fix
Jun 26, 2020
242e9f2
fix
Jun 26, 2020
81a458c
import sort
Jun 26, 2020
404cd00
consul metadata report unit test
Jun 27, 2020
4e782b3
zookeeper's service_discovery modify
Patrick0308 Jun 27, 2020
c066b50
zookeeper's service_discovery modify
Patrick0308 Jun 27, 2020
30ca089
Merge remote-tracking branch 'upstream/feature/dubbo-2.7.5' into zk-s…
Patrick0308 Jun 27, 2020
7ac57ce
zookeeper's service_discovery fix
Patrick0308 Jun 28, 2020
f004237
zookeeper metadata report unit test
Jun 28, 2020
ecf7fa1
go fmt
Jun 28, 2020
ae1df23
add comment and adjust service_discovery's critical area
Patrick0308 Jun 28, 2020
3c3552c
modify comment
Patrick0308 Jun 28, 2020
44dbdfe
global var for empty slice
Jun 28, 2020
dd6e4bd
add unit tests
Patrick0308 Jun 28, 2020
c2e00e5
Merge remote-tracking branch 'flycash/2.7.5-bk' into zk-servicediscovery
Patrick0308 Jun 28, 2020
f440a31
fix
Jun 28, 2020
e030e25
remove panic
Jun 29, 2020
a601a33
fix bug
Jun 29, 2020
f00d104
rename consul agent for test
Jun 29, 2020
a23c6d2
fix
Jul 1, 2020
7248544
fix typo
Jul 1, 2020
f66dda8
update zk library version
Jul 1, 2020
302dbc2
simplify and comment
Jul 1, 2020
8906429
add CreateTempWithValue in zookeeper client
Patrick0308 Jul 2, 2020
5a12137
Merge pull request #633 from dubbo-x/metadata
pantianying Jul 4, 2020
8ad299c
Merge zk and consul
flycash Jul 4, 2020
3fd1b2d
Merge develop
flycash Jul 4, 2020
e90fac6
Merge zk discovery
flycash Jul 5, 2020
9a5990d
Fix ZK BUG
flycash Jul 5, 2020
822f1a2
Add Release Notes
flycash Jul 5, 2020
d28ae76
Remove comments
flycash Jul 6, 2020
750e62d
Resolve conflict
flycash Jul 10, 2020
f433c06
Merge branch '2.7.5-bk' of github.com:flycash/dubbo-go into 2.7.5-bk
flycash Jul 10, 2020
744afb2
Fix Review
flycash Jul 10, 2020
762e45e
Fix Review
flycash Jul 10, 2020
4140d5d
fix travis
zouyx Jul 11, 2020
4c00837
fix review comment
zouyx Jul 11, 2020
2f73ae5
fix review comment
zouyx Jul 11, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions cluster/directory/base_directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
)

import (
"github.com/dubbogo/gost/container/set"
"go.uber.org/atomic"
)

Expand All @@ -35,8 +34,6 @@ import (
"github.com/apache/dubbo-go/common/logger"
)

var routerURLSet = gxset.NewSet()

// BaseDirectory Abstract implementation of Directory: Invoker list returned from this Directory's list method have been filtered by Routers
type BaseDirectory struct {
url *common.URL
Expand Down Expand Up @@ -120,14 +117,3 @@ func (dir *BaseDirectory) Destroy(doDestroy func()) {
func (dir *BaseDirectory) IsAvailable() bool {
return !dir.destroyed.Load()
}

// GetRouterURLSet Return router URL
func GetRouterURLSet() *gxset.HashSet {
return routerURLSet
}

// AddRouterURLSet Add router URL
// Router URL will init in config/config_loader.go
func AddRouterURLSet(url *common.URL) {
routerURLSet.Add(url)
}
9 changes: 9 additions & 0 deletions common/constant/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,12 @@ const (
const (
COMMA_SPLIT_PATTERN = "\\s*[,]+\\s*"
)

const (
SIMPLE_METADATA_SERVICE_NAME = "MetadataService"
DEFAULT_REVIESION = "N/A"
)

const (
SERVICE_DISCOVERY_DEFAULT_GROUP = "DEFAULT_GROUP"
)
27 changes: 24 additions & 3 deletions common/constant/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ const (
)

const (
PORT_KEY = "port"
GROUP_KEY = "group"
VERSION_KEY = "version"
INTERFACE_KEY = "interface"
PATH_KEY = "path"
PROTOCOL_KEY = "protocol"
SERVICE_KEY = "service"
METHODS_KEY = "methods"
TIMEOUT_KEY = "timeout"
Expand All @@ -40,6 +42,7 @@ const (
TOKEN_KEY = "token"
LOCAL_ADDR = "local-addr"
REMOTE_ADDR = "remote-addr"
PATH_SEPARATOR = "/"
DUBBO_KEY = "dubbo"
RELEASE_KEY = "release"
ANYHOST_KEY = "anyhost"
Expand Down Expand Up @@ -77,6 +80,11 @@ const (
EXECUTE_REJECTED_EXECUTION_HANDLER_KEY = "execute.limit.rejected.handler"
PROVIDER_SHUTDOWN_FILTER = "pshutdown"
CONSUMER_SHUTDOWN_FILTER = "cshutdown"
PID_KEY = "pid"
SYNC_REPORT_KEY = "sync.report"
RETRY_PERIOD_KEY = "retry.period"
RETRY_TIMES_KEY = "retry.times"
CYCLE_REPORT_KEY = "cycle.report"
)

const (
Expand Down Expand Up @@ -226,7 +234,6 @@ const (
KEY_SEPARATOR = ":"
DEFAULT_PATH_TAG = "metadata"
KEY_REVISON_PREFIX = "revision"
PATH_SEPARATOR = "/"

// metadata service
METADATA_SERVICE_NAME = "org.apache.dubbo.metadata.MetadataService"
Expand Down Expand Up @@ -255,7 +262,21 @@ const (
)

// service discovery

const (
NACOS_GROUP = "nacos.group"
SUBSCRIBED_SERVICE_NAMES_KEY = "subscribed-services"
PROVIDER_BY = "provided-by"
EXPORTED_SERVICES_REVISION_PROPERTY_NAME = "dubbo.exported-services.revision"
SUBSCRIBED_SERVICES_REVISION_PROPERTY_NAME = "dubbo.subscribed-services.revision"
SERVICE_INSTANCE_SELECTOR = "service-instance-selector"
METADATA_STORAGE_TYPE_PROPERTY_NAME = "dubbo.metadata.storage-type"
DEFAULT_METADATA_STORAGE_TYPE = "local"
SERVICE_INSTANCE_ENDPOINTS = "dubbo.endpoints"
METADATA_SERVICE_PREFIX = "dubbo.metadata-service."
METADATA_SERVICE_URL_PARAMS_PROPERTY_NAME = METADATA_SERVICE_PREFIX + "url-params"
METADATA_SERVICE_URLS_PROPERTY_NAME = METADATA_SERVICE_PREFIX + "urls"

// SERVICE_DISCOVERY_KEY indicate which service discovery instance will be used
SERVICE_DISCOVERY_KEY = "service_discovery"
LANGUAGE_KEY = "language"
GO_LANG = "golang"
)
70 changes: 70 additions & 0 deletions common/extension/event_dispatcher.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package extension

import (
"sync"
flycash marked this conversation as resolved.
Show resolved Hide resolved

flycash marked this conversation as resolved.
Show resolved Hide resolved
"github.com/apache/dubbo-go/common/logger"
"github.com/apache/dubbo-go/common/observer"
)

var (
globalEventDispatcher observer.EventDispatcher
initEventListeners []func() observer.EventListener
initEventOnce sync.Once
)

var (
dispatchers = make(map[string]func() observer.EventDispatcher, 8)
)

// SetEventDispatcher by name
func SetEventDispatcher(name string, v func() observer.EventDispatcher) {
dispatchers[name] = v
}

// SetAndInitGlobalDispatcher
flycash marked this conversation as resolved.
Show resolved Hide resolved
func SetAndInitGlobalDispatcher(name string) {
if len(name) == 0 {
name = "direct"
}
if globalEventDispatcher != nil {
logger.Warnf("EventDispatcher already init. It will be replaced")
flycash marked this conversation as resolved.
Show resolved Hide resolved
}
if dp, ok := dispatchers[name]; !ok || dp == nil {
panic("EventDispatcher for " + name + " is not existing, make sure you have import the package.")
flycash marked this conversation as resolved.
Show resolved Hide resolved
}
globalEventDispatcher = dispatchers[name]()
}

// GetGlobalDispatcher will init all listener and then return dispatcher
func GetGlobalDispatcher() observer.EventDispatcher {
initEventOnce.Do(func() {
// we should delay to add the listeners to avoid some listeners left
flycash marked this conversation as resolved.
Show resolved Hide resolved
for _, l := range initEventListeners {
globalEventDispatcher.AddEventListener(l())
}
})
return globalEventDispatcher
}

// AddEventListener it will be added in global event dispatcher
func AddEventListener(creator func() observer.EventListener) {
initEventListeners = append(initEventListeners, creator)
}
8 changes: 4 additions & 4 deletions common/extension/metadata_report_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@
package extension

import (
"github.com/apache/dubbo-go/metadata"
"github.com/apache/dubbo-go/metadata/report/factory"
)

var (
metaDataReportFactories = make(map[string]func() metadata.MetadataReportFactory, 8)
metaDataReportFactories = make(map[string]func() factory.MetadataReportFactory, 8)
)

// SetMetadataReportFactory sets the MetadataReportFactory with @name
func SetMetadataReportFactory(name string, v func() metadata.MetadataReportFactory) {
func SetMetadataReportFactory(name string, v func() factory.MetadataReportFactory) {
metaDataReportFactories[name] = v
}

// GetMetadataReportFactory finds the MetadataReportFactory with @name
func GetMetadataReportFactory(name string) metadata.MetadataReportFactory {
func GetMetadataReportFactory(name string) factory.MetadataReportFactory {
if metaDataReportFactories[name] == nil {
panic("metadata report for " + name + " is not existing, make sure you have import the package.")
}
Expand Down
42 changes: 42 additions & 0 deletions common/extension/metadata_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package extension

import (
"fmt"

flycash marked this conversation as resolved.
Show resolved Hide resolved
"github.com/apache/dubbo-go/metadata/service"
)
flycash marked this conversation as resolved.
Show resolved Hide resolved

var (
// there will be two types: local or remote
metadataServiceInsMap = make(map[string]func() (service.MetadataService, error), 2)
)

func SetMetadataService(msType string, creator func() (service.MetadataService, error)) {
metadataServiceInsMap[msType] = creator
}

func GetMetadataService(msType string) (service.MetadataService, error) {
if creator, ok := metadataServiceInsMap[msType]; ok {
return creator()
}
panic(fmt.Sprintf("could not find the metadata service creator for metadataType: %s, please check whether you have imported relative packages, \n"+
"local - github.com/apache/dubbo-go/metadata/service/inmemory, \n"+
"remote - github.com/apache/dubbo-go/metadata/service/remote", msType))
}
41 changes: 41 additions & 0 deletions common/extension/metadata_service_proxy_factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package extension

import (
"fmt"

flycash marked this conversation as resolved.
Show resolved Hide resolved
"github.com/apache/dubbo-go/metadata/service"
flycash marked this conversation as resolved.
Show resolved Hide resolved
)

var (
metadataServiceProxyFactoryMap = make(map[string]func() service.MetadataServiceProxyFactory)
flycash marked this conversation as resolved.
Show resolved Hide resolved
)

func SetMetadataServiceProxyFactory(name string, creator func() service.MetadataServiceProxyFactory) {
metadataServiceProxyFactoryMap[name] = creator
}

func GetMetadataServiceProxyFactory(name string) service.MetadataServiceProxyFactory {
if f, ok := metadataServiceProxyFactoryMap[name]; ok {
return f()
}
panic(fmt.Sprintf("could not find the metadata service factory creator for name: %s, please check whether you have imported relative packages, \n"+
"local - github.com/apache/dubbo-go/metadata/service/inmemory, \n"+
"remote - github.com/apache/dubbo-go/metadata/service/remote", name))
}
17 changes: 10 additions & 7 deletions common/extension/service_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,28 @@ import (
perrors "github.com/pkg/errors"
)
import (
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/registry"
)

var (
discoveryCreatorMap = make(map[string]func(url *common.URL) (registry.ServiceDiscovery, error), 4)
discoveryCreatorMap = make(map[string]func(name string) (registry.ServiceDiscovery, error), 4)
)

// SetServiceDiscovery will store the @creator and @name
func SetServiceDiscovery(name string, creator func(url *common.URL) (registry.ServiceDiscovery, error)) {
discoveryCreatorMap[name] = creator
// protocol indicate the implementation, like nacos
// the name like nacos-1...
func SetServiceDiscovery(protocol string, creator func(name string) (registry.ServiceDiscovery, error)) {
discoveryCreatorMap[protocol] = creator
}

// GetServiceDiscovery will return the registry.ServiceDiscovery
// protocol indicate the implementation, like nacos
// the name like nacos-1...
// if not found, or initialize instance failed, it will return error.
func GetServiceDiscovery(name string, url *common.URL) (registry.ServiceDiscovery, error) {
creator, ok := discoveryCreatorMap[name]
func GetServiceDiscovery(protocol string, name string) (registry.ServiceDiscovery, error) {
creator, ok := discoveryCreatorMap[protocol]
if !ok {
return nil, perrors.New("Could not find the service discovery with name: " + name)
}
return creator(url)
return creator(name)
}
49 changes: 49 additions & 0 deletions common/extension/service_instance_customizer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package extension

import (
"sort"

flycash marked this conversation as resolved.
Show resolved Hide resolved
"github.com/apache/dubbo-go/registry"
flycash marked this conversation as resolved.
Show resolved Hide resolved
)

var (
customizers = make([]registry.ServiceInstanceCustomizer, 0, 8)
)

// AddCustomizers will put the customizer into slices and then sort them;
// this method will be invoked several time, so we sort them here.
func AddCustomizers(cus registry.ServiceInstanceCustomizer) {
customizers = append(customizers, cus)
sort.Stable(customizerSlice(customizers))
}

// GetCustomizers will return the sorted customizer
func GetCustomizers() []registry.ServiceInstanceCustomizer {
return customizers
}

type customizerSlice []registry.ServiceInstanceCustomizer

func (c customizerSlice) Len() int {
return len(c)
}

func (c customizerSlice) Swap(i, j int) { c[i], c[j] = c[j], c[i] }
func (c customizerSlice) Less(i, j int) bool { return c[i].GetPriority() < c[j].GetPriority() }
Loading