afe55a23a7570d21c2e2a05d18882cd929335da6
[so.git] / mso-api-handlers / mso-api-handler-infra / src / main / java / org / onap / so / apihandlerinfra / ApiHandlerApplication.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.apihandlerinfra;
22
23 import java.util.concurrent.Executor;
24
25 import org.springframework.beans.factory.annotation.Value;
26 import org.springframework.boot.SpringApplication;
27 import org.springframework.boot.autoconfigure.SpringBootApplication;
28 import org.springframework.context.annotation.Bean;
29 import org.springframework.scheduling.annotation.EnableAsync;
30 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
31
32 @SpringBootApplication(scanBasePackages = { "org.onap"})
33 @EnableAsync
34 public class ApiHandlerApplication {
35
36         @Value("${mso.async.core-pool-size}")
37         private int corePoolSize;
38
39         @Value("${mso.async.max-pool-size}")
40         private int maxPoolSize;
41
42         @Value("${mso.async.queue-capacity}")
43         private int queueCapacity;
44
45         private static final String LOGS_DIR = "logs_dir";
46
47         private static void setLogsDir() {
48                 if (System.getProperty(LOGS_DIR) == null) {
49                         System.getProperties().setProperty(LOGS_DIR, "./logs/apih/");
50                 }
51         }
52
53         public static void main(String[] args) {
54                 SpringApplication.run(ApiHandlerApplication.class, args);
55                 System.getProperties().setProperty("mso.db", "MARIADB");
56                 System.getProperties().setProperty("server.name", "Springboot");
57                 setLogsDir();
58         }
59
60         @Bean
61         public Executor asyncExecutor() {
62                 ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
63                 executor.setCorePoolSize(corePoolSize);
64                 executor.setMaxPoolSize(maxPoolSize);
65                 executor.setQueueCapacity(queueCapacity);
66                 executor.setThreadNamePrefix("mso-apihandler-infra-");
67                 executor.initialize();
68                 return executor;
69         }
70 }