heesung-sn commented on code in PR #19538:
URL: https://github.com/apache/pulsar/pull/19538#discussion_r1119542057


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/extensions/channel/ServiceUnitStateChannelImpl.java:
##########
@@ -509,6 +515,7 @@ private void handle(String serviceUnit, 
ServiceUnitStateData data) {
 
         ServiceUnitState state = state(data);
         try {
+            stateChangeListeners.notify(serviceUnit, data, 
StateChangeListener.EventStage.BEFORE, null);

Review Comment:
   Whats the usecase for this notify? Can we remove this if not used?



##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/extensions/channel/StateChangeListeners.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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 org.apache.pulsar.broker.loadbalance.extensions.channel;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CopyOnWriteArrayList;
+import lombok.extern.slf4j.Slf4j;
+import 
org.apache.pulsar.broker.loadbalance.extensions.manager.StateChangeListener;
+
+@Slf4j
+public class StateChangeListeners {
+
+    private final List<StateChangeListener> stateChangeListeners;
+
+    public StateChangeListeners() {
+        stateChangeListeners = new CopyOnWriteArrayList<>();
+    }
+
+    public void addListener(StateChangeListener listener) {
+        Objects.requireNonNull(listener);
+        stateChangeListeners.add(listener);
+    }
+
+    public void close() {
+        this.stateChangeListeners.clear();
+    }
+
+    /**
+     * Notify SUCCESS/FAILURE notification to all currently added listeners on 
completion of the future.
+     *
+     * @return future of a new completion stage
+     */
+    public <T> CompletableFuture<T> notifyOnCompletion(CompletableFuture<T> 
future,
+                                                       String serviceUnit,
+                                                       ServiceUnitStateData 
data) {
+        return future.whenComplete((r, ex) -> notify(serviceUnit,
+                data,
+                ex == null ? StateChangeListener.EventStage.SUCCESS : 
StateChangeListener.EventStage.FAILURE,

Review Comment:
   Nit: this event stage looks redundant as we pass exception obj anyway.



##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/extensions/manager/StateChangeListener.java:
##########
@@ -0,0 +1,45 @@
+/*
+ * 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 org.apache.pulsar.broker.loadbalance.extensions.manager;
+
+import 
org.apache.pulsar.broker.loadbalance.extensions.channel.ServiceUnitStateData;
+
+public interface StateChangeListener {
+
+    /**
+     * Stages of events currently supported.
+     * before starting the event/successful completion/failed completion.
+     */
+    enum EventStage {

Review Comment:
   Nit: like I commented above, plz consider if this can be removed. 



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

Reply via email to