Merge "Fix checkstyle warnings in netty-threadgroup-config."
[controller.git] / opendaylight / md-sal / statistics-manager / src / main / java / org / opendaylight / controller / config / yang / md / sal / statistics_manager / StatisticsManagerModule.java
1 package org.opendaylight.controller.config.yang.md.sal.statistics_manager;
2
3 import org.opendaylight.controller.md.statistics.manager.StatisticsManager;
4 import org.opendaylight.controller.md.statistics.manager.impl.StatisticsManagerConfig;
5 import org.opendaylight.controller.md.statistics.manager.impl.StatisticsManagerImpl;
6 import org.slf4j.Logger;
7 import org.slf4j.LoggerFactory;
8
9 public class StatisticsManagerModule extends org.opendaylight.controller.config.yang.md.sal.statistics_manager.AbstractStatisticsManagerModule {
10     private final static Logger LOG = LoggerFactory.getLogger(StatisticsManagerModule.class);
11
12     private final static int MAX_NODES_FOR_COLLECTOR_DEFAULT = 16;
13     private final static int MIN_REQUEST_NET_MONITOR_INTERVAL_DEFAULT = 3000;
14
15     private StatisticsManager statisticsManagerProvider;
16
17     public StatisticsManagerModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
18         super(identifier, dependencyResolver);
19     }
20
21     public StatisticsManagerModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, final StatisticsManagerModule oldModule, final java.lang.AutoCloseable oldInstance) {
22         super(identifier, dependencyResolver, oldModule, oldInstance);
23     }
24
25     @Override
26     public void customValidation() {
27         // add custom validation form module attributes here.
28     }
29
30     @Override
31     public java.lang.AutoCloseable createInstance() {
32         LOG.info("StatisticsManager module initialization.");
33         final StatisticsManagerConfig config = createConfig();
34         statisticsManagerProvider = new StatisticsManagerImpl(getDataBrokerDependency(), config);
35         statisticsManagerProvider.start(getNotificationServiceDependency(), getRpcRegistryDependency());
36         LOG.info("StatisticsManager started successfully.");
37         return new AutoCloseable() {
38             @Override
39             public void close() throws Exception {
40                 try {
41                     statisticsManagerProvider.close();
42                 }
43                 catch (final Exception e) {
44                     LOG.error("Unexpected error by stopping StatisticsManager module", e);
45                 }
46                 LOG.info("StatisticsManager module stopped.");
47             }
48         };
49     }
50
51     public StatisticsManagerConfig createConfig() {
52         final StatisticsManagerConfig.StatisticsManagerConfigBuilder builder = StatisticsManagerConfig.builder();
53         if (getStatisticsManagerSettings() != null && getStatisticsManagerSettings().getMaxNodesForCollector() != null) {
54             builder.setMaxNodesForCollector(getStatisticsManagerSettings().getMaxNodesForCollector());
55         } else {
56             LOG.warn("Load the xml ConfigSubsystem input value fail! MaxNodesForCollector value is set to {} ",
57                     MAX_NODES_FOR_COLLECTOR_DEFAULT);
58             builder.setMaxNodesForCollector(MAX_NODES_FOR_COLLECTOR_DEFAULT);
59         }
60         if (getStatisticsManagerSettings() != null &&
61                 getStatisticsManagerSettings().getMinRequestNetMonitorInterval() != null) {
62             builder.setMinRequestNetMonitorInterval(getStatisticsManagerSettings().getMinRequestNetMonitorInterval());
63         } else {
64             LOG.warn("Load the xml CofnigSubsystem input value fail! MinRequestNetMonitorInterval value is set to {} ",
65                     MIN_REQUEST_NET_MONITOR_INTERVAL_DEFAULT);
66             builder.setMinRequestNetMonitorInterval(MIN_REQUEST_NET_MONITOR_INTERVAL_DEFAULT);
67         }
68         return builder.build();
69     }
70
71 }