Skip to content
Snippets Groups Projects
Commit 2570f6e2 authored by Joe Zou's avatar Joe Zou Committed by GitHub
Browse files

Merge pull request #644 from pantianying/fix_waitgroup_develop

Fix: waitGroup use
parents dd33fb2b 454d7cf9
No related branches found
No related tags found
No related merge requests found
......@@ -111,7 +111,6 @@ type RegistryConfigurationListener struct {
// NewRegistryConfigurationListener for listening the event of zk.
func NewRegistryConfigurationListener(client *zk.ZookeeperClient, reg *zkRegistry) *RegistryConfigurationListener {
reg.WaitGroup().Add(1)
return &RegistryConfigurationListener{client: client, registry: reg, events: make(chan *config_center.ConfigChangeEvent, 32), isClosed: false, close: make(chan struct{}, 1)}
}
......
......@@ -134,6 +134,7 @@ func (r *zkRegistry) InitListeners() {
regConfigListener.Close()
}
newDataListener.SubscribeURL(conf, NewRegistryConfigurationListener(r.client, r))
r.WaitGroup().Add(1)
go r.listener.ListenServiceEvent(conf, fmt.Sprintf("/dubbo/%s/"+constant.DEFAULT_CATEGORY, url.QueryEscape(conf.Service())), newDataListener)
}
......@@ -259,7 +260,7 @@ func (r *zkRegistry) getListener(conf *common.URL) (*RegistryConfigurationListen
//Interested register to dataconfig.
r.dataListener.SubscribeURL(conf, zkListener)
r.WaitGroup().Add(1)
go r.listener.ListenServiceEvent(conf, fmt.Sprintf("/dubbo/%s/"+constant.DEFAULT_CATEGORY, url.QueryEscape(conf.Service())), r.dataListener)
return zkListener, nil
......
......@@ -77,13 +77,21 @@ func (l *ZkEventListener) ListenServiceNodeEvent(zkPath string, listener ...remo
case zk.EventNodeDataChanged:
logger.Warnf("zk.ExistW(key{%s}) = event{EventNodeDataChanged}", zkPath)
if len(listener) > 0 {
content, _, _ := l.client.Conn.Get(zkEvent.Path)
content, _, err := l.client.Conn.Get(zkEvent.Path)
if err != nil {
logger.Warnf("zk.Conn.Get{key:%s} = error{%v}", zkPath, err)
return false
}
listener[0].DataChange(remoting.Event{Path: zkEvent.Path, Action: remoting.EventTypeUpdate, Content: string(content)})
}
case zk.EventNodeCreated:
logger.Warnf("zk.ExistW(key{%s}) = event{EventNodeCreated}", zkPath)
if len(listener) > 0 {
content, _, _ := l.client.Conn.Get(zkEvent.Path)
content, _, err := l.client.Conn.Get(zkEvent.Path)
if err != nil {
logger.Warnf("zk.Conn.Get{key:%s} = error{%v}", zkPath, err)
return false
}
listener[0].DataChange(remoting.Event{Path: zkEvent.Path, Action: remoting.EventTypeAdd, Content: string(content)})
}
case zk.EventNotWatching:
......
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