JConsole support for statistics collection 18/12818/3
authorMichal Polkorab <michal.polkorab@pantheon.sk>
Thu, 13 Nov 2014 15:20:44 +0000 (16:20 +0100)
committerMichal Polkorab <michal.polkorab@pantheon.sk>
Fri, 14 Nov 2014 13:00:50 +0000 (14:00 +0100)
 - sevice identity moved to spi
 - removed unnecessary methods
 - toString() renamed to getStat()

Change-Id: I84d8c2f333f11c202b3cbb82f55578ea3f7961f9
Signed-off-by: Michal Polkorab <michal.polkorab@pantheon.sk>
16 files changed:
openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/ConnectionConfiguration.java
openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/StatisticsConfiguration.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/statistics/Counter.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/statistics/StatisticsCounters.java
openflow-protocol-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/openflow/_switch/connection/provider/impl/rev140328/StatisticsCollectionModule.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/openflow/_switch/connection/provider/impl/rev140328/StatisticsCollectionModuleFactory.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/openflow/_switch/connection/provider/impl/rev140328/SwitchConnectionProviderModule.java
openflow-protocol-impl/src/main/yang/openflow-switch-connection-provider-impl.yang
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/OFDecoderStatisticsTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/OFEncoderStatisticsTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/ConnectionAdapterImplStatisticsTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/ConnectionConfigurationImpl.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/statistics/StatisticsCountersTest.java
openflow-protocol-spi/pom.xml
openflow-protocol-spi/src/main/java/org/opendaylight/openflowjava/protocol/spi/statistics/StatisticsHandler.java [new file with mode: 0644]
openflow-protocol-spi/src/main/yang/openflow-switch-connection-provider.yang

index 0ba121cca99e9263aedc42c180d01c7aa0415baa..243f2d93c1d847c84887a0f3b9621236f71163cd 100644 (file)
@@ -53,8 +53,4 @@ public interface ConnectionConfiguration {
      * @return thread numbers for TcpHandler's eventloopGroups
      */
     ThreadConfiguration getThreadConfiguration();
-    /**
-     * @return Statistics configuration
-     */
-    StatisticsConfiguration getStatisticsConfiguration();
 }
\ No newline at end of file
index 68cfa433605c5e430c990a4b1d251f703ee6a472..e5b25d4075662d6de312170907f895c97efc0351 100644 (file)
@@ -5,13 +5,23 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
+
 package org.opendaylight.openflowjava.protocol.api.connection;
 
 /**
+ * Used for StatisticsCounter configuration
+ * 
  * @author madamjak
- *
  */
 public interface StatisticsConfiguration {
-    Boolean getStatisticsCollect();
-    Integer getLogReportDelay();
-}
+
+    /**
+     * @return true if statistics are / will be collected, false otherwise
+     */
+    boolean getStatisticsCollect();
+
+    /**
+     * @return delay between two statistics logs (in milliseconds)
+     */
+    int getLogReportDelay();
+}
\ No newline at end of file
index 9d7ddc77e50fe194948f2126e81c5c12d31b84ce..c5f187293b9e843a239f24dd0981aba7b9574ece 100644 (file)
@@ -73,8 +73,10 @@ public class Counter {
         counterLastReadValue.set(0l);\r
     }\r
 \r
