<commit_before>/*
 * This program is part of the OpenLMIS logistics management information system platform software.
 * Copyright © 2017 VillageReach
 *
 * This program is free software: you can redistribute it and/or modify it under the terms
 * of the GNU Affero General Public License as published by the Free Software Foundation, either
 * version 3 of the License, or (at your option) any later version.
 *  
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 * See the GNU Affero General Public License for more details. You should have received a copy of
 * the GNU Affero General Public License along with this program. If not, see
 * http://www.gnu.org/licenses.  For additional information contact <EMAIL>. 
 */

package org.openlmis.referencedata.service;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@Configuration
public class RightAssignmentExecutor {

  @Value("${rightAssignments.thread.corePool}")
  private int corePoolSize;

  @Value("${rightAssignments.thread.maxPool}")
  private int maxPoolSize;

  @Value("${rightAssignments.queue.capacity}")
  private int queueCapacity;

  @Value("${rightAssignments.thread.timeout}")
  private int threadTimeout;

  /**
   * Executor for right assignment regeneration task.
   * Restricts async parameters such as thread pool size. queue capacity or thread timeout.
   */
  @Bean
  public ThreadPoolTaskExecutor rightAssignmentTaskExecutor() {
    ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
    threadPoolTaskExecutor.setCorePoolSize(corePoolSize);
    threadPoolTaskExecutor.setMaxPoolSize(maxPoolSize);
    threadPoolTaskExecutor.setQueueCapacity(queueCapacity);
    threadPoolTaskExecutor.setKeepAliveSeconds(threadTimeout);
<commit_msg>OLMIS-4041: added handling for exceeding thread pool for Right Assignment task<commit_after>/*
 * This program is part of the OpenLMIS logistics management information system platform software.
 * Copyright © 2017 VillageReach
 *
 * This program is free software: you can redistribute it and/or modify it under the terms
 * of the GNU Affero General Public License as published by the Free Software Foundation, either
 * version 3 of the License, or (at your option) any later version.
 *  
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 * See the GNU Affero General Public License for more details. You should have received a copy of
 * the GNU Affero General Public License along with this program. If not, see
 * http://www.gnu.org/licenses.  For additional information contact <EMAIL>. 
 */

package org.openlmis.referencedata.service;

import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@Configuration
@EnableAsync
public class RightAssignmentExecutor {

  private static final XLogger XLOGGER = XLoggerFactory.getXLogger(RightAssignmentService.class);

  @Value("${rightAssignments.thread.corePool}")
  private int corePoolSize;

  @Value("${rightAssignments.thread.maxPool}")
  private int maxPoolSize;

  @Value("${rightAssignments.queue.capacity}")
  private int queueCapacity;

  @Value("${rightAssignments.thread.timeout}")
  private int threadTimeout;

  /**
   * Executor for right assignment regeneration task.
   * Restricts async parameters such as thread pool size. queue capacity or thread timeout.
   */
  @Bean
  @Qualifier("rightAssignmentTaskExecutor")
  public ThreadPoolTaskExecutor rightAssignmentTaskExecutor() {
    ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
    threadPoolTaskExecutor.setCorePoolSize(corePoolSize);
    threadPoolTaskExecutor.setRejectedExecutionHandler((runnable, executor) ->
        XLOGGER.error("Thread pool for Right Assignment Regeneration exceeded"));
    threadPoolTaskExecutor.setMaxPoolSize(maxPoolSize);
    threadPoolTaskExecutor.setQueueCapacity(queueCapacity);
    threadPoolTaskExecutor.setKeepAliveSeconds(threadTimeout);

{'fraction_non_alphanumeric': 0.07309322033898305, 'fraction_numerical': 0.003389830508474576, 'mean_word_length': 5.328418230563003, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5566131', 'n_tokens_mistral': 1193, 'n_tokens_neox': 1167, 'n_words': 407}