Fix mongodb errors on application startup
[dcaegen2/analytics/tca-gen2.git] / dcae-analytics / dcae-analytics-web / src / main / java / org / onap / dcae / analytics / web / config / DmaapPollerConfig.java
1 /*
2  * ================================================================================
3  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
4  * Copyright (c) 2021 China Mobile Property. All rights reserved.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  * ============LICENSE_END=========================================================
18  *
19  */
20
21 package org.onap.dcae.analytics.web.config;
22
23 import org.onap.dcae.analytics.model.AnalyticsProfile;
24 import org.onap.dcae.analytics.web.dmaap.MrSubscriberPollingAdvice;
25 import org.onap.dcae.analytics.web.dmaap.MrSubscriberPollingPreferences;
26 import org.onap.dcae.analytics.web.dmaap.MrSubscriberPreferences;
27 import org.springframework.context.annotation.Bean;
28 import org.springframework.context.annotation.Configuration;
29 import org.springframework.context.annotation.Profile;
30 import org.springframework.integration.scheduling.PollerMetadata;
31 import org.springframework.integration.util.DynamicPeriodicTrigger;
32 import org.springframework.scheduling.support.PeriodicTrigger;
33
34 /**
35  * @author Rajiv Singla
36  */
37 @Configuration
38 @Profile(AnalyticsProfile.DMAAP_PROFILE_NAME)
39 public class DmaapPollerConfig {
40
41     @Bean
42     public MrSubscriberPollingAdvice mrSubscriberPollingAdvice(final DynamicPeriodicTrigger dynamicPeriodicTrigger,
43                                                                final MrSubscriberPreferences mrSubscriberPreferences) {
44         final MrSubscriberPollingPreferences pollingPreferences = mrSubscriberPreferences.getPollingPreferences();
45         final int minInterval = pollingPreferences.getMinPollingInterval();
46         final int stepUpDelta = pollingPreferences.getStepUpDelta();
47         final int maxInterval = pollingPreferences.getMaxPollingInterval();
48         final int stepDownDelta = pollingPreferences.getStepDownDelta();
49         return new MrSubscriberPollingAdvice(dynamicPeriodicTrigger, minInterval,
50                 stepUpDelta, maxInterval, stepDownDelta);
51     }
52
53     @Bean
54     public DynamicPeriodicTrigger dynamicPeriodicTrigger(final MrSubscriberPreferences mrSubscriberPreferences) {
55         final MrSubscriberPollingPreferences pollingPreferences = mrSubscriberPreferences.getPollingPreferences();
56         final int minInterval = pollingPreferences.getMinPollingInterval();
57         final DynamicPeriodicTrigger dynamicPeriodicTrigger =
58                 new DynamicPeriodicTrigger(minInterval);
59         dynamicPeriodicTrigger.setFixedRate(true);
60         return dynamicPeriodicTrigger;
61     }
62
63     @Bean
64     public PollerMetadata pollerMetadata(final DynamicPeriodicTrigger dynamicPeriodicTrigger) {
65         final PollerMetadata pollerMetadata = new PollerMetadata();
66         pollerMetadata.setTrigger(dynamicPeriodicTrigger);
67         return pollerMetadata;
68     }
69
70
71     @Bean(name = PollerMetadata.DEFAULT_POLLER)
72     public PollerMetadata defaultPoller() {
73         PollerMetadata pollerMetadata = new PollerMetadata();
74         pollerMetadata.setTrigger(new PeriodicTrigger(1000));
75         return pollerMetadata;
76     }
77
78 }
79