Coverage Report - org.mule.management.stats.ServiceStatistics
 
Classes in this File Line Coverage Branch Coverage Complexity
ServiceStatistics
0%
0/80
0%
0/14
0
 
 1  
 /*
 2  
  * $Id: ServiceStatistics.java 20288 2010-11-22 01:19:54Z mike.schilling $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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 java.io.PrintWriter;
 14  
 
 15  
 import org.mule.management.stats.printers.SimplePrinter;
 16  
 
 17  
 import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicLong;
 18  
 
 19  
 public class ServiceStatistics extends FlowConstructStatistics implements QueueStatistics
 20  
 {
 21  
     private static final long serialVersionUID = -2086999226732861675L;
 22  
 
 23  0
     private final AtomicLong sentEventSync = new AtomicLong(0);
 24  0
     private final AtomicLong sentReplyToEvent = new AtomicLong(0);
 25  0
     private final AtomicLong sentEventASync = new AtomicLong(0);
 26  
 
 27  
     // these can't sensibly converted to AtomicLong as they are processed together
 28  
     // in incQueuedEvent
 29  0
     private long queuedEvent = 0;
 30  0
     private long maxQueuedEvent = 0;
 31  0
     private long averageQueueSize = 0;
 32  0
     private long totalQueuedEvent = 0;
 33  
 
 34  0
     private RouterStatistics inboundRouterStat = null;
 35  0
     private ComponentStatistics componentStat = null;
 36  0
     private RouterStatistics outboundRouterStat = null;
 37  
 
 38  
     public ServiceStatistics(String name)
 39  
     {
 40  0
         this(name, 0);
 41  0
     }
 42  
 
 43  
     public ServiceStatistics(String name, int threadPoolSize)
 44  
     {
 45  0
         super("Service", name, threadPoolSize);
 46  0
         clear();
 47  0
     }
 48  
 
 49  
     /**
 50  
      * Enable statistics logs (this is a dynamic parameter)
 51  
      */
 52  
     @Override
 53  
     public synchronized void setEnabled(boolean b)
 54  
     {
 55  0
         super.setEnabled(b);
 56  
 
 57  0
         if (inboundRouterStat != null)
 58  
         {
 59  0
             inboundRouterStat.setEnabled(b);
 60  
         }
 61  0
         if (componentStat != null)
 62  
         {
 63  0
             componentStat.setEnabled(b);
 64  
         }
 65  0
         if (outboundRouterStat != null)
 66  
         {
 67  0
             outboundRouterStat.setEnabled(b);
 68  
         }
 69  0
     }
 70  
 
 71  
     public void incSentEventSync()
 72  
     {
 73  0
         sentEventSync.addAndGet(1);
 74  0
     }
 75  
 
 76  
     public void incSentEventASync()
 77  
     {
 78  0
         sentEventASync.addAndGet(1);
 79  0
     }
 80  
 
 81  
     public void incSentReplyToEvent()
 82  
     {
 83  0
         sentReplyToEvent.addAndGet(1);
 84  0
     }
 85  
 
 86  
     public synchronized void incQueuedEvent()
 87  
     {
 88  0
         queuedEvent++;
 89  0
         totalQueuedEvent++;
 90  0
         if (queuedEvent > maxQueuedEvent)
 91  
         {
 92  0
             maxQueuedEvent = queuedEvent;
 93  
         }
 94  0
         averageQueueSize = receivedEventASync.get() / totalQueuedEvent;
 95  0
     }
 96  
 
 97  
     public synchronized void decQueuedEvent()
 98  
     {
 99  0
         queuedEvent--;
 100  0
     }
 101  
 
 102  
     public long getAverageExecutionTime()
 103  
     {
 104  0
         return componentStat.getAverageExecutionTime();
 105  
     }
 106  
 
 107  
     public synchronized long getAverageQueueSize()
 108  
     {
 109  0
         return averageQueueSize;
 110  
     }
 111  
 
 112  
     public synchronized long getMaxQueueSize()
 113  
     {
 114  0
         return maxQueuedEvent;
 115  
     }
 116  
 
 117  
     /**
 118  
      * @deprecated
 119  
      */
 120  
     @Deprecated
 121  
     public long getMaxExecutionTime()
 122  
     {
 123  0
         return componentStat.getMaxExecutionTime();
 124  
     }
 125  
 
 126  
     /**
 127  
      * @deprecated
 128  
      */
 129  
     @Deprecated
 130  
     public long getMinExecutionTime()
 131  
     {
 132  0
         return componentStat.getMinExecutionTime();
 133  
     }
 134  
 
 135  
     /**
 136  
      * @deprecated
 137  
      */
 138  
     @Deprecated
 139  
     public long getTotalExecutionTime()
 140  
     {
 141  0
         return componentStat.getTotalExecutionTime();
 142  
     }
 143  
 
 144  
     public synchronized long getQueuedEvents()
 145  
     {
 146  0
         return queuedEvent;
 147  
     }
 148  
 
 149  
     public long getReplyToEventsSent()
 150  
     {
 151  0
         return sentReplyToEvent.get();
 152  
     }
 153  
 
 154  
     public long getSyncEventsSent()
 155  
     {
 156  0
         return sentEventSync.get();
 157  
     }
 158  
 
 159  
     public long getAsyncEventsSent()
 160  
     {
 161  0
         return sentEventASync.get();
 162  
     }
 163  
 
 164  
     public long getTotalEventsSent()
 165  
     {
 166  0
         return getSyncEventsSent() + getAsyncEventsSent();
 167  
     }
 168  
 
 169  
     public long getExecutedEvents()
 170  
     {
 171  0
         return componentStat.getExecutedEvents();
 172  
     }
 173  
 
 174  
     public void logSummary()
 175  
     {
 176  0
         logSummary(new SimplePrinter(System.out));
 177  0
     }
 178  
 
 179  
     public void logSummary(PrintWriter printer)
 180  
     {
 181  0
         printer.print(this);
 182  0
     }
 183  
 
 184  
     @Override
 185  
     public synchronized void clear()
 186  
     {
 187  0
         super.clear();
 188  0
         queuedEvent = 0;
 189  0
         maxQueuedEvent = 0;
 190  0
         totalQueuedEvent = 0;
 191  0
         averageQueueSize = 0;
 192  
 
 193  0
         sentEventSync.set(0);
 194  0
         sentEventASync.set(0);
 195  0
         sentReplyToEvent.set(0);
 196  
 
 197  0
         if (getComponentStat() != null)
 198  
         {
 199  0
             getComponentStat().clear();
 200  
         }
 201  0
         if (getInboundRouterStat() != null)
 202  
         {
 203  0
             getInboundRouterStat().clear();
 204  
         }
 205  0
         if (getOutboundRouterStat() != null)
 206  
         {
 207  0
             getOutboundRouterStat().clear();
 208  
         }
 209  0
     }
 210  
 
 211  
     public RouterStatistics getInboundRouterStat()
 212  
     {
 213  0
         return inboundRouterStat;
 214  
     }
 215  
 
 216  
     public void setInboundRouterStat(RouterStatistics inboundRouterStat)
 217  
     {
 218  0
         this.inboundRouterStat = inboundRouterStat;
 219  0
         this.inboundRouterStat.setEnabled(enabled);
 220  0
     }
 221  
 
 222  
     public RouterStatistics getOutboundRouterStat()
 223  
     {
 224  0
         return outboundRouterStat;
 225  
     }
 226  
 
 227  
     public void setOutboundRouterStat(RouterStatistics outboundRouterStat)
 228  
     {
 229  0
         this.outboundRouterStat = outboundRouterStat;
 230  0
         this.outboundRouterStat.setEnabled(enabled);
 231  0
     }
 232  
 
 233  
     public ComponentStatistics getComponentStat()
 234  
     {
 235  0
         return componentStat;
 236  
     }
 237  
 
 238  
     public void setComponentStat(ComponentStatistics componentStat)
 239  
     {
 240  0
         this.componentStat = componentStat;
 241  0
         this.componentStat.setEnabled(enabled);
 242  0
     }
 243  
 }