Skip to content

Commit

Permalink
Finish v4.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
zouyx committed Feb 23, 2021
2 parents 9586d4a + f7e43f2 commit 3ab6674
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
6 changes: 4 additions & 2 deletions storage/change_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ type ConfigChangeType int

//config change event
type baseChangeEvent struct {
Namespace string
Namespace string
NotificationID int64
}

//config change event
Expand Down Expand Up @@ -84,10 +85,11 @@ func createDeletedConfigChange(oldValue interface{}) *ConfigChange {
}

//base on changeList create Change event
func createConfigChangeEvent(changes map[string]*ConfigChange, nameSpace string) *ChangeEvent {
func createConfigChangeEvent(changes map[string]*ConfigChange, nameSpace string, notificationID int64) *ChangeEvent {
c := &ChangeEvent{
Changes: changes,
}
c.Namespace = nameSpace
c.NotificationID = notificationID
return c
}
2 changes: 1 addition & 1 deletion storage/change_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func TestCreateConfigChangeEvent(t *testing.T) {
addConfig := createAddConfigChange("new")
changes := make(map[string]*ConfigChange)
changes["add"] = addConfig
event := createConfigChangeEvent(changes, "ns")
event := createConfigChangeEvent(changes, "ns", 0)
Assert(t, event, NotNilVal())
Assert(t, len(event.Changes), Equal(1))
Assert(t, event.Namespace, Equal("ns"))
Expand Down
12 changes: 8 additions & 4 deletions storage/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ package storage
import (
"container/list"
"fmt"
"github.com/zouyx/agollo/v4/env/config"
"reflect"
"strconv"
"sync"
"sync/atomic"

"github.com/zouyx/agollo/v4/env/config"

"github.com/zouyx/agollo/v4/agcache"
"github.com/zouyx/agollo/v4/component/log"
"github.com/zouyx/agollo/v4/extension"
Expand Down Expand Up @@ -232,12 +233,14 @@ func (c *Cache) UpdateApolloConfig(apolloConfig *config.ApolloConfig, appConfigF
//get change list
changeList := c.UpdateApolloConfigCache(apolloConfig.Configurations, configCacheExpireTime, apolloConfig.NamespaceName)

notify := appConfig.GetNotificationsMap().GetNotify(apolloConfig.NamespaceName)

//push all newest changes
c.pushNewestChanges(apolloConfig.NamespaceName, apolloConfig.Configurations)
c.pushNewestChanges(apolloConfig.NamespaceName, apolloConfig.Configurations, notify)

if len(changeList) > 0 {
//create config change event base on change list
event := createConfigChangeEvent(changeList, apolloConfig.NamespaceName)
event := createConfigChangeEvent(changeList, apolloConfig.NamespaceName, notify)

//push change event to channel
c.pushChangeEvent(event)
Expand Down Expand Up @@ -375,11 +378,12 @@ func (c *Cache) pushChangeEvent(event *ChangeEvent) {
})
}

func (c *Cache) pushNewestChanges(namespace string, configuration map[string]interface{}) {
func (c *Cache) pushNewestChanges(namespace string, configuration map[string]interface{}, notificationID int64) {
e := &FullChangeEvent{
Changes: configuration,
}
e.Namespace = namespace
e.NotificationID = notificationID
c.pushChange(func(listener ChangeListener) {
go listener.OnNewestChange(e)
})
Expand Down

0 comments on commit 3ab6674

Please sign in to comment.