Use singleton for api statistics
[policy/api.git] / main / src / main / java / org / onap / policy / api / main / rest / ApiStatisticsManager.java
index 5be9cf1..2a4a46a 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP Policy API
  * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2020-2021 Bell Canada.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,7 +23,6 @@
 
 package org.onap.policy.api.main.rest;
 
-import lombok.AccessLevel;
 import lombok.Getter;
 import lombok.NoArgsConstructor;
 
@@ -32,79 +31,27 @@ import lombok.NoArgsConstructor;
  *
  * @author Chenfei Gao (cgao@research.att.com)
  */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class ApiStatisticsManager {
-
-    @Getter
-    private static long totalApiCallCount;
-
-    @Getter
-    private static long apiCallSuccessCount;
-
-    @Getter
-    private static long apiCallFailureCount;
-
-    @Getter
-    private static long totalPolicyGetCount;
-
-    @Getter
-    private static long totalPolicyPostCount;
-
-    @Getter
-    private static long totalPolicyDeleteCount;
-
-    @Getter
-    private static long totalPolicyTypeGetCount;
-
-    @Getter
-    private static long totalPolicyTypePostCount;
-
-    @Getter
-    private static long totalPolicyTypeDeleteCount;
-
-    @Getter
-    private static long policyGetSuccessCount;
-
+@Getter
+@NoArgsConstructor
+public class ApiStatisticsManager {
     @Getter
-    private static long policyGetFailureCount;
+    private static ApiStatisticsManager instance = new ApiStatisticsManager();
 
-    @Getter
-    private static long policyPostSuccessCount;
-
-    @Getter
-    private static long policyPostFailureCount;
-
-    @Getter
-    private static long policyDeleteSuccessCount;
-
-    @Getter
-    private static long policyDeleteFailureCount;
-
-    @Getter
-    private static long policyTypeGetSuccessCount;
-
-    @Getter
-    private static long policyTypeGetFailureCount;
-
-    @Getter
-    private static long policyTypePostSuccessCount;
-
-    @Getter
-    private static long policyTypePostFailureCount;
-
-    @Getter
-    private static long policyTypeDeleteSuccessCount;
-
-    @Getter
-    private static long policyTypeDeleteFailureCount;
+    private StatisticsReport report = new StatisticsReport();
+    private long totalPolicyDeleteCount;
+    private long totalPolicyTypeDeleteCount;
+    private long policyDeleteSuccessCount;
+    private long policyDeleteFailureCount;
+    private long policyTypeDeleteSuccessCount;
+    private long policyTypeDeleteFailureCount;
 
     /**
      * Method to update the total api call count.
      *
      * @return the updated value of totalApiCallCount
      */
-    public static long updateTotalApiCallCount() {
-        return ++totalApiCallCount;
+    public long updateTotalApiCallCount() {
+        return ++report.totalApiCallCount;
     }
 
     /**
@@ -112,8 +59,8 @@ public final class ApiStatisticsManager {
      *
      * @return the updated value of apiCallSuccessCount
      */
-    public static long updateApiCallSuccessCount() {
-        return ++apiCallSuccessCount;
+    public long updateApiCallSuccessCount() {
+        return ++report.apiCallSuccessCount;
     }
 
     /**
@@ -121,8 +68,8 @@ public final class ApiStatisticsManager {
      *
      * @return the updated value of apiCallFailureCount
      */
-    public static long updateApiCallFailureCount() {
-        return ++apiCallFailureCount;
+    public long updateApiCallFailureCount() {
+        return ++report.apiCallFailureCount;
     }
 
     /**
@@ -130,8 +77,8 @@ public final class ApiStatisticsManager {
      *
      * @return the updated value of totalPolicyGetCount
      */
-    public static long updateTotalPolicyGetCount() {
-        return ++totalPolicyGetCount;
+    public long updateTotalPolicyGetCount() {
+        return ++report.totalPolicyGetCount;
     }
 
     /**
@@ -139,8 +86,8 @@ public final class ApiStatisticsManager {
      *
      * @return the updated value of totalPolicyPostCount
      */
-    public static long updateTotalPolicyPostCount() {
-        return ++totalPolicyPostCount;
+    public long updateTotalPolicyPostCount() {
+        return ++report.totalPolicyPostCount;
     }
 
     /**
@@ -148,7 +95,7 @@ public final class ApiStatisticsManager {
      *
      * @return the updated value of  totalPolicyDeleteCount
      */
-    public static long updateTotalPolicyDeleteCount() {
+    public long updateTotalPolicyDeleteCount() {
         return ++totalPolicyDeleteCount;
     }
 
@@ -157,8 +104,8 @@ public final class ApiStatisticsManager {
      *
      * @return the updated value of totalPolicyTypeGetCount
      */
-    public static long updateTotalPolicyTypeGetCount() {
-        return ++totalPolicyTypeGetCount;
+    public long updateTotalPolicyTypeGetCount() {
+        return ++report.totalPolicyTypeGetCount;
     }
 
     /**
@@ -166,8 +113,8 @@ public final class ApiStatisticsManager {
      *
      * @return the updated value of totalPolicyTypePostCount
      */
-    public static long updateTotalPolicyTypePostCount() {
-        return ++totalPolicyTypePostCount;
+    public long updateTotalPolicyTypePostCount() {
+        return ++report.totalPolicyTypePostCount;
     }
 
     /**
@@ -175,7 +122,7 @@ public final class ApiStatisticsManager {
      *
      * @return the updated value of totalPolicyTypeDeleteCount
      */
-    public static long updateTotalPolicyTypeDeleteCount() {
+    public long updateTotalPolicyTypeDeleteCount() {
         return ++totalPolicyTypeDeleteCount;
     }
 
@@ -184,8 +131,8 @@ public final class ApiStatisticsManager {
      *
      * @return the updated value of policyGetSuccessCount
      */
-    public static long updatePolicyGetSuccessCount() {
-        return ++policyGetSuccessCount;
+    public long updatePolicyGetSuccessCount() {
+        return ++report.policyGetSuccessCount;
     }
 
     /**
@@ -193,8 +140,8 @@ public final class ApiStatisticsManager {
      *
      * @return the updated value of policyGetFailureCount
      */
-    public static long updatePolicyGetFailureCount() {
-        return ++policyGetFailureCount;
+    public long updatePolicyGetFailureCount() {
+        return ++report.policyGetFailureCount;
     }
 
     /**
@@ -202,8 +149,8 @@ public final class ApiStatisticsManager {
      *
      * @return the updated value of policyPostSuccessCount
      */
-    public static long updatePolicyPostSuccessCount() {
-        return ++policyPostSuccessCount;
+    public long updatePolicyPostSuccessCount() {
+        return ++report.policyPostSuccessCount;
     }
 
     /**
@@ -211,8 +158,8 @@ public final class ApiStatisticsManager {
      *
      * @return the updated value of policyPostFailureCount
      */
-    public static long updatePolicyPostFailureCount() {
-        return ++policyPostFailureCount;
+    public long updatePolicyPostFailureCount() {
+        return ++report.policyPostFailureCount;
     }
 
     /**
@@ -220,7 +167,7 @@ public final class ApiStatisticsManager {
      *
      * @return the updated value of policyDeleteSuccessCount
      */
-    public static long updatePolicyDeleteSuccessCount() {
+    public long updatePolicyDeleteSuccessCount() {
         return ++policyDeleteSuccessCount;
     }
 
@@ -229,7 +176,7 @@ public final class ApiStatisticsManager {
      *
      * @return the updated value of policyDeleteFailureCount
      */
-    public static long updatePolicyDeleteFailureCount() {
+    public long updatePolicyDeleteFailureCount() {
         return ++policyDeleteFailureCount;
     }
 
@@ -238,8 +185,8 @@ public final class ApiStatisticsManager {
      *
      * @return the updated value of policyTypeGetSuccessCount
      */
-    public static long updatePolicyTypeGetSuccessCount() {
-        return ++policyTypeGetSuccessCount;
+    public long updatePolicyTypeGetSuccessCount() {
+        return ++report.policyTypeGetSuccessCount;
     }
 
     /**
@@ -247,8 +194,8 @@ public final class ApiStatisticsManager {
      *
      * @return the updated value of policyTypeGetFailureCount
      */
-    public static long updatePolicyTypeGetFailureCount() {
-        return ++policyTypeGetFailureCount;
+    public long updatePolicyTypeGetFailureCount() {
+        return ++report.policyTypeGetFailureCount;
     }
 
     /**
@@ -256,8 +203,8 @@ public final class ApiStatisticsManager {
      *
      * @return the updated value of policyTypePostSuccessCount
      */
-    public static long updatePolicyTypePostSuccessCount() {
-        return ++policyTypePostSuccessCount;
+    public long updatePolicyTypePostSuccessCount() {
+        return ++report.policyTypePostSuccessCount;
     }
 
     /**
@@ -265,8 +212,8 @@ public final class ApiStatisticsManager {
      *
      * @return the updated value of policyTypePostFailureCount
      */
-    public static long updatePolicyTypePostFailureCount() {
-        return ++policyTypePostFailureCount;
+    public long updatePolicyTypePostFailureCount() {
+        return ++report.policyTypePostFailureCount;
     }
 
     /**
@@ -274,7 +221,7 @@ public final class ApiStatisticsManager {
      *
      * @return the updated value of policyTypeDeleteSuccessCount
      */
-    public static long updatePolicyTypeDeleteSuccessCount() {
+    public long updatePolicyTypeDeleteSuccessCount() {
         return ++policyTypeDeleteSuccessCount;
     }
 
@@ -283,36 +230,14 @@ public final class ApiStatisticsManager {
      *
      * @return the updated value of policyTypePostFailureCount
      */
-    public static long updatePolicyTypeDeleteFailureCount() {
+    public long updatePolicyTypeDeleteFailureCount() {
         return ++policyTypeDeleteFailureCount;
     }
 
     /**
-     * Reset all the statistics counts to 0.
+     * Resets the statistics.
      */
-    public static void resetAllStatistics() {
-        totalApiCallCount = 0L;
-        apiCallSuccessCount = 0L;
-        apiCallFailureCount = 0L;
-        totalPolicyGetCount = 0L;
-        totalPolicyPostCount = 0L;
-        totalPolicyDeleteCount = 0L;
-        totalPolicyTypeGetCount = 0L;
-        totalPolicyTypePostCount = 0L;
-        totalPolicyTypeDeleteCount = 0L;
-        policyGetSuccessCount = 0L;
-        policyGetFailureCount = 0L;
-        policyPostSuccessCount = 0L;
-        policyPostFailureCount = 0L;
-        policyDeleteSuccessCount = 0L;
-        policyDeleteFailureCount = 0L;
-        policyTypeGetSuccessCount = 0L;
-        policyTypeGetFailureCount = 0L;
-        policyTypePostSuccessCount = 0L;
-        policyTypePostFailureCount = 0L;
-        policyTypeDeleteSuccessCount = 0L;
-        policyTypeDeleteFailureCount = 0L;
-
+    protected static void resetAllStatistics() {
+        instance = new ApiStatisticsManager();
     }
-
 }