robocanic commented on code in PR #1371:
URL: https://github.com/apache/dubbo-admin/pull/1371#discussion_r2636732823


##########
pkg/discovery/zk/zkwatcher/watcher.go:
##########
@@ -0,0 +1,237 @@
+/*
+ * 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 zkwatcher
+
+import (
+       "sync"
+       "time"
+
+       "github.com/dubbogo/go-zookeeper/zk"
+       set "github.com/duke-git/lancet/v2/datastructure/set"
+
+       "github.com/apache/dubbo-admin/pkg/core/logger"
+)
+
+type EventType string
+
+const (
+       NodeCreated EventType = "NodeCreated"
+       NodeDeleted EventType = "NodeDeleted"
+       NodeChanged EventType = "NodeChanged"
+)
+
+// ZookeeperEvent represents a zookeeper event
+type ZookeeperEvent struct {
+       Type EventType
+       // node path
+       Path string
+       // node data
+       Data string
+       // whether it is a leaf node
+       LeafNode bool
+}
+
+// RecursiveWatcher recursive watcher
+type RecursiveWatcher struct {
+       conn      *zk.Conn
+       basePath  string
+       eventChan chan ZookeeperEvent
+       stopChan  chan struct{}
+       mu        sync.Mutex
+}
+
+// NewRecursiveWatcher create a new recursive watcher
+func NewRecursiveWatcher(conn *zk.Conn, basePath string) *RecursiveWatcher {
+       return &RecursiveWatcher{
+               conn:      conn,
+               basePath:  basePath,
+               eventChan: make(chan ZookeeperEvent, 1000),
+               stopChan:  make(chan struct{}),
+       }
+}
+
+// StartAsync begin watching
+func (rw *RecursiveWatcher) StartAsync() error {
+       logger.Infof("Start watching path: %s", rw.basePath)
+       // Recursively watch the initial path
+       return rw.watchPathRecursively(rw.basePath)
+}
+
+// Stop watching
+func (rw *RecursiveWatcher) Stop() {
+       logger.Infof("Stop watching path: %s", rw.basePath)
+       rw.conn.Close()
+       close(rw.stopChan)
+       close(rw.eventChan)
+}

Review Comment:
   fixed



-- 
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.

To unsubscribe, e-mail: [email protected]

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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to