tianxiaoliang commented on a change in pull request #789:
URL: 
https://github.com/apache/servicecomb-service-center/pull/789#discussion_r547732860



##########
File path: datasource/mongo/sd/event_proxy.go
##########
@@ -0,0 +1,69 @@
+/*
+ * 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 sd
+
+import (
+       "fmt"
+       "sync"
+
+       "github.com/apache/servicecomb-service-center/pkg/log"
+       "github.com/apache/servicecomb-service-center/pkg/util"
+)
+
+var (
+       eventProxies = make(map[string]*MongoEventProxy)
+)
+
+type MongoEventProxy struct {
+       evtHandleFuncs []MongoEventFunc
+       lock           sync.RWMutex
+}
+
+func (h *MongoEventProxy) AddHandleFunc(f MongoEventFunc) {
+       h.lock.Lock()
+       h.evtHandleFuncs = append(h.evtHandleFuncs, f)
+       h.lock.Unlock()
+}
+
+func (h *MongoEventProxy) OnEvent(evt MongoEvent) {
+       h.lock.RLock()
+       for _, f := range h.evtHandleFuncs {
+               f(evt)
+       }
+       h.lock.RUnlock()
+}
+
+// InjectConfig will inject a resource changed event callback function in 
Config
+func (h *MongoEventProxy) InjectConfig(cfg *Config) *Config {

Review comment:
       这个方法只需要传入回调函数,不要传入结构体,变量意义不明,方法意义不明,注释确实很明确,但是提倡方法本身就是明确的




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to