Coverage Report - org.mule.management.stats.ComponentStatistics
 
Classes in this File Line Coverage Branch Coverage Complexity
ComponentStatistics
0%
0/118
0%
0/8
1.171
 
 1  
 /*
 2  
  * $Id: ComponentStatistics.java 7976 2007-08-21 14:26:13Z dirk.olmes $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.management.stats;
 12  
 
 13  
 import org.mule.management.stats.printers.SimplePrinter;
 14  
 
 15  
 import java.io.PrintWriter;
 16  
 
 17  
 public class ComponentStatistics implements Statistics
 18  
 {
 19  
     /**
 20  
      * Serial version
 21  
      */
 22  
     private static final long serialVersionUID = -2086999226732861674L;
 23  
 
 24  
     private String name;
 25  0
     private long totalExecTime = 0;
 26  0
     private long receivedEventSync = 0;
 27  0
     private long receivedEventASync = 0;
 28  0
     private long queuedEvent = 0;
 29  0
     private long maxQueuedEvent = 0;
 30  0
     private long averageQueueSize = 0;
 31  0
     private long totalQueuedEvent = 0;
 32  0
     private long sentEventSync = 0;
 33  0
     private long sentReplyToEvent = 0;
 34  0
     private long sentEventASync = 0;
 35  0
     private long executedEvent = 0;
 36  0
     private long executionError = 0;
 37  0
     private long fatalError = 0;
 38  0
     private long minExecutionTime = 0;
 39  0
     private long maxExecutionTime = 0;
 40  0
     private long averageExecutionTime = 0;
 41  0
     private boolean enabled = false;
 42  
 
 43  0
     private int threadPoolSize = 0;
 44  0
     private long samplePeriod = 0;
 45  
 
 46  0
     private RouterStatistics inboundRouterStat = null;
 47  0
     private RouterStatistics outboundRouterStat = null;
 48  
 
 49  
     /**
 50  
      * The constructor
 51  
      *
 52  
      * @param name
 53  
      */
 54  
     public ComponentStatistics(String name, int threadPoolSize)
 55  
     {
 56  0
         super();
 57  0
         this.name = name;
 58  
 
 59  0
         this.threadPoolSize = threadPoolSize;
 60  0
         clear();
 61  0
     }
 62  
 
 63  
     /**
 64  
      * Are statistics logged
 65  
      */
 66  
     public boolean isEnabled()
 67  
     {
 68  0
         return enabled;
 69  
     }
 70  
 
 71  
     /**
 72  
      * Enable statistics logs (this is a dynamic parameter)
 73  
      */
 74  
     public synchronized void setEnabled(boolean b)
 75  
     {
 76  0
         enabled = b;
 77  
 
 78  0
         if (inboundRouterStat != null)
 79  
         {
 80  0
             inboundRouterStat.setEnabled(b);
 81  
         }
 82  0
         if (outboundRouterStat != null)
 83  
         {
 84  0
             outboundRouterStat.setEnabled(b);
 85  
         }
 86  0
     }
 87  
 
 88  
     public synchronized void incReceivedEventSync()
 89  
     {
 90  0
         receivedEventSync++;
 91  0
     }
 92  
 
 93  
     public synchronized void incReceivedEventASync()
 94  
     {
 95  0
         receivedEventASync++;
 96  0
     }
 97  
 
 98  
     public synchronized void incExecutionError()
 99  
     {
 100  0
         executionError++;
 101  0
     }
 102  
 
 103  
     public synchronized void incFatalError()
 104  
     {
 105  0
         fatalError++;
 106  0
     }
 107  
 
 108  
     public synchronized void incSentEventSync()
 109  
     {
 110  0
         sentEventSync++;
 111  0
     }
 112  
 
 113  
     public synchronized void incSentEventASync()
 114  
     {
 115  0
         sentEventASync++;
 116  0
     }
 117  
 
 118  
     public synchronized void incSentReplyToEvent()
 119  
     {
 120  0
         sentReplyToEvent++;
 121  0
     }
 122  
 
 123  
     public synchronized void incQueuedEvent()
 124  
     {
 125  0
         queuedEvent++;
 126  0
         totalQueuedEvent++;
 127  0
         if (queuedEvent > maxQueuedEvent)
 128  
         {
 129  0
             maxQueuedEvent = queuedEvent;
 130  
         }
 131  
         // if(queuedEvent > 1) {
 132  0
         averageQueueSize = Math.round(getAsyncEventsReceived() / totalQueuedEvent);
 133  
         // }
 134  0
     }
 135  
 
 136  
     public synchronized void decQueuedEvent()
 137  
     {
 138  0
         queuedEvent--;
 139  0
     }
 140  
 
 141  
     public synchronized void addExecutionTime(long time)
 142  
     {
 143  0
         executedEvent++;
 144  
 
 145  0
         totalExecTime += (time == 0 ? 1 : time);
 146  
 
 147  0
         if (minExecutionTime == 0 || time < minExecutionTime)
 148  
         {
 149  0
             minExecutionTime = time;
 150  
         }
 151  0
         if (maxExecutionTime == 0 || time > maxExecutionTime)
 152  
         {
 153  0
             maxExecutionTime = time;
 154  
         }
 155  0
         averageExecutionTime = Math.round(totalExecTime / executedEvent);
 156  0
     }
 157  
 
 158  
     public long getAverageExecutionTime()
 159  
     {
 160  0
         return averageExecutionTime;
 161  
     }
 162  
 
 163  
     public long getAverageQueueSize()
 164  
     {
 165  0
         return averageQueueSize;
 166  
     }
 167  
 
 168  
     public long getMaxQueueSize()
 169  
     {
 170  0
         return maxQueuedEvent;
 171  
     }
 172  
 
 173  
     public long getMaxExecutionTime()
 174  
     {
 175  0
         return maxExecutionTime;
 176  
     }
 177  
 
 178  
     public long getFatalErrors()
 179  
     {
 180  0
         return fatalError;
 181  
     }
 182  
 
 183  
     public long getMinExecutionTime()
 184  
     {
 185  0
         return minExecutionTime;
 186  
     }
 187  
 
 188  
     public long getTotalExecutionTime()
 189  
     {
 190  0
         return totalExecTime;
 191  
     }
 192  
 
 193  
     public long getQueuedEvents()
 194  
     {
 195  0
         return queuedEvent;
 196  
     }
 197  
 
 198  
     public long getAsyncEventsReceived()
 199  
     {
 200  0
         return receivedEventASync;
 201  
     }
 202  
 
 203  
     public long getSyncEventsReceived()
 204  
     {
 205  0
         return receivedEventSync;
 206  
     }
 207  
 
 208  
     public long getReplyToEventsSent()
 209  
     {
 210  0
         return sentReplyToEvent;
 211  
     }
 212  
 
 213  
     public long getSyncEventsSent()
 214  
     {
 215  0
         return sentEventSync;
 216  
     }
 217  
 
 218  
     public long getAsyncEventsSent()
 219  
     {
 220  0
         return sentEventASync;
 221  
     }
 222  
 
 223  
     public long getTotalEventsSent()
 224  
     {
 225  0
         return getSyncEventsSent() + getAsyncEventsSent();
 226  
     }
 227  
 
 228  
     public long getTotalEventsReceived()
 229  
     {
 230  0
         return getSyncEventsReceived() + getAsyncEventsReceived();
 231  
     }
 232  
 
 233  
     public long getExecutedEvents()
 234  
     {
 235  0
         return executedEvent;
 236  
     }
 237  
 
 238  
     public long getExecutionErrors()
 239  
     {
 240  0
         return executionError;
 241  
     }
 242  
 
 243  
     public synchronized String getName()
 244  
     {
 245  0
         return name;
 246  
     }
 247  
 
 248  
     public synchronized void setName(String name)
 249  
     {
 250  0
         this.name = name;
 251  0
     }
 252  
 
 253  
     /**
 254  
      * log in info level the main statistics
 255  
      */
 256  
     public void logSummary()
 257  
     {
 258  0
         logSummary(new SimplePrinter(System.out));
 259  0
     }
 260  
 
 261  
     public void logSummary(PrintWriter printer)
 262  
     {
 263  0
         printer.print(this);
 264  0
     }
 265  
 
 266  
     public synchronized void clear()
 267  
     {
 268  
 
 269  0
         totalExecTime = 0;
 270  0
         receivedEventSync = 0;
 271  0
         receivedEventASync = 0;
 272  0
         queuedEvent = 0;
 273  0
         maxQueuedEvent = 0;
 274  0
         totalQueuedEvent = 0;
 275  0
         averageQueueSize = 0;
 276  
 
 277  0
         sentEventSync = 0;
 278  0
         sentEventASync = 0;
 279  0
         sentReplyToEvent = 0;
 280  
 
 281  0
         executedEvent = 0;
 282  0
         executionError = 0;
 283  0
         fatalError = 0;
 284  
 
 285  0
         minExecutionTime = 0;
 286  0
         maxExecutionTime = 0;
 287  
 
 288  0
         if (getInboundRouterStat() != null)
 289  
         {
 290  0
             getInboundRouterStat().clear();
 291  
         }
 292  0
         if (getOutboundRouterStat() != null)
 293  
         {
 294  0
             getOutboundRouterStat().clear();
 295  
         }
 296  
 
 297  0
         samplePeriod = System.currentTimeMillis();
 298  
 
 299  0
     }
 300  
 
 301  
     /**
 302  
      * @return Returns the inboundRouterStat.
 303  
      */
 304  
     public RouterStatistics getInboundRouterStat()
 305  
     {
 306  0
         return inboundRouterStat;
 307  
     }
 308  
 
 309  
     /**
 310  
      * @param inboundRouterStat The inboundRouterStat to set.
 311  
      */
 312  
     public void setInboundRouterStat(RouterStatistics inboundRouterStat)
 313  
     {
 314  0
         this.inboundRouterStat = inboundRouterStat;
 315  0
         this.inboundRouterStat.setEnabled(enabled);
 316  0
     }
 317  
 
 318  
     /**
 319  
      * @return Returns the outboundRouterStat.
 320  
      */
 321  
     public RouterStatistics getOutboundRouterStat()
 322  
     {
 323  0
         return outboundRouterStat;
 324  
     }
 325  
 
 326  
     /**
 327  
      * @param outboundRouterStat The outboundRouterStat to set.
 328  
      */
 329  
     public void setOutboundRouterStat(RouterStatistics outboundRouterStat)
 330  
     {
 331  0
         this.outboundRouterStat = outboundRouterStat;
 332  0
         this.outboundRouterStat.setEnabled(enabled);
 333  0
     }
 334  
 
 335  
     public int getThreadPoolSize()
 336  
     {
 337  0
         return threadPoolSize;
 338  
     }
 339  
 
 340  
     public long getSamplePeriod()
 341  
     {
 342  0
         return System.currentTimeMillis() - samplePeriod;
 343  
     }
 344  
 }