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 | 22 | 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 | 22 | 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 | 22 | { |
54 | 22 | this.muleContext = muleContext; |
55 | 22 | String patch = System.getProperty("sun.os.patch.level", null); |
56 | 22 | jdk = System.getProperty("java.version") + " (" + System.getProperty("java.vm.info") + ")"; |
57 | 22 | os = System.getProperty("os.name"); |
58 | 22 | if (patch != null && !"unknown".equalsIgnoreCase(patch)) |
59 | |
{ |
60 | 0 | os += " - " + patch; |
61 | |
} |
62 | 22 | os += " (" + System.getProperty("os.version") + ", " + System.getProperty("os.arch") + ")"; |
63 | |
|
64 | 22 | buildNumber = MuleManifest.getBuildNumber(); |
65 | 22 | buildDate = MuleManifest.getBuildDate(); |
66 | |
try |
67 | |
{ |
68 | 22 | InetAddress iad = InetAddress.getLocalHost(); |
69 | 22 | host = iad.getCanonicalHostName(); |
70 | 22 | ip = iad.getHostAddress(); |
71 | |
} |
72 | 0 | catch (UnknownHostException e) |
73 | |
{ |
74 | |
|
75 | 22 | } |
76 | 22 | } |
77 | |
|
78 | |
public boolean isInitialised() |
79 | |
{ |
80 | 0 | return muleContext!=null && muleContext.isInitialised(); |
81 | |
} |
82 | |
|
83 | |
public boolean isStopped() |
84 | |
{ |
85 | 0 | return muleContext!=null && !muleContext.isStarted(); |
86 | |
} |
87 | |
|
88 | |
public Date getStartTime() |
89 | |
{ |
90 | 0 | if (!isStopped()) |
91 | |
{ |
92 | 0 | return new Date(muleContext.getStartDate()); |
93 | |
} |
94 | |
else |
95 | |
{ |
96 | 0 | return null; |
97 | |
} |
98 | |
} |
99 | |
|
100 | |
public String getVersion() |
101 | |
{ |
102 | 0 | if (version == null) |
103 | |
{ |
104 | 0 | version = MuleManifest.getProductVersion(); |
105 | 0 | if (version == null) |
106 | |
{ |
107 | 0 | version = "Mule Version Info Not Set"; |
108 | |
} |
109 | |
} |
110 | 0 | return version; |
111 | |
} |
112 | |
|
113 | |
public String getVendor() |
114 | |
{ |
115 | 0 | if (vendor == null) |
116 | |
{ |
117 | 0 | vendor = MuleManifest.getVendorName(); |
118 | 0 | if (vendor == null) |
119 | |
{ |
120 | 0 | vendor = "Mule Vendor Info Not Set"; |
121 | |
} |
122 | |
} |
123 | 0 | return vendor; |
124 | |
} |
125 | |
|
126 | |
public void start() throws MuleException |
127 | |
{ |
128 | 0 | muleContext.start(); |
129 | 0 | } |
130 | |
|
131 | |
public void stop() throws MuleException |
132 | |
{ |
133 | 0 | muleContext.stop(); |
134 | 0 | } |
135 | |
|
136 | |
public void dispose() throws MuleException |
137 | |
{ |
138 | 0 | muleContext.dispose(); |
139 | 0 | } |
140 | |
|
141 | |
public long getFreeMemory() |
142 | |
{ |
143 | 0 | return Runtime.getRuntime().freeMemory(); |
144 | |
} |
145 | |
|
146 | |
public long getMaxMemory() |
147 | |
{ |
148 | 0 | return Runtime.getRuntime().maxMemory(); |
149 | |
} |
150 | |
|
151 | |
public long getTotalMemory() |
152 | |
{ |
153 | 0 | return Runtime.getRuntime().totalMemory(); |
154 | |
} |
155 | |
|
156 | |
public String getServerId() |
157 | |
{ |
158 | 0 | return muleContext.getConfiguration().getId(); |
159 | |
} |
160 | |
|
161 | |
public String getHostname() |
162 | |
{ |
163 | 0 | return host; |
164 | |
} |
165 | |
|
166 | |
public String getHostIp() |
167 | |
{ |
168 | 0 | return ip; |
169 | |
} |
170 | |
|
171 | |
public String getOsVersion() |
172 | |
{ |
173 | 0 | return os; |
174 | |
} |
175 | |
|
176 | |
public String getJdkVersion() |
177 | |
{ |
178 | 0 | return jdk; |
179 | |
} |
180 | |
|
181 | |
public String getCopyright() |
182 | |
{ |
183 | 0 | return copyright; |
184 | |
} |
185 | |
|
186 | |
public String getLicense() |
187 | |
{ |
188 | 0 | if (license == null) |
189 | |
{ |
190 | |
try |
191 | |
{ |
192 | 0 | license = IOUtils.getResourceAsString("MULE_LICENSE.txt", getClass()); |
193 | 0 | license = StringMessageUtils.getBoilerPlate(license, ' ', 80); |
194 | |
} |
195 | 0 | catch (IOException e) |
196 | |
{ |
197 | 0 | logger.warn("Failed to load MULE_LICENSE.txt", e); |
198 | 0 | } |
199 | 0 | if (license == null) |
200 | |
{ |
201 | 0 | license = "Failed to load license"; |
202 | |
} |
203 | |
} |
204 | 0 | return license; |
205 | |
} |
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
public String getBuildDate() |
211 | |
{ |
212 | 0 | return buildDate; |
213 | |
} |
214 | |
|
215 | |
public String getBuildNumber() |
216 | |
{ |
217 | 0 | return buildNumber; |
218 | |
} |
219 | |
|
220 | |
public String getInstanceId() |
221 | |
{ |
222 | 0 | return muleContext.getConfiguration().getId(); |
223 | |
} |
224 | |
|
225 | |
public String getConfigBuilderClassName() |
226 | |
{ |
227 | 0 | return MuleServer.getConfigBuilderClassName(); |
228 | |
} |
229 | |
} |