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