Coverage Report - org.mule.management.mbeans.YourKitProfilerService
 
Classes in this File Line Coverage Branch Coverage Complexity
YourKitProfilerService
0%
0/35
0%
0/4
1.235
YourKitProfilerService$1
0%
0/8
0%
0/2
1.235
 
 1  
 /*
 2  
  * $Id: YourKitProfilerService.java 9726 2007-11-15 14:17:11Z akuzmin $
 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.i18n.ManagementMessages;
 14  
 
 15  
 import com.yourkit.api.Controller;
 16  
 
 17  
 import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean;
 18  
 import org.apache.commons.logging.Log;
 19  
 import org.apache.commons.logging.LogFactory;
 20  
 
 21  0
 public class YourKitProfilerService implements YourKitProfilerServiceMBean
 22  
 {
 23  
     /**
 24  
      * logger used by this class
 25  
      */
 26  0
     protected transient Log logger = LogFactory.getLog(getClass());
 27  
 
 28  
     private final Controller controller;
 29  0
     private AtomicBoolean capturing = new AtomicBoolean(false);
 30  
 
 31  
     public YourKitProfilerService() throws Exception
 32  0
     {
 33  0
         controller = new Controller();
 34  0
     }
 35  
 
 36  
     /**
 37  
      * {@inheritDoc}
 38  
      */
 39  
     public String getHost()
 40  
     {
 41  0
         return controller.getHost();
 42  
     }
 43  
 
 44  
     /**
 45  
      * {@inheritDoc}
 46  
      */
 47  
     public int getPort()
 48  
     {
 49  0
         return controller.getPort();
 50  
     }
 51  
 
 52  
     /**
 53  
      * {@inheritDoc}
 54  
      */
 55  
     public String captureMemorySnapshot() throws Exception
 56  
     {
 57  0
         return controller.captureMemorySnapshot();
 58  
     }
 59  
 
 60  
     /**
 61  
      * {@inheritDoc}
 62  
      */
 63  
     public String captureSnapshot(long snapshotFlags) throws Exception
 64  
     {
 65  0
         return controller.captureSnapshot(snapshotFlags);
 66  
     }
 67  
 
 68  
     /**
 69  
      * {@inheritDoc}
 70  
      */
 71  
     public void startAllocationRecording(long mode) throws Exception
 72  
     {
 73  0
         controller.startAllocationRecording(mode);
 74  0
     }
 75  
 
 76  
     /**
 77  
      * {@inheritDoc}
 78  
      */
 79  
     public void stopAllocationRecording() throws Exception
 80  
     {
 81  0
         controller.stopAllocationRecording();
 82  0
     }
 83  
 
 84  
     /**
 85  
      * {@inheritDoc}
 86  
      */
 87  
     public void startCPUProfiling(long mode, String filters) throws Exception
 88  
     {
 89  0
         controller.startCPUProfiling(mode, filters);
 90  0
     }
 91  
 
 92  
     /**
 93  
      * {@inheritDoc}
 94  
      */
 95  
     public void stopCPUProfiling() throws Exception
 96  
     {
 97  0
         controller.stopCPUProfiling();
 98  0
     }
 99  
 
 100  
     /**
 101  
      * {@inheritDoc}
 102  
      */
 103  
     public void startMonitorProfiling() throws Exception
 104  
     {
 105  0
         controller.startMonitorProfiling();
 106  0
     }
 107  
 
 108  
     /**
 109  
      * {@inheritDoc}
 110  
      */
 111  
     public void stopMonitorProfiling() throws Exception
 112  
     {
 113  0
         controller.stopMonitorProfiling();
 114  0
     }
 115  
 
 116  
     /**
 117  
      * {@inheritDoc}
 118  
      */
 119  
     public void advanceGeneration(String description)
 120  
     {
 121  0
         controller.advanceGeneration(description);
 122  0
     }
 123  
 
 124  
     /**
 125  
      * {@inheritDoc}
 126  
      */
 127  
     public String forceGC() throws Exception
 128  
     {
 129  0
         long[] heapSizes = controller.forceGC();
 130  0
         return ManagementMessages.forceGC(heapSizes).getMessage();
 131  
     }
 132  
 
 133  
     /**
 134  
      * {@inheritDoc}
 135  
      */
 136  
     public void startCapturingMemSnapshot(final int seconds)
 137  
     {
 138  0
         if (!this.capturing.compareAndSet(false, true))
 139  
         {
 140  0
             return;
 141  
         }
 142  
 
 143  
 
 144  0
         final Thread thread = new Thread(
 145  
                 new Runnable()
 146  
                 {
 147  0
                     public void run()
 148  
                     {
 149  
                         try
 150  
                         {
 151  0
                             while (capturing.get())
 152  
                             {
 153  0
                                 controller.captureMemorySnapshot();
 154  0
                                 Thread.sleep(seconds * 1000 /* millis in second */);
 155  
                             }
 156  
                         }
 157  0
                         catch (Exception e)
 158  
                         {
 159  0
                             logger.error("Failed to capture memory snapshot", e);
 160  0
                         }
 161  0
                     }
 162  
                 }
 163  
         );
 164  0
         thread.setDaemon(true); // let the application normally terminate
 165  0
         thread.start();
 166  0
     }
 167  
 
 168  
     /**
 169  
      * {@inheritDoc}
 170  
      */
 171  
     public void stopCapturingMemSnapshot()
 172  
     {
 173  0
         this.capturing.set(false);
 174  0
     }
 175  
 
 176  
 
 177  
     /**
 178  
      * {@inheritDoc}
 179  
      */
 180  
     public long getStatus() throws java.lang.Exception
 181  
     {
 182  0
         return (this.capturing.get()) ? (controller.getStatus() | SNAPSHOT_CAPTURING) : controller.getStatus();
 183  
     }
 184  
 
 185  
 }