<commit_before>/*
*  Copyright (c) 2005-2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
*  WSO2 Inc. licenses this file to you under the Apache License,
*  Version 2.0 (the "License"); you may not use this file except
*  in compliance with the License.
*  You may obtain a copy of the License at
*
*    http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied.  See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.event.statistics.internal.ds;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.base.ServerConfiguration;
import org.wso2.carbon.event.statistics.EventStatisticsObserver;
import org.wso2.carbon.event.statistics.EventStatisticsService;
import org.wso2.carbon.event.statistics.internal.Constants;
import org.wso2.carbon.event.statistics.internal.EventStatisticsManager;
import org.wso2.carbon.event.statistics.internal.StatisticsReporterThread;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;


/**
 * @scr.component name="mediation.statistics" immediate="true"
 */
public class EventStatisticsDS {

    private static final Log log = LogFactory.getLog(EventStatisticsDS.class);
    private StatisticsReporterThread reporterThread;

    protected void activate(ComponentContext context) throws Exception {
        try {


            createStatisticsManager();
            EventStatisticsServiceHolder.getInstance().setEventStatisticsService(new EventStatisticsService());
            context.getBundleContext().registerService(EventStatisticsService.class.getName(),
                                                       EventStatisticsServiceHolder.getInstance().getEventStatisticsService(), null);
            if (log.isDebugEnabled()) {
                log.debug("Successfully deployed the event statistics monitoring service");
            }
        } catch (Throwable e) {
            log.error("Can not create the event statistics monitoring service ", e);
        }
    }

    /**
     * Create the statistics store using the synapse environment and configuration context.
     */
    private void createStatisticsManager() {

//        EventStatisticsManager eventStatisticsManager;
        //Ignoring statistics report observers registration if {StatisticsReporterDisabled =true}
        ServerConfiguration config = ServerConfiguration.getInstance();
        String confStatisticsReporterDisabled = config.getFirstProperty("StatisticsReporterDisabled");
        if (!"".equals(confStatisticsReporterDisabled)) {
            boolean disabled = Boolean.valueOf(confStatisticsReporterDisabled);
            if (disabled) {
                return;
            }

        }

        EventStatisticsServiceHolder.getInstance().setEventStatisticsManager(new EventStatisticsManager());

        //JMX-based event-stat monitoring is supported only super tenant because other tenants cannot use JMX to monitor event-stats.
        reporterThread = new StatisticsReporterThread(MultitenantConstants.SUPER_TENANT_ID);

        // Set a custom interval value if required
        ServerConfiguration serverConf = ServerConfiguration.getInstance();
        String interval = serverConf.getFirstProperty(Constants.STAT_REPORTING_INTERVAL);
        if (interval != null) {<commit_msg>Fixing a typo in a comment<commit_after>/*
*  Copyright (c) 2005-2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
*  WSO2 Inc. licenses this file to you under the Apache License,
*  Version 2.0 (the "License"); you may not use this file except
*  in compliance with the License.
*  You may obtain a copy of the License at
*
*    http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied.  See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.event.statistics.internal.ds;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.base.ServerConfiguration;
import org.wso2.carbon.event.statistics.EventStatisticsObserver;
import org.wso2.carbon.event.statistics.EventStatisticsService;
import org.wso2.carbon.event.statistics.internal.Constants;
import org.wso2.carbon.event.statistics.internal.EventStatisticsManager;
import org.wso2.carbon.event.statistics.internal.StatisticsReporterThread;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;


/**
 * @scr.component name="mediation.statistics" immediate="true"
 */
public class EventStatisticsDS {

    private static final Log log = LogFactory.getLog(EventStatisticsDS.class);
    private StatisticsReporterThread reporterThread;

    protected void activate(ComponentContext context) throws Exception {
        try {


            createStatisticsManager();
            EventStatisticsServiceHolder.getInstance().setEventStatisticsService(new EventStatisticsService());
            context.getBundleContext().registerService(EventStatisticsService.class.getName(),
                                                       EventStatisticsServiceHolder.getInstance().getEventStatisticsService(), null);
            if (log.isDebugEnabled()) {
                log.debug("Successfully deployed the event statistics monitoring service");
            }
        } catch (Throwable e) {
            log.error("Can not create the event statistics monitoring service ", e);
        }
    }

    /**
     * Create the statistics store using the synapse environment and configuration context.
     */
    private void createStatisticsManager() {

//        EventStatisticsManager eventStatisticsManager;
        //Ignoring statistics report observers registration if {StatisticsReporterDisabled =true}
        ServerConfiguration config = ServerConfiguration.getInstance();
        String confStatisticsReporterDisabled = config.getFirstProperty("StatisticsReporterDisabled");
        if (!"".equals(confStatisticsReporterDisabled)) {
            boolean disabled = Boolean.valueOf(confStatisticsReporterDisabled);
            if (disabled) {
                return;
            }

        }

        EventStatisticsServiceHolder.getInstance().setEventStatisticsManager(new EventStatisticsManager());

        //JMX-based event-stat monitoring is supported only for super tenant because other tenants cannot it to monitor event-stats.
        reporterThread = new StatisticsReporterThread(MultitenantConstants.SUPER_TENANT_ID);

        // Set a custom interval value if required
        ServerConfiguration serverConf = ServerConfiguration.getInstance();
        String interval = serverConf.getFirstProperty(Constants.STAT_REPORTING_INTERVAL);
        if (interval != null) {
{'fraction_non_alphanumeric': 0.08238871993364667, 'fraction_numerical': 0.006358860934476085, 'mean_word_length': 3.579113924050633, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2411640', 'n_tokens_mistral': 1765, 'n_tokens_neox': 1706, 'n_words': 489}