Search in sources :

Example 1 with MetricCreationException

use of org.wso2.am.analytics.publisher.exception.MetricCreationException in project carbon-apimgt by wso2.

the class AnalyticsDataPublisher method initialize.

public void initialize(AnalyticsCommonConfiguration commonConfig) {
    Map<String, String> configs = commonConfig.getConfigurations();
    String reporterClass = configs.get("publisher.reporter.class");
    try {
        MetricReporter metricReporter;
        if (reporterClass != null) {
            metricReporter = MetricReporterFactory.getInstance().createMetricReporter(reporterClass, configs);
        } else {
            metricReporter = MetricReporterFactory.getInstance().createMetricReporter(configs);
        }
        if (!StringUtils.isEmpty(commonConfig.getResponseSchema())) {
            this.successMetricReporter = metricReporter.createCounterMetric(Constants.RESPONSE_METRIC_NAME, MetricSchema.valueOf(commonConfig.getResponseSchema()));
        } else {
            this.successMetricReporter = metricReporter.createCounterMetric(Constants.RESPONSE_METRIC_NAME, MetricSchema.RESPONSE);
        }
        if (!StringUtils.isEmpty(commonConfig.getFaultSchema())) {
            this.faultyMetricReporter = metricReporter.createCounterMetric(Constants.FAULTY_METRIC_NAME, MetricSchema.valueOf(commonConfig.getFaultSchema()));
        } else {
            this.faultyMetricReporter = metricReporter.createCounterMetric(Constants.FAULTY_METRIC_NAME, MetricSchema.ERROR);
        }
    // Illegal Argument is possible as the enum conversion could fail
    } catch (MetricCreationException | IllegalArgumentException e) {
        log.error("Error initializing event publisher.", e);
    }
}
Also used : MetricCreationException(org.wso2.am.analytics.publisher.exception.MetricCreationException) MetricReporter(org.wso2.am.analytics.publisher.reporter.MetricReporter)

Aggregations

MetricCreationException (org.wso2.am.analytics.publisher.exception.MetricCreationException)1 MetricReporter (org.wso2.am.analytics.publisher.reporter.MetricReporter)1