Async thread pool change for VES heartbeat
[oam/tr069-adapter.git] / ves-agent / src / main / java / org / commscope / tr069adapter / vesagent / mapper / MapperRequestSender.java
1 /*
2  * ============LICENSE_START========================================================================
3  * ONAP : tr-069-adapter
4  * =================================================================================================
5  * Copyright (C) 2020 CommScope Inc Intellectual Property.
6  * =================================================================================================
7  * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License,
8  * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You
9  * may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14  * either express or implied. See the License for the specific language governing permissions and
15  * limitations under the License.
16  * ===============LICENSE_END=======================================================================
17  */
18
19 package org.commscope.tr069adapter.vesagent.mapper;\r
20 \r
21 import java.util.concurrent.Future;\r
22 \r
23 import org.commscope.tr069adapter.acs.common.DeviceRPCRequest;\r
24 import org.commscope.tr069adapter.acs.common.DeviceRPCResponse;\r
25 import org.commscope.tr069adapter.vesagent.VesConfiguration;\r
26 import org.commscope.tr069adapter.vesagent.async.WaitForNotifications;\r
27 import org.slf4j.Logger;\r
28 import org.slf4j.LoggerFactory;\r
29 import org.springframework.beans.factory.annotation.Autowired;\r
30 import org.springframework.scheduling.annotation.Async;\r
31 import org.springframework.scheduling.annotation.AsyncResult;\r
32 import org.springframework.stereotype.Component;\r
33 import org.springframework.web.client.RestTemplate;\r
34 \r
35 @Component\r
36 // @EnableAsync\r
37 public class MapperRequestSender {\r
38   private static final Logger LOG = LoggerFactory.getLogger(MapperRequestSender.class);\r
39   private RestTemplate restTemplate = new RestTemplate();\r
40 \r
41   @Autowired\r
42   VesConfiguration config;\r
43 \r
44   @Autowired\r
45   WaitForNotifications waitForNotifications;\r
46 \r
47   // public DeviceRPCResponse sendRequest(DeviceRPCRequest deviceRPCRequest) {\r
48   // return restTemplate.postForObject(config.getMapperPath(), deviceRPCRequest,\r
49   // DeviceRPCResponse.class);\r
50   // }\r
51 \r
52   @Async("threadPoolTaskExecutor2")\r
53   public Future<DeviceRPCResponse> sendRequest(DeviceRPCRequest deviceRPCRequest) {\r
54     LOG.info("Sending device connectivity request to ACS for device {}",\r
55         deviceRPCRequest.getDeviceDetails().getDeviceId());\r
56     DeviceRPCResponse response = restTemplate.postForObject(config.getMapperPath(),\r
57         deviceRPCRequest, DeviceRPCResponse.class);\r
58 \r
59     waitForNotifications.notifyResult(response);\r
60 \r
61     return new AsyncResult<>(response);\r
62   }\r
63 \r
64 }\r