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