예제 #1
0
 /**
  * Starts sinks from a given metrics configuration. This is made public for unit test.
  *
  * @param config the metrics config
  */
 public static synchronized void startSinksFromConfig(MetricsConfig config) {
   if (sSinks != null) {
     LOG.warn("Sinks have already been started.");
     return;
   }
   sSinks = new ArrayList<>();
   Map<String, Properties> sinkConfigs =
       MetricsConfig.subProperties(config.getProperties(), SINK_REGEX);
   for (Map.Entry<String, Properties> entry : sinkConfigs.entrySet()) {
     String classPath = entry.getValue().getProperty("class");
     if (classPath != null) {
       try {
         Sink sink =
             (Sink)
                 Class.forName(classPath)
                     .getConstructor(Properties.class, MetricRegistry.class)
                     .newInstance(entry.getValue(), METRIC_REGISTRY);
         sSinks.add(sink);
       } catch (Exception e) {
         LOG.error("Sink class {} cannot be instantiated", classPath, e);
       }
     }
   }
 }