1
2
3
4
5
6
7
8
9
10
11 package org.mule.module.management.mbean;
12
13 import org.mule.MuleServer;
14 import org.mule.api.MuleContext;
15 import org.mule.api.MuleException;
16 import org.mule.config.MuleManifest;
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
30
31 public class MuleService implements MuleServiceMBean
32 {
33
34
35
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 buildNumber;
45 private String buildDate;
46
47 private String copyright = "Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com";
48 private String license;
49
50 private MuleContext muleContext;
51
52 public MuleService(MuleContext muleContext)
53 {
54 this.muleContext = muleContext;
55 String patch = System.getProperty("sun.os.patch.level", null);
56 jdk = System.getProperty("java.version") + " (" + System.getProperty("java.vm.info") + ")";
57 os = System.getProperty("os.name");
58 if (patch != null && !"unknown".equalsIgnoreCase(patch))
59 {
60 os += " - " + patch;
61 }
62 os += " (" + System.getProperty("os.version") + ", " + System.getProperty("os.arch") + ")";
63
64 buildNumber = MuleManifest.getBuildNumber();
65 buildDate = MuleManifest.getBuildDate();
66 try
67 {
68 InetAddress iad = InetAddress.getLocalHost();
69 host = iad.getCanonicalHostName();
70 ip = iad.getHostAddress();
71 }
72 catch (UnknownHostException e)
73 {
74
75 }
76 }
77
78 public boolean isInitialised()
79 {
80 return muleContext!=null && muleContext.isInitialised();
81 }
82
83 public boolean isStopped()
84 {
85 return muleContext!=null && !muleContext.isStarted();
86 }
87
88 public Date getStartTime()
89 {
90 if (!isStopped())
91 {
92 return new Date(muleContext.getStartDate());
93 }
94 else
95 {
96 return null;
97 }
98 }
99
100 public String getVersion()
101 {
102 if (version == null)
103 {
104 version = MuleManifest.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 = MuleManifest.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 MuleException
127 {
128 muleContext.start();
129 }
130
131 public void stop() throws MuleException
132 {
133 muleContext.stop();
134 }
135
136 public void dispose() throws MuleException
137 {
138 muleContext.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 muleContext.getConfiguration().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 MULE_LICENSE.txt", e);
198 }
199 if (license == null)
200 {
201 license = "Failed to load license";
202 }
203 }
204 return license;
205 }
206
207
208
209
210 public String getBuildDate()
211 {
212 return buildDate;
213 }
214
215 public String getBuildNumber()
216 {
217 return buildNumber;
218 }
219
220 public String getInstanceId()
221 {
222 return muleContext.getConfiguration().getId();
223 }
224
225 public String getConfigBuilderClassName()
226 {
227 return MuleServer.getConfigBuilderClassName();
228 }
229 }