Coverage Report - org.mule.management.mbeans.ComponentStats
 
Classes in this File Line Coverage Branch Coverage Complexity
ComponentStats
47%
27/57
50%
6/12
1.346
 
 1  
 /*
 2  
  * $Id: ComponentStats.java 7963 2007-08-21 08:53:15Z 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.mbeans;
 12  
 
 13  
 import org.mule.management.stats.ComponentStatistics;
 14  
 import org.mule.management.stats.RouterStatistics;
 15  
 
 16  
 import javax.management.MBeanRegistration;
 17  
 import javax.management.MBeanServer;
 18  
 import javax.management.ObjectName;
 19  
 
 20  
 import org.apache.commons.logging.Log;
 21  
 import org.apache.commons.logging.LogFactory;
 22  
 
 23  
 /**
 24  
  * <code>ComponentStats</code> TODO
 25  
  */
 26  
 public class ComponentStats implements ComponentStatsMBean, MBeanRegistration
 27  
 {
 28  
 
 29  
     /**
 30  
      * logger used by this class
 31  
      */
 32  4
     private static Log LOGGER = LogFactory.getLog(ComponentStats.class);
 33  
 
 34  
     private MBeanServer server;
 35  
 
 36  
     private ObjectName name;
 37  
     private ObjectName inboundName;
 38  
     private ObjectName outboundName;
 39  
 
 40  
     private ComponentStatistics statistics;
 41  
 
 42  
     public ComponentStats(ComponentStatistics statistics)
 43  4
     {
 44  4
         this.statistics = statistics;
 45  4
     }
 46  
 
 47  
     /**
 48  
      * 
 49  
      */
 50  
     public void clearStatistics()
 51  
     {
 52  0
         statistics.clear();
 53  0
     }
 54  
 
 55  
     /**
 56  
      * @return
 57  
      */
 58  
     public long getAsyncEventsReceived()
 59  
     {
 60  0
         return statistics.getAsyncEventsReceived();
 61  
     }
 62  
 
 63  
     /**
 64  
      * @return
 65  
      */
 66  
     public long getAsyncEventsSent()
 67  
     {
 68  0
         return statistics.getAsyncEventsSent();
 69  
     }
 70  
 
 71  
     /**
 72  
      * @return
 73  
      */
 74  
     public long getAverageExecutionTime()
 75  
     {
 76  0
         return statistics.getAverageExecutionTime();
 77  
     }
 78  
 
 79  
     /**
 80  
      * @return
 81  
      */
 82  
     public long getAverageQueueSize()
 83  
     {
 84  0
         return statistics.getAverageQueueSize();
 85  
     }
 86  
 
 87  
     /**
 88  
      * @return
 89  
      */
 90  
     public long getExecutedEvents()
 91  
     {
 92  0
         return statistics.getExecutedEvents();
 93  
     }
 94  
 
 95  
     /**
 96  
      * @return
 97  
      */
 98  
     public long getExecutionErrors()
 99  
     {
 100  0
         return statistics.getExecutionErrors();
 101  
     }
 102  
 
 103  
     /**
 104  
      * @return
 105  
      */
 106  
     public long getFatalErrors()
 107  
     {
 108  0
         return statistics.getFatalErrors();
 109  
     }
 110  
 
 111  
     /**
 112  
      * @return
 113  
      */
 114  
     public long getMaxExecutionTime()
 115  
     {
 116  0
         return statistics.getMaxExecutionTime();
 117  
     }
 118  
 
 119  
     /**
 120  
      * @return
 121  
      */
 122  
     public long getMaxQueueSize()
 123  
     {
 124  0
         return statistics.getMaxQueueSize();
 125  
     }
 126  
 
 127  
     /**
 128  
      * @return
 129  
      */
 130  
     public long getMinExecutionTime()
 131  
     {
 132  0
         return statistics.getMinExecutionTime();
 133  
     }
 134  
 
 135  
     /**
 136  
      * @return
 137  
      */
 138  
     public String getName()
 139  
     {
 140  0
         return statistics.getName();
 141  
     }
 142  
 
 143  
     /**
 144  
      * @return
 145  
      */
 146  
     public long getQueuedEvents()
 147  
     {
 148  0
         return statistics.getQueuedEvents();
 149  
     }
 150  
 
 151  
     /**
 152  
      * @return
 153  
      */
 154  
     public long getReplyToEventsSent()
 155  
     {
 156  0
         return statistics.getReplyToEventsSent();
 157  
     }
 158  
 
 159  
     /**
 160  
      * @return
 161  
      */
 162  
     public long getSyncEventsReceived()
 163  
     {
 164  0
         return statistics.getSyncEventsReceived();
 165  
     }
 166  
 
 167  
     /**
 168  
      * @return
 169  
      */
 170  
     public long getSyncEventsSent()
 171  
     {
 172  0
         return statistics.getSyncEventsSent();
 173  
     }
 174  
 
 175  
     /**
 176  
      * @return
 177  
      */
 178  
     public long getTotalEventsReceived()
 179  
     {
 180  0
         return statistics.getTotalEventsReceived();
 181  
     }
 182  
 
 183  
     /**
 184  
      * @return
 185  
      */
 186  
     public long getTotalEventsSent()
 187  
     {
 188  0
         return statistics.getTotalEventsSent();
 189  
     }
 190  
 
 191  
     /**
 192  
      * @return
 193  
      */
 194  
     public long getTotalExecutionTime()
 195  
     {
 196  0
         return statistics.getTotalExecutionTime();
 197  
     }
 198  
 
 199  
     /*
 200  
      * (non-Javadoc)
 201  
      * 
 202  
      * @see javax.management.MBeanRegistration#preRegister(javax.management.MBeanServer,
 203  
      *      javax.management.ObjectName)
 204  
      */
 205  
     public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception
 206  
     {
 207  4
         this.server = server;
 208  4
         this.name = name;
 209  4
         return name;
 210  
     }
 211  
 
 212  
     /*
 213  
      * (non-Javadoc)
 214  
      * 
 215  
      * @see javax.management.MBeanRegistration#postRegister(java.lang.Boolean)
 216  
      */
 217  
     public void postRegister(Boolean registrationDone)
 218  
     {
 219  
 
 220  
         try
 221  
         {
 222  4
             RouterStatistics is = this.statistics.getInboundRouterStat();
 223  4
             if (is != null)
 224  
             {
 225  4
                 inboundName = new ObjectName(name.getDomain() + ":type=org.mule.Statistics,component="
 226  
                                              + statistics.getName() + ",router=inbound");
 227  
                 // unregister old version if exists
 228  4
                 if (this.server.isRegistered(inboundName))
 229  
                 {
 230  0
                     this.server.unregisterMBean(inboundName);
 231  
                 }
 232  4
                 this.server.registerMBean(new RouterStats(is), this.inboundName);
 233  
             }
 234  4
             RouterStatistics os = this.statistics.getOutboundRouterStat();
 235  4
             if (os != null)
 236  
             {
 237  4
                 outboundName = new ObjectName(name.getDomain() + ":type=org.mule.Statistics,component="
 238  
                                               + statistics.getName() + ",router=outbound");
 239  
                 // unregister old version if exists
 240  4
                 if (this.server.isRegistered(outboundName))
 241  
                 {
 242  0
                     this.server.unregisterMBean(outboundName);
 243  
                 }
 244  4
                 this.server.registerMBean(new RouterStats(os), this.outboundName);
 245  
             }
 246  
         }
 247  0
         catch (Exception e)
 248  
         {
 249  0
             LOGGER.error("Error post-registering MBean", e);
 250  4
         }
 251  
 
 252  4
     }
 253  
 
 254  
     /*
 255  
      * (non-Javadoc)
 256  
      * 
 257  
      * @see javax.management.MBeanRegistration#preDeregister()
 258  
      */
 259  
     public void preDeregister() throws Exception
 260  
     {
 261  
         // nothing to do
 262  4
     }
 263  
 
 264  
     /*
 265  
      * (non-Javadoc)
 266  
      * 
 267  
      * @see javax.management.MBeanRegistration#postDeregister()
 268  
      */
 269  
     public void postDeregister()
 270  
     {
 271  
         try
 272  
         {
 273  4
             if (this.server.isRegistered(inboundName))
 274  
             {
 275  4
                 this.server.unregisterMBean(inboundName);
 276  
             }
 277  
         }
 278  0
         catch (Exception ex)
 279  
         {
 280  0
             LOGGER.error("Error unregistering ComponentStats child " + inboundName.getCanonicalName(), ex);
 281  4
         }
 282  
         try
 283  
         {
 284  4
             if (this.server.isRegistered(outboundName))
 285  
             {
 286  4
                 this.server.unregisterMBean(outboundName);
 287  
             }
 288  
         }
 289  0
         catch (Exception ex)
 290  
         {
 291  0
             LOGGER.error("Error unregistering ComponentStats child " + inboundName.getCanonicalName(), ex);
 292  4
         }
 293  4
     }
 294  
 
 295  
     /*
 296  
      * (non-Javadoc)
 297  
      * 
 298  
      * @see org.mule.management.mbeans.ComponentStatsMBean#getInboundRouter()
 299  
      */
 300  
     public ObjectName getRouterInbound()
 301  
     {
 302  0
         return this.inboundName;
 303  
     }
 304  
 
 305  
     /*
 306  
      * (non-Javadoc)
 307  
      * 
 308  
      * @see org.mule.management.mbeans.ComponentStatsMBean#getOutboundRouter()
 309  
      */
 310  
     public ObjectName getRouterOutbound()
 311  
     {
 312  0
         return this.outboundName;
 313  
     }
 314  
 }