private PropertyProvider getDelegate(MetricDefinition definition,
                                       StreamProvider streamProvider,
                                       MetricHostProvider metricsHostProvider,
                                       String clusterNamePropertyId,
                                       String hostNamePropertyId,
                                       String componentNamePropertyId,
                                       String statePropertyId,
                                       String componentName) {
    Map<String, PropertyInfo> metrics = getPropertyInfo(definition);
    HashMap<String, Map<String, PropertyInfo>> componentMetrics =
      new HashMap<>();
    componentMetrics.put(WRAPPED_METRICS_KEY, metrics);

    try {
      Class<?> clz = Class.forName(definition.getType());

      // use a Factory for the REST provider
      if (clz.equals(RestMetricsPropertyProvider.class)) {
        return metricPropertyProviderFactory.createRESTMetricsPropertyProvider(
            definition.getProperties(), componentMetrics, streamProvider, metricsHostProvider,
            clusterNamePropertyId, hostNamePropertyId, componentNamePropertyId, statePropertyId,
            componentName);
      }

      try {
         /*
         * Warning: this branch is already used, that's why please adjust
         * all implementations when modifying constructor interface
         */
        Constructor<?> ct = clz.getConstructor(Map.class,
            Map.class, StreamProvider.class, MetricHostProvider.class,
            String.class, String.class, String.class, String.class, String.class);
        Object o = ct.newInstance(
            injector,
            definition.getProperties(), componentMetrics,
            streamProvider, metricsHostProvider,
            clusterNamePropertyId, hostNamePropertyId,
            componentNamePropertyId, statePropertyId, componentName);
        return PropertyProvider.class.cast(o);
      } catch (Exception e) {
        LOG.info("Could not find contructor for type '" +
            definition.getType());
      }

      // just new instance
      return PropertyProvider.class.cast(clz.newInstance());

    } catch (Exception e) {
      LOG.error("Could not load class " + definition.getType());
      return null;
    }


  }
@param definition the metric definition for a component
@param streamProvider the stream provider
@param metricsHostProvider the metrics host provider
@param clusterNamePropertyId the cluster name property id
@param hostNamePropertyId the host name property id
@param componentNamePropertyId the component name property id
@param statePropertyId the state property id
@return the custom property provider
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProvider.java