1 package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.provider.impl.rev140328;
3 import org.opendaylight.openflowjava.protocol.api.connection.StatisticsConfiguration;
4 import org.opendaylight.openflowjava.protocol.spi.statistics.StatisticsHandler;
5 import org.opendaylight.openflowjava.statistics.StatisticsCounters;
6 import org.slf4j.Logger;
7 import org.slf4j.LoggerFactory;
10 * This is the definition of statistics collection module identity.
12 public class StatisticsCollectionModule extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.provider.impl.rev140328.AbstractStatisticsCollectionModule {
14 private static final Logger LOG = LoggerFactory.getLogger(StatisticsCollectionModule.class);
16 public StatisticsCollectionModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
17 super(identifier, dependencyResolver);
20 public StatisticsCollectionModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.provider.impl.rev140328.StatisticsCollectionModule oldModule, java.lang.AutoCloseable oldInstance) {
21 super(identifier, dependencyResolver, oldModule, oldInstance);
25 public void customValidation() {
26 // add custom validation form module attributes here.
30 public java.lang.AutoCloseable createInstance() {
31 final Statistics statistics = getStatistics();
32 final StatisticsCounters statsCounter = StatisticsCounters.getInstance();
33 StatisticsConfiguration statsConfig = null;
34 if (statistics != null) {
35 statsConfig = new StatisticsConfiguration() {
38 public boolean getStatisticsCollect() {
39 if (statistics.getStatisticsCollect() != null) {
40 return statistics.getStatisticsCollect().booleanValue();
46 public int getLogReportDelay() {
47 if (statistics.getLogReportDelay() != null) {
48 return statistics.getLogReportDelay().intValue();
54 if (statsConfig != null) {
55 statsCounter.startCounting(statsConfig.getStatisticsCollect(), statsConfig.getLogReportDelay());
57 LOG.debug("Unable to start StatisticCounter - wrong configuration");
60 /* Internal MXBean implementation */
61 final StatisticsCollectionRuntimeMXBean collectionBean = new StatisticsCollectionRuntimeMXBean() {
64 public String printOfjavaStatistics() {
65 if (statsCounter != null) {
66 return statsCounter.printStatistics();
68 return "Statistics collection is not avaliable.";
71 public String getMsgStatistics() {
72 return printOfjavaStatistics();
75 public String resetOfjavaStatistics() {
76 statsCounter.resetCounters();
77 return "Statistics have been reset";
81 /* MXBean registration */
82 final StatisticsCollectionRuntimeRegistration runtimeReg =
83 getRootRuntimeBeanRegistratorWrapper().register(collectionBean);
85 /* Internal StatisticsCollectionService implementation */
86 final class AutoClosableStatisticsCollection implements StatisticsHandler, AutoCloseable {
90 if (runtimeReg != null) {
95 String errMsg = "Error by stoping StatisticsCollectionService.";
97 throw new IllegalStateException(errMsg, e);
100 LOG.info("StatisticsCollection Service consumer (instance {} turn down.)", this);
104 public void resetCounters() {
105 statsCounter.resetCounters();
109 public String printStatistics() {
110 return statsCounter.printStatistics();
114 AutoCloseable ret = new AutoClosableStatisticsCollection();
115 LOG.info("StatisticsCollection service (instance {}) initialized.", ret);