You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@helix.apache.org by GitBox <gi...@apache.org> on 2022/03/09 17:42:06 UTC

[GitHub] [helix] junkaixue commented on a change in pull request #1976: Add event handler and event listener interface

junkaixue commented on a change in pull request #1976:
URL: https://github.com/apache/helix/pull/1976#discussion_r822916070



##########
File path: helix-core/src/main/java/org/apache/helix/cloud/event/CloudEventHandler.java
##########
@@ -0,0 +1,92 @@
+package org.apache.helix.cloud.event;
+
+/*
+ * 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.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class CloudEventHandler {
+  private static final Logger LOG = LoggerFactory.getLogger(CloudEventHandler.class.getName());
+  @VisibleForTesting
+  protected List<CloudEventListener> _eventListeners = new ArrayList<>();
+  private PreEventHandlerCallback _preEventHandlerCallback = null;
+  private PostEventHandlerCallback _postEventHandlerCallback = null;

Review comment:
       Except us, nobody may hook this, right? It is to fine-grained to have explicit call pre/post.
   
   We can make internal property of CallbackHanlder to differentiate them by a flag or enum type inside EventHanlderCallback class. It will reduce functions or declarations. 

##########
File path: helix-core/src/main/java/org/apache/helix/cloud/event/CloudEventHandler.java
##########
@@ -0,0 +1,92 @@
+package org.apache.helix.cloud.event;
+
+/*
+ * 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.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class CloudEventHandler {
+  private static final Logger LOG = LoggerFactory.getLogger(CloudEventHandler.class.getName());
+  @VisibleForTesting
+  protected List<CloudEventListener> _eventListeners = new ArrayList<>();
+  private PreEventHandlerCallback _preEventHandlerCallback = null;
+  private PostEventHandlerCallback _postEventHandlerCallback = null;
+
+  public void registerCloudEventListener(CloudEventListener listener) {
+    _eventListeners.add(listener);
+  }
+
+  public void unregisterCloudEventListener(CloudEventListener listener) {
+    _eventListeners.remove(listener);
+  }
+
+  public void registerPreEventHandlerCallback(PreEventHandlerCallback preEventHandlerCallback) {
+    _preEventHandlerCallback = preEventHandlerCallback;
+  }
+
+  public void unregisterPreEventHandlerCallback(PreEventHandlerCallback preEventHandlerCallback) {
+    _preEventHandlerCallback = null;
+  }
+
+  public PreEventHandlerCallback getPreEventHandlerCallback() {
+    return _preEventHandlerCallback;
+  }
+
+  public PostEventHandlerCallback getPostEventHandlerCallback() {
+    return _postEventHandlerCallback;
+  }
+
+  public void registerPostEventHandlerCallback(PostEventHandlerCallback postEventHandlerCallback) {
+    _postEventHandlerCallback = postEventHandlerCallback;
+  }
+
+  public void unregisterPostEventHandlerCallback(
+      PostEventHandlerCallback postEventHandlerCallback) {
+    _postEventHandlerCallback = null;
+  }
+
+  public void onPause(Object eventInfo) {
+    if (_preEventHandlerCallback != null) {
+      _preEventHandlerCallback.onPause(eventInfo);
+    }
+    for (CloudEventListener listener : _eventListeners) {
+      listener.onPause(eventInfo);
+    }

Review comment:
       How you take the order of listeners? Are we allowing them to do it by order or parallel is fine. Let's define the behavior. If it can be parallel, we can just Java8 parallel process.




-- 
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: reviews-unsubscribe@helix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org