KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > management > mbeans > MuleService


1 /*
2  * $Id: MuleService.java 3798 2006-11-04 04:07:14Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.management.mbeans;
12
13 import java.io.IOException JavaDoc;
14 import java.net.InetAddress JavaDoc;
15 import java.net.UnknownHostException JavaDoc;
16 import java.util.Date JavaDoc;
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 /**
26  * <code>MuleService</code> exposes certain Mule server functions for management
27  *
28  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
29  * @version $Revision: 3798 $
30  */

31 public class MuleService implements MuleServiceMBean
32 {
33     /**
34      * logger used by this class
35      */

36     protected transient Log logger = LogFactory.getLog(getClass());
37
38     private String JavaDoc version;
39     private String JavaDoc vendor;
40     private String JavaDoc jdk;
41     private String JavaDoc host;
42     private String JavaDoc ip;
43     private String JavaDoc os;
44     private String JavaDoc buildDate;
45     // TODO
46
private String JavaDoc copyright = "Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com";
47     private String JavaDoc license;
48
49     public MuleService()
50     {
51         String JavaDoc 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 JavaDoc iad = InetAddress.getLocalHost();
64             host = iad.getCanonicalHostName();
65             ip = iad.getHostAddress();
66         }
67         catch (UnknownHostException JavaDoc e)
68         {
69             // ignore
70
}
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 JavaDoc getStartTime()
89     {
90         if (!isStopped())
91         {
92             return new Date JavaDoc(MuleManager.getInstance().getStartDate());
93         }
94         else
95         {
96             return null;
97         }
98     }
99
100     public String JavaDoc 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 JavaDoc 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 JavaDoc getServerId()
157     {
158         return MuleManager.getInstance().getId();
159     }
160
161     public String JavaDoc getHostname()
162     {
163         return host;
164     }
165
166     public String JavaDoc getHostIp()
167     {
168         return ip;
169     }
170
171     public String JavaDoc getOsVersion()
172     {
173         return os;
174     }
175
176     public String JavaDoc getJdkVersion()
177     {
178         return jdk;
179     }
180
181     public String JavaDoc getCopyright()
182     {
183         return copyright;
184     }
185
186     public String JavaDoc 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 JavaDoc 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 JavaDoc getBuildDate()
208     {
209         return buildDate;
210     }
211
212     public String JavaDoc getInstanceId()
213     {
214         return MuleManager.getInstance().getId();
215     }
216 }
217
Popular Tags