001: /*
002: * $Id: MuleService.java 11371 2008-03-15 03:12:09Z tcarlson $
003: * --------------------------------------------------------------------------------------
004: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
005: *
006: * The software in this package is published under the terms of the CPAL v1.0
007: * license, a copy of which has been included with this distribution in the
008: * LICENSE.txt file.
009: */
010:
011: package org.mule.module.management.mbean;
012:
013: import org.mule.MuleServer;
014: import org.mule.api.MuleContext;
015: import org.mule.api.MuleException;
016: import org.mule.config.MuleManifest;
017: import org.mule.util.IOUtils;
018: import org.mule.util.StringMessageUtils;
019:
020: import java.io.IOException;
021: import java.net.InetAddress;
022: import java.net.UnknownHostException;
023: import java.util.Date;
024:
025: import org.apache.commons.logging.Log;
026: import org.apache.commons.logging.LogFactory;
027:
028: /**
029: * <code>MuleService</code> exposes certain Mule server functions for management
030: */
031: public class MuleService implements MuleServiceMBean {
032: /**
033: * logger used by this class
034: */
035: protected transient Log logger = LogFactory.getLog(getClass());
036:
037: private String version;
038: private String vendor;
039: private String jdk;
040: private String host;
041: private String ip;
042: private String os;
043: private String buildNumber;
044: private String buildDate;
045: // TODO
046: private String copyright = "Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com";
047: private String license;
048:
049: private MuleContext muleContext;
050:
051: public MuleService(MuleContext muleContext) {
052: this .muleContext = muleContext;
053: String patch = System.getProperty("sun.os.patch.level", null);
054: jdk = System.getProperty("java.version") + " ("
055: + System.getProperty("java.vm.info") + ")";
056: os = System.getProperty("os.name");
057: if (patch != null && !"unknown".equalsIgnoreCase(patch)) {
058: os += " - " + patch;
059: }
060: os += " (" + System.getProperty("os.version") + ", "
061: + System.getProperty("os.arch") + ")";
062:
063: buildNumber = MuleManifest.getBuildNumber();
064: buildDate = MuleManifest.getBuildDate();
065: try {
066: InetAddress iad = InetAddress.getLocalHost();
067: host = iad.getCanonicalHostName();
068: ip = iad.getHostAddress();
069: } catch (UnknownHostException e) {
070: // ignore
071: }
072: }
073:
074: public boolean isInitialised() {
075: return muleContext != null && muleContext.isInitialised();
076: }
077:
078: public boolean isStopped() {
079: return muleContext != null && !muleContext.isStarted();
080: }
081:
082: public Date getStartTime() {
083: if (!isStopped()) {
084: return new Date(muleContext.getStartDate());
085: } else {
086: return null;
087: }
088: }
089:
090: public String getVersion() {
091: if (version == null) {
092: version = MuleManifest.getProductVersion();
093: if (version == null) {
094: version = "Mule Version Info Not Set";
095: }
096: }
097: return version;
098: }
099:
100: public String getVendor() {
101: if (vendor == null) {
102: vendor = MuleManifest.getVendorName();
103: if (vendor == null) {
104: vendor = "Mule Vendor Info Not Set";
105: }
106: }
107: return vendor;
108: }
109:
110: public void start() throws MuleException {
111: muleContext.start();
112: }
113:
114: public void stop() throws MuleException {
115: muleContext.stop();
116: }
117:
118: public void dispose() throws MuleException {
119: muleContext.dispose();
120: }
121:
122: public long getFreeMemory() {
123: return Runtime.getRuntime().freeMemory();
124: }
125:
126: public long getMaxMemory() {
127: return Runtime.getRuntime().maxMemory();
128: }
129:
130: public long getTotalMemory() {
131: return Runtime.getRuntime().totalMemory();
132: }
133:
134: public String getServerId() {
135: return muleContext.getConfiguration().getId();
136: }
137:
138: public String getHostname() {
139: return host;
140: }
141:
142: public String getHostIp() {
143: return ip;
144: }
145:
146: public String getOsVersion() {
147: return os;
148: }
149:
150: public String getJdkVersion() {
151: return jdk;
152: }
153:
154: public String getCopyright() {
155: return copyright;
156: }
157:
158: public String getLicense() {
159: if (license == null) {
160: try {
161: license = IOUtils.getResourceAsString(
162: "MULE_LICENSE.txt", getClass());
163: license = StringMessageUtils.getBoilerPlate(license,
164: ' ', 80);
165: } catch (IOException e) {
166: logger.warn("Failed to load MULE_LICENSE.txt", e);
167: }
168: if (license == null) {
169: license = "Failed to load license";
170: }
171: }
172: return license;
173: }
174:
175: /**
176: * @deprecated use getBuildNumber() instead
177: */
178: public String getBuildDate() {
179: return buildDate;
180: }
181:
182: public String getBuildNumber() {
183: return buildNumber;
184: }
185:
186: public String getInstanceId() {
187: return muleContext.getConfiguration().getId();
188: }
189:
190: public String getConfigBuilderClassName() {
191: return MuleServer.getConfigBuilderClassName();
192: }
193: }
|