Coverage Report - org.mule.management.mbeans.MuleService
 
Classes in this File Line Coverage Branch Coverage Complexity
MuleService
25%
15/61
8%
2/26
1.458
 
 1  
 /*
 2  
  * $Id: MuleService.java 10003 2007-12-05 18:00:51Z aperepel $
 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.MuleManager;
 14  
 import org.mule.MuleServer;
 15  
 import org.mule.config.MuleManifest;
 16  
 import org.mule.umo.UMOException;
 17  
 import org.mule.util.IOUtils;
 18  
 import org.mule.util.StringMessageUtils;
 19  
 
 20  
 import java.io.IOException;
 21  
 import java.net.InetAddress;
 22  
 import java.net.UnknownHostException;
 23  
 import java.util.Date;
 24  
 
 25  
 import org.apache.commons.logging.Log;
 26  
 import org.apache.commons.logging.LogFactory;
 27  
 
 28  
 /**
 29  
  * <code>MuleService</code> exposes certain Mule server functions for management
 30  
  */
 31  
 public class MuleService implements MuleServiceMBean
 32  
 {
 33  
     /**
 34  
      * logger used by this class
 35  
      */
 36  18
     protected transient Log logger = LogFactory.getLog(getClass());
 37  
 
 38  
     private String version;
 39  
     private String vendor;
 40  
     private String jdk;
 41  
     private String host;
 42  
     private String ip;
 43  
     private String os;
 44  
     private String buildNumber;
 45  
     private String buildDate;
 46  
     // TODO
 47  18
     private String copyright = "Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com";
 48  
     private String license;
 49  
 
 50  
 
 51  
     public MuleService()
 52  18
     {
 53  18
         String patch = System.getProperty("sun.os.patch.level", null);
 54  18
         jdk = System.getProperty("java.version") + " (" + System.getProperty("java.vm.info") + ")";
 55  18
         os = System.getProperty("os.name");
 56  18
         if (patch != null && !"unknown".equalsIgnoreCase(patch))
 57  
         {
 58  0
             os += " - " + patch;
 59  
         }
 60  18
         os += " (" + System.getProperty("os.version") + ", " + System.getProperty("os.arch") + ")";
 61  
 
 62  18
         buildNumber = MuleManifest.getBuildNumber();
 63  18
         buildDate = MuleManifest.getBuildDate();
 64  
         try
 65  
         {
 66  18
             InetAddress iad = InetAddress.getLocalHost();
 67  18
             host = iad.getCanonicalHostName();
 68  18
             ip = iad.getHostAddress();
 69  
         }
 70  0
         catch (UnknownHostException e)
 71  
         {
 72  
             // ignore
 73  18
         }
 74  18
     }
 75  
 
 76  
     public boolean isInstanciated()
 77  
     {
 78  0
         return MuleManager.isInstanciated();
 79  
     }
 80  
 
 81  
     public boolean isInitialised()
 82  
     {
 83  0
         return isInstanciated() && MuleManager.getInstance().isInitialised();
 84  
     }
 85  
 
 86  
     public boolean isStopped()
 87  
     {
 88  0
         return isInstanciated() && !MuleManager.getInstance().isStarted();
 89  
     }
 90  
 
 91  
     public Date getStartTime()
 92  
     {
 93  0
         if (!isStopped())
 94  
         {
 95  0
             return new Date(MuleManager.getInstance().getStartDate());
 96  
         }
 97  
         else
 98  
         {
 99  0
             return null;
 100  
         }
 101  
     }
 102  
 
 103  
     public String getVersion()
 104  
     {
 105  0
         if (version == null)
 106  
         {
 107  0
             version = MuleManifest.getProductVersion();
 108  0
             if (version == null)
 109  
             {
 110  0
                 version = "Mule Version Info Not Set";
 111  
             }
 112  
         }
 113  0
         return version;
 114  
     }
 115  
 
 116  
     public String getVendor()
 117  
     {
 118  0
         if (vendor == null)
 119  
         {
 120  0
             vendor = MuleManifest.getVendorName();
 121  0
             if (vendor == null)
 122  
             {
 123  0
                 vendor = "Mule Vendor Info Not Set";
 124  
             }
 125  
         }
 126  0
         return vendor;
 127  
     }
 128  
 
 129  
     public void start() throws UMOException
 130  
     {
 131  0
         MuleManager.getInstance().start();
 132  0
     }
 133  
 
 134  
     public void stop() throws UMOException
 135  
     {
 136  0
         MuleManager.getInstance().stop();
 137  0
     }
 138  
 
 139  
     public void dispose() throws UMOException
 140  
     {
 141  0
         MuleManager.getInstance().dispose();
 142  0
     }
 143  
 
 144  
     public long getFreeMemory()
 145  
     {
 146  0
         return Runtime.getRuntime().freeMemory();
 147  
     }
 148  
 
 149  
     public long getMaxMemory()
 150  
     {
 151  0
         return Runtime.getRuntime().maxMemory();
 152  
     }
 153  
 
 154  
     public long getTotalMemory()
 155  
     {
 156  0
         return Runtime.getRuntime().totalMemory();
 157  
     }
 158  
 
 159  
     public String getServerId()
 160  
     {
 161  0
         return MuleManager.getInstance().getId();
 162  
     }
 163  
 
 164  
     public String getHostname()
 165  
     {
 166  0
         return host;
 167  
     }
 168  
 
 169  
     public String getHostIp()
 170  
     {
 171  0
         return ip;
 172  
     }
 173  
 
 174  
     public String getOsVersion()
 175  
     {
 176  0
         return os;
 177  
     }
 178  
 
 179  
     public String getJdkVersion()
 180  
     {
 181  0
         return jdk;
 182  
     }
 183  
 
 184  
     public String getCopyright()
 185  
     {
 186  0
         return copyright;
 187  
     }
 188  
 
 189  
     public String getLicense()
 190  
     {
 191  0
         if (license == null)
 192  
         {
 193  
             try
 194  
             {
 195  0
                 license = IOUtils.getResourceAsString("MULE_LICENSE.txt", getClass());
 196  0
                 license = StringMessageUtils.getBoilerPlate(license, ' ', 80);
 197  
             }
 198  0
             catch (IOException e)
 199  
             {
 200  0
                 logger.warn("Failed to load MULE_LICENSE.txt", e);
 201  0
             }
 202  0
             if (license == null)
 203  
             {
 204  0
                 license = "Failed to load license";
 205  
             }
 206  
         }
 207  0
         return license;
 208  
     }
 209  
 
 210  
     public String getBuildDate()
 211  
     {
 212  0
         return buildDate;
 213  
     }
 214  
     
 215  
     public String getBuildNumber()
 216  
     {
 217  0
         return buildNumber;
 218  
     }
 219  
 
 220  
     public String getInstanceId()
 221  
     {
 222  0
         return MuleManager.getInstance().getId();
 223  
     }
 224  
 
 225  
     public String getConfigBuilderClassName()
 226  
     {
 227  0
         return MuleServer.getConfigBuilderClassName();
 228  
     }
 229  
 }