desaikomal commented on code in PR #2121:
URL: https://github.com/apache/helix/pull/2121#discussion_r881945116
##########
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());
Review Comment:
do we need the log at info level or debug?
##########
helix-core/src/test/java/org/apache/helix/cloud/event/HelixTestCloudEventHandler.java:
##########
@@ -0,0 +1,17 @@
+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:
nit: extra empty lines
##########
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:
can we simplify by just getting once and then setting or creating default
and returning once.
##########
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:
can we also print the exception and stack-trace?
##########
helix-core/src/test/java/org/apache/helix/cloud/event/TestCloudEventCallbackProperty.java:
##########
@@ -188,7 +193,7 @@ public void testUsingInvalidImplClassName() throws
Exception {
_helixManager.connect();
// Manually trigger event
- CloudEventHandlerFactory.getInstance()
+ ((CloudEventHandler)
CloudEventHandlerFactory.getInstance(CloudEventHandler.class.getCanonicalName()))
Review Comment:
can we add negative case where event handle is not registered and we call
unregister etc
--
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]