-    @Override\r
-    public String toString() {\r
+    /**\r
+     * @return last and current count for specified statistic\r
+     */\r
+    public String getStat() {\r
         long cntPrevVal = getCounterLastReadValue();\r
         long cntCurValue = getCounterValue();\r
         return String.format("+%d | %d",cntCurValue-cntPrevVal,cntCurValue);\r
index 34f072b0839abbc6664625957d5b689d51854b6b..951969ab254492f18bd977489dba90a638cca4bf 100644 (file)
@@ -12,6 +12,7 @@ import java.util.Timer;
 import java.util.TimerTask;
 import java.util.concurrent.ConcurrentHashMap;
 
+import org.opendaylight.openflowjava.protocol.spi.statistics.StatisticsHandler;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -20,7 +21,7 @@ import org.slf4j.LoggerFactory;
  * @author madamjak
  *
  */
-public final class StatisticsCounters {
+public final class StatisticsCounters implements StatisticsHandler {
 
     /**
      * Default delay between two writings into log (milliseconds)
@@ -67,43 +68,28 @@ public final class StatisticsCounters {
             countersMap.put(cet, new Counter());
         }
         runCounting = false;
-        this.logReportPeriod = -1;
+        this.logReportPeriod = 0;
         this.runLogReport = false;
         LOGGER.debug("StaticsCounters has been created");
     }
 
     /**
-     * Start counting
-     * @param resetCounters - true = statistics counters will be reset before start counting
-     * @param reportToLogs - true = statistics counters will periodically write to log
-     * @param logReportDelay - delay between two writings into logs in milliseconds (for details see startLogReport(int logReportDelay))
+     * Start counting (counters are set to 0 before counting starts)
+     * @param reportToLogs - true = statistic counters will periodically log
+     * @param logReportDelay - delay between two logs (in milliseconds)
      */
-    public void startCounting(boolean resetCounters, boolean reportToLogs, int logReportDelay){
+    public void startCounting(boolean reportToLogs, int logReportDelay){
         if (runCounting) {
             return;
         }
-        LOGGER.debug("Start counting...");
+        resetCounters();
+        LOGGER.debug("Counting started...");
         if(reportToLogs){
             startLogReport(logReportDelay);
         }
-        if(resetCounters){
-            resetCounters();
-        }
         runCounting = true;
     }
 
-    /**
-     * Start counting (counters are set to 0 before start counting)
-     * @param reportToLogs - true = statistics counters will periodically write to log
-     * @param logReportDelay - delay between two writings into logs in milliseconds (for details see startLogReport(int logReportDelay))
-     */
-    public void startCounting(boolean reportToLogs, int logReportDelay){
-        if (runCounting) {
-            return;
-        }
-        startCounting(true,reportToLogs,logReportDelay);
-    }
-
     /**
      * Stop counting, values in counters are untouched, log reporter is stopped
      */
@@ -122,49 +108,30 @@ public final class StatisticsCounters {
     }
 
     /**
-     * Start write statistics into logs, if writing is run calling has no effect. 
-     * If method is called without previous setting of report delay than DEFAULT_LOG_REPORT_PERIOD will be used.
-     */
-    public void startLogReport(){
-        if(runLogReport){
-            return;
-        }
-        if(this.logReportPeriod <= 0){
-            this.logReportPeriod = DEFAULT_LOG_REPORT_PERIOD;
-        }
-        if(this.logReportPeriod <= MINIMAL_LOG_REPORT_PERIOD){
-            this.logReportPeriod = MINIMAL_LOG_REPORT_PERIOD;
-        }
-        logReporter = new Timer("SC_Timer");
-        logReporter.schedule(new LogReporterTask(this), this.logReportPeriod,this.logReportPeriod);
-        runLogReport = true;
-        LOGGER.debug("Statistics log reporter has been scheduled with period {} ms", this.logReportPeriod);
-    }
-
-    /**
-     * Start write statistics into logs with given delay between writings, if writing is run calling has no effect.
-     * @param logReportDelay - delay between two writings into logs (milliseconds). 
-     *            It is mandatory if reportToLogs is true, value have to be greater than 0 (zero)
-     *            If value is smaller than MINIMAL_LOG_REPORT_PERIOD, the value MINIMAL_LOG_REPORT_PERIOD will be used.
-     * @exception IllegalArgumentException if logReportDelay is not greater than 0 (zero)
+     * Prints statistics with given delay between logs
+     * @param logReportDelay - delay between two logs (in milliseconds)
+     * @exception IllegalArgumentException if logReportDelay is less than 0
      */
     public void startLogReport(int logReportDelay){
         if(runLogReport){
             return;
         }
         if(logReportDelay <= 0){
-            throw new IllegalArgumentException("logReportPeriod have to bee greater than 0 zero");
+            throw new IllegalArgumentException("logReportDelay has to be greater than 0");
         }
         if(logReportDelay < MINIMAL_LOG_REPORT_PERIOD){
             this.logReportPeriod = MINIMAL_LOG_REPORT_PERIOD;
         } else {
             this.logReportPeriod = logReportDelay;
         }
-        startLogReport();
+        logReporter = new Timer("SC_Timer");
+        logReporter.schedule(new LogReporterTask(this), this.logReportPeriod, this.logReportPeriod);
+        runLogReport = true;
+        LOGGER.debug("Statistics log reporter has been scheduled with period {} ms", this.logReportPeriod);
     }
 
     /**
-     * Stop  write statistics into logs, counting does not stop
+     * Stops logging, counting continues
      */
     public void stopLogReport(){
         if(runLogReport){
@@ -217,7 +184,7 @@ public final class StatisticsCounters {
     }
 
     /**
-     * Get counter by counter event type
+     * Get counter by CounterEventType
      * @param counterEventKey key to identify counter (can not be null)
      * @return - Counter object or null if counter has not been enabled
      * @exception - IllegalArgumentException if counterEventKey is null
@@ -241,9 +208,7 @@ public final class StatisticsCounters {
         }
     }
 
-    /**
-     * Set values of all counter to 0 (zero)
-     */
+    @Override
     public void resetCounters() {
         for(CounterEventTypes cet : enabledCounters){
             countersMap.get(cet).reset();
@@ -251,6 +216,15 @@ public final class StatisticsCounters {
         LOGGER.debug("StaticsCounters has been reset");
     }
 
+    @Override
+    public String printStatistics() {
+        StringBuilder strBuilder = new StringBuilder();
+        for(CounterEventTypes cet : getEnabledCounters()){
+            strBuilder.append(cet.name() + ": " + getCountersMap().get(cet).getStat() + "\n");
+        }
+        return strBuilder.toString();
+    }
+
     /**
      * internal class to process logReporter
      * @author madamjak
@@ -266,9 +240,9 @@ public final class StatisticsCounters {
 
         @Override
         public void run() {
-                for(CounterEventTypes cet : sc.getEnabledCounters()){
-                    LOG.debug(cet.toString() + ": " + sc.getCountersMap().get(cet).toString());
-                }
+            for(CounterEventTypes cet : sc.getEnabledCounters()){
+                LOG.debug(cet.name() + ": " + sc.getCountersMap().get(cet).getStat());
+            }
         }
     }
-}
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/openflow/_switch/connection/provider/impl/rev140328/StatisticsCollectionModule.java b/openflow-protocol-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/openflow/_switch/connection/provider/impl/rev140328/StatisticsCollectionModule.java
new file mode 100644 (file)
index 0000000..ff686c1
--- /dev/null
@@ -0,0 +1,121 @@
+package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.provider.impl.rev140328;
+
+import org.opendaylight.openflowjava.protocol.api.connection.StatisticsConfiguration;
+import org.opendaylight.openflowjava.protocol.spi.statistics.StatisticsHandler;
+import org.opendaylight.openflowjava.statistics.StatisticsCounters;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+* This is the definition of statistics collection module identity.
+*/
+public class StatisticsCollectionModule extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.provider.impl.rev140328.AbstractStatisticsCollectionModule {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(StatisticsCollectionModule.class);
+
+    public StatisticsCollectionModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+        super(identifier, dependencyResolver);
+    }
+
+    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) {
+        super(identifier, dependencyResolver, oldModule, oldInstance);
+    }
+
+    @Override
+    public void customValidation() {
+        // add custom validation form module attributes here.
+    }
+
+    @Override
+    public java.lang.AutoCloseable createInstance() {
+        final Statistics statistics = getStatistics();
+        final StatisticsCounters statsCounter = StatisticsCounters.getInstance();
+        StatisticsConfiguration statsConfig = null;
+        if (statistics != null) {
+            statsConfig = new StatisticsConfiguration() {
+
+                @Override
+                public boolean getStatisticsCollect() {
+                    if (statistics.getStatisticsCollect() != null) {
+                        return statistics.getStatisticsCollect().booleanValue();
+                    }
+                    return false;
+                }
+
+                @Override
+                public int getLogReportDelay() {
+                    if (statistics.getLogReportDelay() != null) {
+                        return statistics.getLogReportDelay().intValue();
+                    }
+                    return 0;
+                }
+            };
+        } else {
+            LOGGER.error("STATISTICS ARE NULL");
+        }
+        LOGGER.error("config " + statsConfig);
+        if (statsConfig != null) {
+            statsCounter.startCounting(statsConfig.getStatisticsCollect(), statsConfig.getLogReportDelay());
+        } else {
+            LOGGER.debug("Unable to start StatisticCounter - wrong configuration");
+        }
+
+        /* Internal MXBean implementation */
+        final StatisticsCollectionRuntimeMXBean collectionBean = new StatisticsCollectionRuntimeMXBean() {
+
+            @Override
+            public String printOfjavaStatistics() {
+                if (statsCounter != null) {
+                    return statsCounter.printStatistics();
+                }
+                return "Statistics collection is not avaliable.";
+            }
+            @Override
+            public String getMsgStatistics() {
+                return printOfjavaStatistics();
+            }
+            @Override
+            public String resetOfjavaStatistics() {
+                statsCounter.resetCounters();
+                return "Statistics have been reset";
+            }
+        };
+
+        /* MXBean registration */
+        final StatisticsCollectionRuntimeRegistration runtimeReg =
+                getRootRuntimeBeanRegistratorWrapper().register(collectionBean);
+
+        /* Internal StatisticsCollectionService implementation */
+        final class AutoClosableStatisticsCollection implements StatisticsHandler, AutoCloseable {
+
+            @Override
+            public void close() {
+                if (runtimeReg != null) {
+                    try {
+                        runtimeReg.close();
+                    }
+                    catch (Exception e) {
+                        String errMsg = "Error by stoping StatisticsCollectionService.";
+                        LOGGER.error(errMsg, e);
+                        throw new IllegalStateException(errMsg, e);
+                    }
+                }
+                LOGGER.info("StatisticsCollection Service consumer (instance {} turn down.)", this);
+            }
+
+            @Override
+            public void resetCounters() {
+                statsCounter.resetCounters();
+            }
+
+            @Override
+            public String printStatistics() {
+                return statsCounter.printStatistics();
+            }
+        }
+
+        AutoCloseable ret = new AutoClosableStatisticsCollection();
+        LOGGER.info("StatisticsCollection service (instance {}) initialized.", ret);
+        return ret;
+    }
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/openflow/_switch/connection/provider/impl/rev140328/StatisticsCollectionModuleFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/openflow/_switch/connection/provider/impl/rev140328/StatisticsCollectionModuleFactory.java
new file mode 100644 (file)
index 0000000..04db2fa
--- /dev/null
@@ -0,0 +1,13 @@
+/*
+* Generated file
+*
+* Generated from: yang module name: openflow-switch-connection-provider-impl yang module local name: statistics-collection-service-impl
+* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+* Generated at: Thu Nov 13 12:52:26 CET 2014
+*
+* Do not modify this file unless it is present under src/main directory
+*/
+package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.provider.impl.rev140328;
+public class StatisticsCollectionModuleFactory extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.provider.impl.rev140328.AbstractStatisticsCollectionModuleFactory {
+
+}
index d64941083860214cbba9a50d8179bfc0bf130936..fd5cf8aa2a9fcbf14c49ce7c8689745e591ea6a5 100644 (file)
@@ -13,11 +13,9 @@ import java.net.InetAddress;
 import java.net.UnknownHostException;
 
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration;
-import org.opendaylight.openflowjava.protocol.api.connection.StatisticsConfiguration;
 import org.opendaylight.openflowjava.protocol.api.connection.ThreadConfiguration;
 import org.opendaylight.openflowjava.protocol.api.connection.TlsConfiguration;
 import org.opendaylight.openflowjava.protocol.impl.core.SwitchConnectionProviderImpl;
-import org.opendaylight.openflowjava.statistics.StatisticsCounters;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.KeystoreType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.TransportProtocol;
@@ -63,18 +61,15 @@ public final class SwitchConnectionProviderModule extends org.opendaylight.yang.
     public java.lang.AutoCloseable createInstance() {
         LOG.info("SwitchConnectionProvider started.");
         SwitchConnectionProviderImpl switchConnectionProviderImpl = new SwitchConnectionProviderImpl();
-        StatisticsCounters sc = StatisticsCounters.getInstance();
         try {
             ConnectionConfiguration connConfiguration = createConnectionConfiguration();
             switchConnectionProviderImpl.setConfiguration(connConfiguration);
-            startStatistics(sc, connConfiguration.getStatisticsConfiguration());
         } catch (UnknownHostException e) {
             throw new IllegalArgumentException(e.getMessage(), e);
         }
         return switchConnectionProviderImpl;
     }
 
-    
     /**
      * @return instance configuration object
      * @throws UnknownHostException 
@@ -86,8 +81,7 @@ public final class SwitchConnectionProviderModule extends org.opendaylight.yang.
         final Tls tlsConfig = getTls();
         final Threads threads = getThreads();
         final TransportProtocol transportProtocol = getTransportProtocol();
-        final Statistics statistics = getStatistics();
-        
+
         return new ConnectionConfiguration() {
             @Override
             public InetAddress getAddress() {
@@ -172,31 +166,6 @@ public final class SwitchConnectionProviderModule extends org.opendaylight.yang.
                     }
                 };
             }
-            @Override
-            public StatisticsConfiguration getStatisticsConfiguration(){
-               return new StatisticsConfiguration() {
-                @Override
-                public Boolean getStatisticsCollect() {
-                    if(statistics == null){
-                        return false;
-                    }
-                    if (statistics.getStatisticsCollect() == null){
-                        return false;
-                    }
-                    return statistics.getStatisticsCollect();
-                }
-                @Override
-                public Integer getLogReportDelay() {
-                    if(statistics == null){
-                        return -1;
-                    }
-                    if(statistics.getLogReportDelay() == null){
-                        return -1;
-                    };
-                    return statistics.getLogReportDelay();
-                }
-            };
-            }
         };
     }
 
@@ -222,37 +191,6 @@ public final class SwitchConnectionProviderModule extends org.opendaylight.yang.
         }
     }
 
-    /**
-     * Configure and start Statistics Counters by configuration parameters. 
-     *      No operations is performed if:
-     *      - statisticsConfig is null
-     *      - sc is null
-     *      - sc is not null and if counting is running
-     * @param sc - statistic counter to configure and start
-     * @param statisticsConfig - configuration parameters
-     */
-    private static void startStatistics(StatisticsCounters sc, StatisticsConfiguration statisticsConfig){
-        if(statisticsConfig == null){
-            return;
-        }
-        if(sc == null || sc.isRunCounting()){
-            return;
-        }
-        Boolean toCollectStats = statisticsConfig.getStatisticsCollect();
-        Integer logDelay = statisticsConfig.getLogReportDelay();
-        if(toCollectStats != null && toCollectStats.booleanValue()){
-            int logPeriod = -1;
-            if(logDelay != null){
-                logPeriod = logDelay.intValue();
-            }
-            if(logPeriod >0){
-                sc.startCounting(true, logPeriod);
-            } else {
-                sc.startCounting(false, 0);
-            }
-        }
-    }
-    
     /**
      * @param value
      * @return
index 4ca3188622ff2ef96c596364b6cd40746e100886..cb714d6b5e27fe452778494bd19fce44d3afc139 100644 (file)
@@ -7,6 +7,7 @@ module openflow-switch-connection-provider-impl {
     import openflow-switch-connection-provider {prefix openflow-switch-connection-provider; revision-date 2014-03-28; }
     import ietf-inet-types {prefix ietf-inet; revision-date 2010-09-24; }
     import openflow-configuration {prefix of-config; revision-date 2014-06-30; }
+    import rpc-context { prefix rpcx; revision-date 2013-06-17; }
 
     description
         "openflow-switch-connection-provider";
@@ -22,6 +23,13 @@ module openflow-switch-connection-provider-impl {
         config:java-name-prefix SwitchConnectionProvider;
     }
 
+    identity statistics-collection-service-impl {
+        description
+            "This is the definition of statistics collection module identity.";
+        base config:module-type;
+        config:provided-service openflow-switch-connection-provider:statistics-collection-service;
+        config:java-name-prefix StatisticsCollection;
+    }
 
     augment "/config:modules/config:module/config:configuration" {
         case openflow-switch-connection-provider-impl {
@@ -92,9 +100,14 @@ module openflow-switch-connection-provider-impl {
                     type uint16;
                 }
             }
+        }
+
+        case statistics-collection-service-impl {
+            when "/config:modules/config:module/config:type = 'statistics-collection-service-impl'";
+
             container statistics {
                 leaf statistics-collect {
-                    description "Toggle of collecting statistics";
+                    description "Toggle statistics collecting";
                     type boolean;
                 }
                 leaf log-report-delay {
@@ -102,6 +115,67 @@ module openflow-switch-connection-provider-impl {
                     type uint16;
                 }
             }
+            list openflow-switch-connection-provider {
+                uses config:service-ref {
+                    refine type {
+                        mandatory true;
+                        config:required-identity openflow-switch-connection-provider:openflow-switch-connection-provider;
+                    }
+                }
+            }
+        }
+    }
+
+    augment "/config:modules/config:module/config:state" {
+        case statistics-collection-service-impl {
+            when "/config:modules/config:module/config:type = 'statistics-collection-service-impl'";
+
+            description
+                "MXBean designed for Message Statistic providing to JConsole.";
+
+            leaf msgStatistics {
+                type string;
+            }
+
+            rpcx:rpc-context-instance "print-ofjava-statistics-rpc";
+            rpcx:rpc-context-instance "reset-ofjava-statistics-rpc";
+        }
+    }
+
+    identity print-ofjava-statistics-rpc;
+    identity reset-ofjava-statistics-rpc;
+
+    rpc print-ofjava-statistics {
+        description 
+            "Shortcut JMX call to printOfjavaStatistics.";
+        input {
+            uses rpcx:rpc-context-ref {
+                refine context-instance {
+                    rpcx:rpc-context-instance print-ofjava-statistics-rpc;
+                }
+            }
+        }
+        output {
+            leaf result {
+                type string;
+            }
+        }
+    }
+
+    rpc reset-ofjava-statistics {
+        description 
+            "Shortcut JMX call to resetOfjavaStatistics.";
+        input {
+            uses rpcx:rpc-context-ref {
+                refine context-instance {
+                    rpcx:rpc-context-instance reset-ofjava-statistics-rpc;
+                }
+            }
+        }
+        output {
+            leaf result {
+                type string;
+            }
         }
     }
 }
\ No newline at end of file
index 4dd3f53b1c14a4b362ae041ca72421ac2a491528..2b30d84656f43815ae2820734c002051015316f7 100644 (file)
@@ -58,7 +58,7 @@ public class OFDecoderStatisticsTest {
         ofDecoder.setDeserializationFactory(mockDeserializationFactory);
         outList = new ArrayList<>();
         statCounters = StatisticsCounters.getInstance();
-        statCounters.startCounting(true, false, 0);
+        statCounters.startCounting(false, 0);
     }
 
     /**
index 46aa2f45b113bb110619a416d35a2cca5161cfb8..cfafe99450c95ca297375ba6cf6add566c958b32 100644 (file)
@@ -59,7 +59,7 @@ public class OFEncoderStatisticsTest {
         ofEncoder = new OFEncoder() ;
         ofEncoder.setSerializationFactory(mockSerializationFactory) ;
         statCounters = StatisticsCounters.getInstance();
-        statCounters.startCounting(true,false, 0);
+        statCounters.startCounting(false, 0);
     }
 
     /**
index 8429afdef1bca8d5feb384d1bf56c8e49279a73b..a770e853e554c222c1d63597c400696b9b92f1c2 100644 (file)
@@ -117,7 +117,7 @@ public class ConnectionAdapterImplStatisticsTest {
     public void setUp() {
         MockitoAnnotations.initMocks(this);
         statCounters = StatisticsCounters.getInstance();
-        statCounters.startCounting(true,false, 0);
+        statCounters.startCounting(false, 0);
     }
 
     /**
index ec947e9aa5114d426ecc5b8e54ea352616f81045..6f1993284f1807ce317025838763d6741049cc4e 100644 (file)
@@ -11,11 +11,9 @@ package org.opendaylight.openflowjava.protocol.impl.core.connection;
 import java.net.InetAddress;
 
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration;
-import org.opendaylight.openflowjava.protocol.api.connection.StatisticsConfiguration;
 import org.opendaylight.openflowjava.protocol.api.connection.ThreadConfiguration;
 import org.opendaylight.openflowjava.protocol.api.connection.TlsConfiguration;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.TransportProtocol;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.provider.impl.rev140328.modules.module.configuration.openflow._switch.connection.provider.impl.Statistics;
 
 /**
  * @author michal.polkorab
@@ -29,8 +27,6 @@ public class ConnectionConfigurationImpl implements ConnectionConfiguration {
     private TlsConfiguration tlsConfig;
     private long switchIdleTimeout;
     private ThreadConfiguration threadConfig;
-    private TransportProtocol protocol;
-    private Statistics statistics;
 
     /**
      * Creates {@link ConnectionConfigurationImpl}
@@ -96,10 +92,4 @@ public class ConnectionConfigurationImpl implements ConnectionConfiguration {
     public void setThreadConfiguration(ThreadConfiguration threadConfig) {
         this.threadConfig = threadConfig;
     }
-
-    @Override
-    public StatisticsConfiguration getStatisticsConfiguration() {
-        // TODO Auto-generated method stub
-        return null;
-    }
 }
\ No newline at end of file
index 1bb549b6fedb5f9b1efbc478ae51ecb716aac7a9..d586a24dcdeeeb3a0560cac375ff0d0b47460246 100644 (file)
@@ -30,7 +30,7 @@ public class StatisticsCountersTest {
     @Before
     public void initTest(){
         statCounters = StatisticsCounters.getInstance();
-        statCounters.startCounting(true,false, 0);
+        statCounters.startCounting(false, 0);
     }
 
     /**
@@ -101,9 +101,6 @@ public class StatisticsCountersTest {
         statCounters.startLogReport(testDelay);
         Assert.assertTrue("Wrong - logRepoter is not running", statCounters.isRunLogReport());
         Assert.assertEquals("Wrong - bad logReportPeriod", testDelay, statCounters.getLogReportPeriod());
-        statCounters.startLogReport();
-        Assert.assertTrue("Wrong - logRepoter is not running", statCounters.isRunLogReport());
-        Assert.assertEquals("Wrong - bad logReportPeriod", testDelay, statCounters.getLogReportPeriod());
         statCounters.stopLogReport();
         Assert.assertFalse("Wrong - logRepoter is running", statCounters.isRunLogReport());
         statCounters.startLogReport(statCounters.MINIMAL_LOG_REPORT_PERIOD / 2);
@@ -118,7 +115,7 @@ public class StatisticsCountersTest {
      */
     @Test(expected = IllegalArgumentException.class)
     public void testLogReportBadPeriod(){
-        statCounters.startLogReport(-1);
+        statCounters.startLogReport(0);
     }
 
     /**
index f6ea1ffd92e0ac73fc610a36ac3a816db387dc0c..6cef4f39e3f5f7baa670ced2b5efbc6305083b39 100644 (file)
@@ -23,7 +23,7 @@
               <configuration>
                 <instructions>
                     <Export-Package>
-                      org.opendaylight.openflowjava.protocol.spi.connection*,
+                      org.opendaylight.openflowjava.protocol.spi*,
                       org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.provider.*
                     </Export-Package>
                 </instructions>
diff --git a/openflow-protocol-spi/src/main/java/org/opendaylight/openflowjava/protocol/spi/statistics/StatisticsHandler.java b/openflow-protocol-spi/src/main/java/org/opendaylight/openflowjava/protocol/spi/statistics/StatisticsHandler.java
new file mode 100644 (file)
index 0000000..c5d7a6a
--- /dev/null
@@ -0,0 +1,28 @@
+/*\r
+ * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
+package org.opendaylight.openflowjava.protocol.spi.statistics;\r
+\r
+/**\r
+ * Used for JConsole service\r
+ * \r
+ * @author michal.polkorab\r
+ */\r
+public interface StatisticsHandler {\r
+\r
+    /**\r
+     * Resets all counters\r
+     */\r
+    public void resetCounters();\r
+\r
+    /**\r
+     * Prints statistics\r
+     * @return statistics\r
+     */\r
+    public String printStatistics();\r
+}
\ No newline at end of file
index 88d2427f0b6ea64ab9ca191ef2c80614014151c3..3ed7c20bf08297e8f88f8b4d2f8f04b23cc8b340 100644 (file)
@@ -17,4 +17,11 @@ module openflow-switch-connection-provider {
          base "config:service-type";
          config:java-class "org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider";
     }
+
+    identity statistics-collection-service {
+        description
+            "StatisticsHandlerService interface as a StatisticsCollection interface identity";
+        base config:service-type;
+        config:java-class "org.opendaylight.openflowjava.protocol.spi.statistics.StatisticsHandler";
+    }
 }
\ No newline at end of file