diff --git a/registry/directory/directory.go b/registry/directory/directory.go index c78a9f1bd4a64e3d94db8ecf2b15e017b4b21b05..88e8189fa60460350cc5601e28b68b51a42cf71c 100644 --- a/registry/directory/directory.go +++ b/registry/directory/directory.go @@ -113,8 +113,9 @@ func (dir *RegistryDirectory) Notify(event *registry.ServiceEvent) { } // NotifyAll notify the events that are complete Service Event List. -func (dir *RegistryDirectory) NotifyAll(events []*registry.ServiceEvent) { - go dir.refreshAllInvokers(events) +// After notify the address, the callback func will be invoked. +func (dir *RegistryDirectory) NotifyAll(events []*registry.ServiceEvent, callback func()) { + go dir.refreshAllInvokers(events, callback) } // refreshInvokers refreshes service's events. @@ -132,7 +133,7 @@ func (dir *RegistryDirectory) refreshInvokers(event *registry.ServiceEvent) { // refreshAllInvokers the argument is the complete list of the service events, we can safely assume any cached invoker // not in the incoming list can be removed. The Action of serviceEvent should be EventTypeUpdate. -func (dir *RegistryDirectory) refreshAllInvokers(events []*registry.ServiceEvent) { +func (dir *RegistryDirectory) refreshAllInvokers(events []*registry.ServiceEvent, callback func()) { var ( oldInvokers []protocol.Invoker addEvents []*registry.ServiceEvent @@ -145,6 +146,8 @@ func (dir *RegistryDirectory) refreshAllInvokers(events []*registry.ServiceEvent return } } + // After notify all addresses, do some callback. + defer callback() func() { // this lock is work at batch update of InvokeCache dir.registerLock.Lock() diff --git a/registry/protocol/protocol.go b/registry/protocol/protocol.go index 00f7e8b2b52881302c2eea066965f216a879fe5c..a3ba3eba6b725eb090ddf3b2ab7516446b577aef 100644 --- a/registry/protocol/protocol.go +++ b/registry/protocol/protocol.go @@ -249,7 +249,7 @@ func (nl *overrideSubscribeListener) Notify(event *registry.ServiceEvent) { } } -func (nl *overrideSubscribeListener) NotifyAll(events []*registry.ServiceEvent) { +func (nl *overrideSubscribeListener) NotifyAll(events []*registry.ServiceEvent, callback func()) { if len(events) == 0 { return } diff --git a/registry/registry.go b/registry/registry.go index 97051334dfb6865d2b0147c7f277bc412998acbe..8018aadd1607db12e2b52b21df1208e4adf7b28c 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -76,7 +76,8 @@ type NotifyListener interface { // NotifyAll the events are complete Service Event List. // The argument of events []*ServiceEvent is equal to urls []*URL, The Action of serviceEvent should be EventTypeUpdate. // If your registry center can only get all urls but can't get individual event, you should use this one. - NotifyAll([]*ServiceEvent) + // After notify the address, the callback func will be invoked. + NotifyAll([]*ServiceEvent, func()) } // Listener Deprecated!