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


##########
helix-core/src/test/java/org/apache/helix/cloud/event/MockCloudEventAwareHelixManager.java:
##########
@@ -75,21 +75,32 @@ public MockCloudEventAwareHelixManager(HelixManagerProperty 
helixManagerProperty
             .build());
   }
 
-  public void connect() throws IllegalAccessException, InstantiationException {
+  @Override
+  public void connect()
+      throws IllegalAccessException, InstantiationException, 
ClassNotFoundException {
     if (_helixManagerProperty != null) {
       HelixCloudProperty helixCloudProperty = 
_helixManagerProperty.getHelixCloudProperty();
       if (helixCloudProperty != null && 
helixCloudProperty.isCloudEventCallbackEnabled()) {
         _cloudEventListener =
             new 
HelixCloudEventListener(helixCloudProperty.getCloudEventCallbackProperty(), 
this);
-        
CloudEventHandlerFactory.getInstance().registerCloudEventListener(_cloudEventListener);
+        System.out.println("Using handler: " + 
helixCloudProperty.getCloudEventHandlerClassName());
+        CloudEventHandlerFactory.getInstance(
+            
_helixManagerProperty.getHelixCloudProperty().getCloudEventHandlerClassName())
+            .registerCloudEventListener(_cloudEventListener);
       }
     }
   }
 
+  @Override
   public void disconnect() {
     if (_cloudEventListener != null) {
-      
CloudEventHandlerFactory.getInstance().unregisterCloudEventListener(_cloudEventListener);
-      _cloudEventListener = null;
+      try {
+        CloudEventHandlerFactory.getInstance(
+            
_helixManagerProperty.getHelixCloudProperty().getCloudEventHandlerClassName())
+            .unregisterCloudEventListener(_cloudEventListener);
+      } catch (Exception e) {
+        System.out.println("Failed to unregister cloudEventListener.");

Review Comment:
   Updated.



##########
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) {
+      if (INSTANCE_MAP.get(eventHandlerClassName) == null) {

Review Comment:
   TFTR. Updated.



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