View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.management.stats;
8   
9   /**
10   * Aggregate statistics for all services and flows in an application.   Do this by looping through all of the
11   * applications' FlowConstructStatistics that aren;t themselves aggregators.
12   */
13  public class ApplicationStatistics extends FlowConstructStatistics
14  {
15      private AllStatistics parent;
16  
17      public ApplicationStatistics(AllStatistics parent)
18      {
19          super("Application", "application totals", 0);
20          this.parent = parent;
21      }
22  
23      @Override
24      public long getAverageProcessingTime()
25      {
26          long totalTime = 0;
27          long totalEvents = 0;
28          for (FlowConstructStatistics stats : parent.getServiceStatistics())
29          {
30              if (!(stats instanceof ApplicationStatistics))
31              {
32                  totalEvents += stats.getProcessedEvents();
33                  totalTime += stats.getTotalProcessingTime();
34              }
35          }
36          return totalEvents == 0 ? 0 : totalTime / totalEvents;
37      }
38  
39      @Override
40      public long getProcessedEvents()
41      {
42          long total = 0;
43          for (FlowConstructStatistics stats : parent.getServiceStatistics())
44          {
45              if (!(stats instanceof ApplicationStatistics))
46              {
47                  total += stats.getProcessedEvents();
48              }
49          }
50          return total;
51      }
52  
53      @Override
54      public long getMinProcessingTime()
55      {
56          long min = 0;
57          boolean first = true;
58          for (FlowConstructStatistics stats : parent.getServiceStatistics())
59          {
60              if (!(stats instanceof ApplicationStatistics))
61              {
62                  long flowMin = stats.getMinProcessingTime();
63                  if (first)
64                  {
65                      min = flowMin;
66                  }
67                  else
68                  {
69                      min = Math.min(min, flowMin);
70                  }
71              }
72              first = false;
73          }
74          return min;
75      }
76  
77      @Override
78      public long getMaxProcessingTime()
79      {
80          long max = 0;
81          for (FlowConstructStatistics stats : parent.getServiceStatistics())
82          {
83              if (!(stats instanceof ApplicationStatistics))
84              {
85                  max = Math.max(max, stats.getMaxProcessingTime());
86              }
87          }
88          return max;
89      }
90  
91      @Override
92      public long getTotalProcessingTime()
93      {
94          long total = 0;
95          for (FlowConstructStatistics stats : parent.getServiceStatistics())
96          {
97              if (!(stats instanceof ApplicationStatistics))
98              {
99                  total += stats.getTotalProcessingTime();
100             }
101         }
102         return total;
103     }
104 
105     @Override
106     public long getExecutionErrors()
107     {
108         long total = 0;
109         for (FlowConstructStatistics stats : parent.getServiceStatistics())
110         {
111             if (!(stats instanceof ApplicationStatistics))
112             {
113                 total += stats.getExecutionErrors();
114             }
115         }
116         return total;
117     }
118 
119     @Override
120     public long getFatalErrors()
121     {
122         long total = 0;
123         for (FlowConstructStatistics stats : parent.getServiceStatistics())
124         {
125             if (!(stats instanceof ApplicationStatistics))
126             {
127                 total += stats.getFatalErrors();
128             }
129         }
130         return total;
131     }
132 
133     @Override
134     public long getAsyncEventsReceived()
135     {
136         long total = 0;
137         for (FlowConstructStatistics stats : parent.getServiceStatistics())
138         {
139             if (!(stats instanceof ApplicationStatistics))
140             {
141                 total += stats.getAsyncEventsReceived();
142             }
143         }
144         return total;
145     }
146 
147     @Override
148     public long getSyncEventsReceived()
149     {
150         long total = 0;
151         for (FlowConstructStatistics stats : parent.getServiceStatistics())
152         {
153             if (!(stats instanceof ApplicationStatistics))
154             {
155                 total += stats.getSyncEventsReceived();
156             }
157         }
158         return total;
159     }
160 
161     @Override
162     public long getTotalEventsReceived()
163     {
164         long total = 0;
165         for (FlowConstructStatistics stats : parent.getServiceStatistics())
166         {
167             if (!(stats instanceof ApplicationStatistics))
168             {
169                 total += stats.getTotalEventsReceived();
170             }
171         }
172         return total;
173     }
174 }