mgao0 commented on code in PR #2121:
URL: https://github.com/apache/helix/pull/2121#discussion_r886036875


##########
helix-core/src/main/java/org/apache/helix/cloud/event/CloudEventHandlerFactory.java:
##########
@@ -19,27 +19,35 @@
  * under the License.
  */
 
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.helix.util.HelixUtil;
+
+
 /**
- * This class is the factory for singleton class {@link CloudEventHandler}
+ * This class is the factory for singleton class {@link AbstractEventHandler}
  */
 public class CloudEventHandlerFactory {
-  private static CloudEventHandler INSTANCE = null;
+  private static Map<String, AbstractEventHandler> INSTANCE_MAP = new 
HashMap();
 
   private CloudEventHandlerFactory() {
   }
 
   /**
-   * Get a CloudEventHandler instance
+   * Get an instance of AbstractEventHandler implementation.
    * @return
    */
-  public static CloudEventHandler getInstance() {
-    if (INSTANCE == null) {
-      synchronized (CloudEventHandlerFactory.class) {
-        if (INSTANCE == null) {
-          INSTANCE = new CloudEventHandler();
-        }
+  public static AbstractEventHandler getInstance(String eventHandlerClassName)
+      throws ClassNotFoundException, IllegalAccessException, 
InstantiationException {
+    synchronized (CloudEventHandlerFactory.class) {
+      AbstractEventHandler instance = INSTANCE_MAP.get(eventHandlerClassName);
+      if (instance == null) {
+         instance = (AbstractEventHandler) (HelixUtil

Review Comment:
   nit: Can we add a info level logging here?



##########
helix-core/src/main/java/org/apache/helix/cloud/event/AbstractEventHandler.java:
##########
@@ -0,0 +1,10 @@
+package org.apache.helix.cloud.event;
+

Review Comment:
   nit: Let's add the Apache License



##########
helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixManager.java:
##########
@@ -832,7 +832,10 @@ public void connect() throws Exception {
       if (helixCloudProperty != null && 
helixCloudProperty.isCloudEventCallbackEnabled()) {
         _cloudEventListener =
             new 
HelixCloudEventListener(helixCloudProperty.getCloudEventCallbackProperty(), 
this);
-        
CloudEventHandlerFactory.getInstance().registerCloudEventListener(_cloudEventListener);
+        LOG.info("Using handler: " + 
helixCloudProperty.getCloudEventHandlerClassName());
+        CloudEventHandlerFactory.getInstance(
+            
_helixManagerProperty.getHelixCloudProperty().getCloudEventHandlerClassName())
+            .registerCloudEventListener(_cloudEventListener);

Review Comment:
   nit: Maybe we can add a line of logging here as well.



##########
helix-core/src/test/java/org/apache/helix/cloud/event/HelixTestCloudEventHandler.java:
##########
@@ -0,0 +1,16 @@
+package org.apache.helix.cloud.event;
+

Review Comment:
   nit: Apache license



##########
helix-core/src/test/java/org/apache/helix/cloud/event/HelixTestCloudEventHandler.java:
##########
@@ -0,0 +1,16 @@
+package org.apache.helix.cloud.event;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+public class HelixTestCloudEventHandler extends CloudEventHandler {
+  private static final int TIMEOUT = 900;  // second to timeout
+  private static ExecutorService executorService = 
Executors.newSingleThreadExecutor();
+
+  @Override
+  public void registerCloudEventListener(CloudEventListener listener) {
+    super.registerCloudEventListener(listener);
+    System.out.println("in child register");
+  }
+
+}

Review Comment:
   Could we test unregister as well? My imagination would be we disconnect the 
zk helix manager, and the listener should be automatically unregistered. It is 
missing in the current test, could you help add this test? Thanks!



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