use of org.apache.helix.api.listeners.BatchMode in project helix by apache.
the class CallbackHandler method parseListenerProperties.
private void parseListenerProperties() {
BatchMode batchMode = _listener.getClass().getAnnotation(BatchMode.class);
PreFetch preFetch = _listener.getClass().getAnnotation(PreFetch.class);
String asyncBatchModeEnabled = System.getProperty("helix.callbackhandler.isAsyncBatchModeEnabled");
if (asyncBatchModeEnabled == null) {
// for backcompatible, the old property name is deprecated.
asyncBatchModeEnabled = System.getProperty("isAsyncBatchModeEnabled");
}
if (asyncBatchModeEnabled != null) {
_batchModeEnabled = Boolean.parseBoolean(asyncBatchModeEnabled);
logger.info("isAsyncBatchModeEnabled by default: " + _batchModeEnabled);
}
if (batchMode != null) {
_batchModeEnabled = batchMode.enabled();
}
if (preFetch != null) {
_preFetchEnabled = preFetch.enabled();
}
Class listenerClass = null;
switch(_changeType) {
case IDEAL_STATE:
listenerClass = IdealStateChangeListener.class;
break;
case INSTANCE_CONFIG:
if (_listener instanceof ConfigChangeListener) {
listenerClass = ConfigChangeListener.class;
} else if (_listener instanceof InstanceConfigChangeListener) {
listenerClass = InstanceConfigChangeListener.class;
}
break;
case CLUSTER_CONFIG:
listenerClass = ClusterConfigChangeListener.class;
break;
case RESOURCE_CONFIG:
listenerClass = ResourceConfigChangeListener.class;
break;
case CONFIG:
listenerClass = ConfigChangeListener.class;
break;
case LIVE_INSTANCE:
listenerClass = LiveInstanceChangeListener.class;
break;
case CURRENT_STATE:
listenerClass = CurrentStateChangeListener.class;
;
break;
case MESSAGE:
case MESSAGES_CONTROLLER:
listenerClass = MessageListener.class;
break;
case EXTERNAL_VIEW:
case TARGET_EXTERNAL_VIEW:
listenerClass = ExternalViewChangeListener.class;
break;
case CONTROLLER:
listenerClass = ControllerChangeListener.class;
}
Method callbackMethod = listenerClass.getMethods()[0];
try {
Method method = _listener.getClass().getMethod(callbackMethod.getName(), callbackMethod.getParameterTypes());
BatchMode batchModeInMethod = method.getAnnotation(BatchMode.class);
PreFetch preFetchInMethod = method.getAnnotation(PreFetch.class);
if (batchModeInMethod != null) {
_batchModeEnabled = batchModeInMethod.enabled();
}
if (preFetchInMethod != null) {
_preFetchEnabled = preFetchInMethod.enabled();
}
} catch (NoSuchMethodException e) {
logger.warn("No method " + callbackMethod.getName() + " defined in listener " + _listener.getClass().getCanonicalName());
}
}
Aggregations