Search in sources :

Example 1 with BatchMode

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());
    }
}
Also used : PreFetch(org.apache.helix.api.listeners.PreFetch) ClusterConfigChangeListener(org.apache.helix.api.listeners.ClusterConfigChangeListener) InstanceConfigChangeListener(org.apache.helix.api.listeners.InstanceConfigChangeListener) ScopedConfigChangeListener(org.apache.helix.api.listeners.ScopedConfigChangeListener) ResourceConfigChangeListener(org.apache.helix.api.listeners.ResourceConfigChangeListener) ConfigChangeListener(org.apache.helix.api.listeners.ConfigChangeListener) InstanceConfigChangeListener(org.apache.helix.api.listeners.InstanceConfigChangeListener) BatchMode(org.apache.helix.api.listeners.BatchMode) Method(java.lang.reflect.Method)

Aggregations

Method (java.lang.reflect.Method)1 BatchMode (org.apache.helix.api.listeners.BatchMode)1 ClusterConfigChangeListener (org.apache.helix.api.listeners.ClusterConfigChangeListener)1 ConfigChangeListener (org.apache.helix.api.listeners.ConfigChangeListener)1 InstanceConfigChangeListener (org.apache.helix.api.listeners.InstanceConfigChangeListener)1 PreFetch (org.apache.helix.api.listeners.PreFetch)1 ResourceConfigChangeListener (org.apache.helix.api.listeners.ResourceConfigChangeListener)1 ScopedConfigChangeListener (org.apache.helix.api.listeners.ScopedConfigChangeListener)1