<commit_before>/*
 * Copyright (c) 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.identity.mgt;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * email sender this creates a new task in thread pool for each email sending request
 */
public class NotificationSender {

    private static ExecutorService threadPool = null;
    NotificationSendingModule module;
    private static final Log log = LogFactory.getLog(NotificationSender.class);

    static {

        IdentityMgtConfig identityMgtConfig = IdentityMgtConfig.getInstance();
        if (identityMgtConfig != null) {

            int threadPoolSize = identityMgtConfig.getNotificationSendingThreadPoolSize();
            int notificationSendingTimeout = identityMgtConfig.getNotificationSendingTimeout();

            if (threadPoolSize > 0) {
                threadPool = Executors.newFixedThreadPool(threadPoolSize);
            } else {
                threadPool = Executors.newFixedThreadPool(5);
            }

            if (notificationSendingTimeout > 0) {
                try {
                    threadPool.awaitTermination(notificationSendingTimeout * 1000, TimeUnit.MILLISECONDS);
                } catch (InterruptedException e) {
                    log.error("Interruption occurred while waiting for termination", e);
                }
            }
        }
    }

    /**
     * creates and submits a task to the thread pool
     *
     * @param module email sending module as task
     */
    public void sendNotification(NotificationSendingModule module) {

        threadPool.submit(module);
    }

    public NotificationSendingModule getModule() {
        return module;
    }
}
<commit_msg>adding improvements<commit_after>/*
 * Copyright (c) 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.identity.mgt;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * email sender this creates a new task in thread pool for each email sending request
 */
public class NotificationSender {

    private static ExecutorService threadPool = null;
    NotificationSendingModule module;
    private static final Log log = LogFactory.getLog(NotificationSender.class);

    static {

        IdentityMgtConfig identityMgtConfig = IdentityMgtConfig.getInstance();
        if (identityMgtConfig != null) {

            int threadPoolSize = identityMgtConfig.getNotificationSendingThreadPoolSize();
            int notificationSendingTimeout = identityMgtConfig.getNotificationSendingTimeout();

            if (threadPoolSize <= 0) {
                threadPoolSize = 5;
            }

            Executors.newFixedThreadPool(threadPoolSize);
            
            if (notificationSendingTimeout > 0) {
                try {
                    threadPool.awaitTermination(notificationSendingTimeout * 1000, TimeUnit.MILLISECONDS);
                } catch (InterruptedException e) {
                    log.error("Interruption occurred while waiting for termination", e);
                }
            }
        }
    }

    /**
     * creates and submits a task to the thread pool
     *
     * @param module email sending module as task
     */
    public void sendNotification(NotificationSendingModule module) {

        threadPool.submit(module);
    }

    public NotificationSendingModule getModule() {
        return module;
    }
}

{'fraction_non_alphanumeric': 0.07653061224489796, 'fraction_numerical': 0.007755102040816327, 'mean_word_length': 2.7904098994586235, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6749810', 'n_tokens_mistral': 1279, 'n_tokens_neox': 1218, 'n_words': 401}