Coverage Report - org.mule.module.management.mbean.ServiceService
 
Classes in this File Line Coverage Branch Coverage Complexity
ServiceService
0%
0/57
0%
0/6
1.152
 
 1  
 /*
 2  
  * $Id: ServiceService.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.module.management.mbean;
 12  
 
 13  
 import org.mule.api.MuleContext;
 14  
 import org.mule.api.MuleException;
 15  
 import org.mule.api.config.MuleConfiguration;
 16  
 import org.mule.api.service.Service;
 17  
 import org.mule.management.stats.ServiceStatistics;
 18  
 import org.mule.model.seda.SedaService;
 19  
 import org.mule.service.AbstractService;
 20  
 
 21  
 import javax.management.MBeanRegistration;
 22  
 import javax.management.MBeanServer;
 23  
 import javax.management.ObjectName;
 24  
 
 25  
 import org.apache.commons.logging.Log;
 26  
 import org.apache.commons.logging.LogFactory;
 27  
 
 28  
 /**
 29  
  * <code>ServiceService</code> exposes service information about a Mule Managed
 30  
  * service.
 31  
  */
 32  
 public class ServiceService extends FlowConstructService implements ServiceServiceMBean, MBeanRegistration, ServiceStatsMBean
 33  
 {
 34  
 
 35  
     /**
 36  
      * logger used by this class
 37  
      */
 38  0
     private static Log LOGGER = LogFactory.getLog(ServiceService.class);
 39  
 
 40  
     private ServiceStatistics  statistics;
 41  
 
 42  
     public ServiceService(String name, MuleContext muleContext)
 43  
     {
 44  0
         super("Service", name, muleContext);
 45  0
         this.statistics = getComponent().getStatistics();
 46  0
         super.statistics = statistics;
 47  0
     }
 48  
 
 49  
     public int getQueueSize()
 50  
     {
 51  0
         Service c = getComponent();
 52  0
         if (c instanceof SedaService)
 53  
         {
 54  0
             return (int) c.getStatistics().getQueuedEvents();
 55  
         }
 56  
         else
 57  
         {
 58  0
             return -1;
 59  
         }
 60  
     }
 61  
 
 62  
     /**
 63  
      * Pauses event processing for theComponent. Unlike stop(), a paused service
 64  
      * will still consume messages from the underlying transport, but those messages
 65  
      * will be queued until the service is resumed. <p/> In order to persist these
 66  
      * queued messages you can set the 'recoverableMode' property on the
 67  
      * Muleconfiguration to true. this causes all internal queues to store their
 68  
      * state.
 69  
      * 
 70  
      * @throws MuleException if the service failed to pause.
 71  
      * @see MuleConfiguration
 72  
      */
 73  
     public void pause() throws MuleException
 74  
     {
 75  0
         getComponent().pause();
 76  0
     }
 77  
 
 78  
     /**
 79  
      * Resumes the Service that has been paused. If the service is not paused
 80  
      * nothing is executed.
 81  
      * 
 82  
      * @throws MuleException if the service failed to resume
 83  
      */
 84  
     public void resume() throws MuleException
 85  
     {
 86  0
         getComponent().resume();
 87  0
     }
 88  
 
 89  
     public boolean isPaused()
 90  
     {
 91  0
         return getComponent().isPaused();
 92  
     }
 93  
 
 94  
     public boolean isStopped()
 95  
     {
 96  0
         return getComponent().isStopped();
 97  
     }
 98  
 
 99  
     public void stop() throws MuleException
 100  
     {
 101  0
         getComponent().stop();
 102  0
     }
 103  
 
 104  
     public void forceStop() throws MuleException
 105  
     {
 106  0
         getComponent().forceStop();
 107  0
     }
 108  
 
 109  
     public boolean isStopping()
 110  
     {
 111  0
         return getComponent().isStopping();
 112  
     }
 113  
 
 114  
     public void dispose() throws MuleException
 115  
     {
 116  0
         getComponent().dispose();
 117  0
     }
 118  
 
 119  
     public void start() throws MuleException
 120  
     {
 121  0
         getComponent().start();
 122  0
     }
 123  
 
 124  
     public ObjectName getStatistics()
 125  
     {
 126  0
         return statsName;
 127  
     }
 128  
 
 129  
     public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception
 130  
     {
 131  0
         return super.preRegister(server, name);
 132  
     }
 133  
 
 134  
     public void postRegister(Boolean registrationDone)
 135  
     {
 136  
         try
 137  
         {
 138  0
             if (getComponent().getStatistics() != null)
 139  
             {
 140  0
                 statsName = new ObjectName(objectName.getDomain() + ":type=org.mule.Statistics,service="
 141  
                                            + getName());
 142  
                 // unregister old version if exists
 143  0
                 if (this.server.isRegistered(statsName))
 144  
                 {
 145  0
                     this.server.unregisterMBean(statsName);
 146  
                 }
 147  
 
 148  0
                 this.server.registerMBean(new ServiceStats(getComponent().getStatistics()), this.statsName);
 149  
             }
 150  
         }
 151  0
         catch (Exception e)
 152  
         {
 153  0
             LOGGER.error("Error post-registering the MBean", e);
 154  0
         }
 155  0
     }
 156  
 
 157  
     public void preDeregister() throws Exception
 158  
     {
 159  0
         super.preDeregister();
 160  0
     }
 161  
 
 162  
     public void postDeregister()
 163  
     {
 164  0
         super.postDeregister();
 165  0
     }
 166  
 
 167  
     private AbstractService getComponent()
 168  
     {
 169  0
         return (AbstractService)muleContext.getRegistry().lookupService(getName());
 170  
     }
 171  
 
 172  
     // ///// Service stats impl /////////
 173  
     public void clearStatistics()
 174  
     {
 175  0
         statistics.clear();
 176  0
     }
 177  
 
 178  
     public long getAsyncEventsReceived()
 179  
     {
 180  0
         return statistics.getAsyncEventsReceived();
 181  
     }
 182  
 
 183  
     public long getSyncEventsReceived()
 184  
     {
 185  0
         return statistics.getSyncEventsReceived();
 186  
     }
 187  
 
 188  
     public long getTotalEventsReceived()
 189  
     {
 190  0
         return statistics.getTotalEventsReceived();
 191  
     }
 192  
 
 193  
     public long getAsyncEventsSent()
 194  
     {
 195  0
         return statistics.getAsyncEventsSent();
 196  
     }
 197  
 
 198  
     public long getAverageExecutionTime()
 199  
     {
 200  0
         return statistics.getAverageExecutionTime();
 201  
     }
 202  
 
 203  
     public long getAverageQueueSize()
 204  
     {
 205  0
         return statistics.getAverageQueueSize();
 206  
     }
 207  
 
 208  
     public long getExecutedEvents()
 209  
     {
 210  0
         return statistics.getExecutedEvents();
 211  
     }
 212  
 
 213  
     public long getMaxExecutionTime()
 214  
     {
 215  0
         return statistics.getMaxExecutionTime();
 216  
     }
 217  
 
 218  
     public long getMaxQueueSize()
 219  
     {
 220  0
         return statistics.getMaxQueueSize();
 221  
     }
 222  
 
 223  
     public long getMinExecutionTime()
 224  
     {
 225  0
         return statistics.getMinExecutionTime();
 226  
     }
 227  
 
 228  
     public long getQueuedEvents()
 229  
     {
 230  0
         return statistics.getQueuedEvents();
 231  
     }
 232  
 
 233  
     public long getReplyToEventsSent()
 234  
     {
 235  0
         return statistics.getReplyToEventsSent();
 236  
     }
 237  
 
 238  
     public long getSyncEventsSent()
 239  
     {
 240  0
         return statistics.getSyncEventsSent();
 241  
     }
 242  
 
 243  
     public long getTotalEventsSent()
 244  
     {
 245  0
         return statistics.getTotalEventsSent();
 246  
     }
 247  
 
 248  
     public long getTotalExecutionTime()
 249  
     {
 250  0
         return statistics.getTotalExecutionTime();
 251  
     }
 252  
 }