Skip to content
Snippets Groups Projects
Commit ea5e28b6 authored by Ian Luo's avatar Ian Luo
Browse files

Merge branch 'develop' into export-flag

parents da3d9fcc f8c8593d
No related branches found
No related tags found
No related merge requests found
/*
* 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 (
"github.com/apache/dubbo-go/config/interfaces"
)
var (
processors = make(map[string]interfaces.ConfigPostProcessor)
)
// SetConfigPostProcessor registers a ConfigPostProcessor with the given name.
func SetConfigPostProcessor(name string, processor interfaces.ConfigPostProcessor) {
processors[name] = processor
}
// GetConfigPostProcessor finds a ConfigPostProcessor by name.
func GetConfigPostProcessor(name string) interfaces.ConfigPostProcessor {
return processors[name]
}
// GetConfigPostProcessors returns all registered instances of ConfigPostProcessor.
func GetConfigPostProcessors() []interfaces.ConfigPostProcessor {
ret := make([]interfaces.ConfigPostProcessor, 0, len(processors))
for _, v := range processors {
ret = append(ret, v)
}
return ret
}
......@@ -234,3 +234,8 @@ func (p *Proxy) Get() common.RPCService {
func (p *Proxy) GetCallback() interface{} {
return p.callBack
}
// GetInvoker gets Invoker.
func (p *Proxy) GetInvoker() protocol.Invoker {
return p.invoke
}
/*
* 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 interfaces
import (
"github.com/apache/dubbo-go/common"
)
// ConfigPostProcessor is an extension to give users a chance to customize configs against ReferenceConfig and
// ServiceConfig during deployment time.
type ConfigPostProcessor interface {
// PostProcessReferenceConfig customizes ReferenceConfig's params.
PostProcessReferenceConfig(*common.URL)
// PostProcessServiceConfig customizes ServiceConfig's params.
PostProcessServiceConfig(*common.URL)
}
......@@ -100,6 +100,9 @@ func (c *ReferenceConfig) Refer(_ interface{}) {
if c.ForceTag {
cfgURL.AddParam(constant.ForceUseTag, "true")
}
c.postProcessConfig(cfgURL)
if c.Url != "" {
// 1. user specified URL, could be peer-to-peer address, or register center's address.
urlStrings := gxstrings.RegSplit(c.Url, "\\s*[;]+\\s*")
......@@ -185,6 +188,11 @@ func (c *ReferenceConfig) GetRPCService() common.RPCService {
return c.pxy.Get()
}
// GetProxy gets proxy
func (c *ReferenceConfig) GetProxy() *proxy.Proxy {
return c.pxy
}
func (c *ReferenceConfig) getUrlMap() url.Values {
urlMap := url.Values{}
//first set user params
......@@ -248,3 +256,10 @@ func (c *ReferenceConfig) GenericLoad(id string) {
c.Refer(genericService)
c.Implement(genericService)
}
// postProcessConfig asks registered ConfigPostProcessor to post-process the current ReferenceConfig.
func (c *ReferenceConfig) postProcessConfig(url *common.URL) {
for _, p := range extension.GetConfigPostProcessors() {
p.PostProcessReferenceConfig(url)
}
}
......@@ -200,6 +200,8 @@ func (c *ServiceConfig) Export() error {
ivkURL.AddParam(constant.Tagkey, c.Tag)
}
// post process the URL to be exported
c.postProcessConfig(ivkURL)
// config post processor may set "export" to false
if !ivkURL.GetParamBool(constant.EXPORT_KEY, true) {
return nil
......@@ -342,3 +344,10 @@ func (c *ServiceConfig) GetExportedUrls() []*common.URL {
}
return nil
}
// postProcessConfig asks registered ConfigPostProcessor to post-process the current ServiceConfig.
func (c *ServiceConfig) postProcessConfig(url *common.URL) {
for _, p := range extension.GetConfigPostProcessors() {
p.PostProcessServiceConfig(url)
}
}
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