1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.module.management.mbean; |
8 | |
|
9 | |
import org.mule.MuleServer; |
10 | |
import org.mule.api.MuleContext; |
11 | |
import org.mule.api.MuleException; |
12 | |
import org.mule.config.MuleManifest; |
13 | |
import org.mule.util.IOUtils; |
14 | |
import org.mule.util.StringMessageUtils; |
15 | |
|
16 | |
import java.io.IOException; |
17 | |
import java.net.InetAddress; |
18 | |
import java.net.UnknownHostException; |
19 | |
import java.util.Date; |
20 | |
|
21 | |
import org.apache.commons.logging.Log; |
22 | |
import org.apache.commons.logging.LogFactory; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
public class MuleService implements MuleServiceMBean |
28 | |
{ |
29 | |
|
30 | |
|
31 | |
|
32 | 0 | protected transient Log logger = LogFactory.getLog(getClass()); |
33 | |
|
34 | |
private String version; |
35 | |
private String vendor; |
36 | |
private String jdk; |
37 | |
private String host; |
38 | |
private String ip; |
39 | |
private String os; |
40 | |
private String buildNumber; |
41 | |
private String buildDate; |
42 | |
|
43 | 0 | private String copyright = "Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com"; |
44 | |
private String license; |
45 | |
|
46 | |
private MuleContext muleContext; |
47 | |
|
48 | |
public MuleService(MuleContext muleContext) |
49 | 0 | { |
50 | 0 | this.muleContext = muleContext; |
51 | 0 | String patch = System.getProperty("sun.os.patch.level", null); |
52 | 0 | jdk = System.getProperty("java.version") + " (" + System.getProperty("java.vm.info") + ")"; |
53 | 0 | os = System.getProperty("os.name"); |
54 | 0 | if (patch != null && !"unknown".equalsIgnoreCase(patch)) |
55 | |
{ |
56 | 0 | os += " - " + patch; |
57 | |
} |
58 | 0 | os += " (" + System.getProperty("os.version") + ", " + System.getProperty("os.arch") + ")"; |
59 | |
|
60 | 0 | buildNumber = MuleManifest.getBuildNumber(); |
61 | 0 | buildDate = MuleManifest.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 | |
|
71 | 0 | } |
72 | 0 | } |
73 | |
|
74 | |
public boolean isInitialised() |
75 | |
{ |
76 | 0 | return muleContext!=null && muleContext.isInitialised(); |
77 | |
} |
78 | |
|
79 | |
public boolean isStopped() |
80 | |
{ |
81 | 0 | return muleContext!=null && !muleContext.isStarted(); |
82 | |
} |
83 | |
|
84 | |
public Date getStartTime() |
85 | |
{ |
86 | 0 | if (!isStopped()) |
87 | |
{ |
88 | 0 | return new Date(muleContext.getStartDate()); |
89 | |
} |
90 | |
else |
91 | |
{ |
92 | 0 | return null; |
93 | |
} |
94 | |
} |
95 | |
|
96 | |
public String getVersion() |
97 | |
{ |
98 | 0 | if (version == null) |
99 | |
{ |
100 | 0 | version = MuleManifest.getProductVersion(); |
101 | 0 | if (version == null) |
102 | |
{ |
103 | 0 | version = "Mule Version Info Not Set"; |
104 | |
} |
105 | |
} |
106 | 0 | return version; |
107 | |
} |
108 | |
|
109 | |
public String getVendor() |
110 | |
{ |
111 | 0 | if (vendor == null) |
112 | |
{ |
113 | 0 | vendor = MuleManifest.getVendorName(); |
114 | 0 | if (vendor == null) |
115 | |
{ |
116 | 0 | vendor = "Mule Vendor Info Not Set"; |
117 | |
} |
118 | |
} |
119 | 0 | return vendor; |
120 | |
} |
121 | |
|
122 | |
public void start() throws MuleException |
123 | |
{ |
124 | 0 | muleContext.start(); |
125 | 0 | } |
126 | |
|
127 | |
public void stop() throws MuleException |
128 | |
{ |
129 | 0 | muleContext.stop(); |
130 | 0 | } |
131 | |
|
132 | |
public void dispose() throws MuleException |
133 | |
{ |
134 | 0 | muleContext.dispose(); |
135 | 0 | } |
136 | |
|
137 | |
public long getFreeMemory() |
138 | |
{ |
139 | 0 | return Runtime.getRuntime().freeMemory(); |
140 | |
} |
141 | |
|
142 | |
public long getMaxMemory() |
143 | |
{ |
144 | 0 | return Runtime.getRuntime().maxMemory(); |
145 | |
} |
146 | |
|
147 | |
public long getTotalMemory() |
148 | |
{ |
149 | 0 | return Runtime.getRuntime().totalMemory(); |
150 | |
} |
151 | |
|
152 | |
public String getServerId() |
153 | |
{ |
154 | 0 | return muleContext.getConfiguration().getId(); |
155 | |
} |
156 | |
|
157 | |
public String getHostname() |
158 | |
{ |
159 | 0 | return host; |
160 | |
} |
161 | |
|
162 | |
public String getHostIp() |
163 | |
{ |
164 | 0 | return ip; |
165 | |
} |
166 | |
|
167 | |
public String getOsVersion() |
168 | |
{ |
169 | 0 | return os; |
170 | |
} |
171 | |
|
172 | |
public String getJdkVersion() |
173 | |
{ |
174 | 0 | return jdk; |
175 | |
} |
176 | |
|
177 | |
public String getCopyright() |
178 | |
{ |
179 | 0 | return copyright; |
180 | |
} |
181 | |
|
182 | |
public String getLicense() |
183 | |
{ |
184 | 0 | if (license == null) |
185 | |
{ |
186 | 0 | loadEnterpriseLicense(); |
187 | 0 | if (license == null) |
188 | |
{ |
189 | 0 | loadCommunityLicense(); |
190 | |
} |
191 | |
|
192 | 0 | if (license == null) |
193 | |
{ |
194 | 0 | license = "Failed to load license"; |
195 | |
} |
196 | |
} |
197 | 0 | return license; |
198 | |
} |
199 | |
|
200 | |
private void loadEnterpriseLicense() |
201 | |
{ |
202 | |
try |
203 | |
{ |
204 | 0 | loadLicense("MULE_EE_LICENSE.txt"); |
205 | |
} |
206 | 0 | catch (IOException e) |
207 | |
{ |
208 | |
|
209 | 0 | } |
210 | 0 | } |
211 | |
|
212 | |
private void loadCommunityLicense() |
213 | |
{ |
214 | |
try |
215 | |
{ |
216 | 0 | loadLicense("MULE_LICENSE.txt"); |
217 | |
} |
218 | 0 | catch (IOException e) |
219 | |
{ |
220 | 0 | logger.warn("Failed to load MULE_LICENSE.txt", e); |
221 | 0 | } |
222 | 0 | } |
223 | |
|
224 | |
private void loadLicense(String licenseFile) throws IOException |
225 | |
{ |
226 | 0 | license = IOUtils.getResourceAsString(licenseFile, getClass()); |
227 | 0 | license = StringMessageUtils.getBoilerPlate(license, ' ', 80); |
228 | 0 | } |
229 | |
|
230 | |
|
231 | |
|
232 | |
|
233 | |
public String getBuildDate() |
234 | |
{ |
235 | 0 | return buildDate; |
236 | |
} |
237 | |
|
238 | |
public String getBuildNumber() |
239 | |
{ |
240 | 0 | return buildNumber; |
241 | |
} |
242 | |
|
243 | |
public String getInstanceId() |
244 | |
{ |
245 | 0 | return muleContext.getConfiguration().getId(); |
246 | |
} |
247 | |
|
248 | |
public String getConfigBuilderClassName() |
249 | |
{ |
250 | 0 | return MuleServer.getConfigBuilderClassName(); |
251 | |
} |
252 | |
} |