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