KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > management > agents > JdmkAgent


1 /*
2  * $Id: JdmkAgent.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.agents;
12
13 // import com.sun.jdmk.comm.HtmlAdaptorServer;
14

15 import java.net.URI JavaDoc;
16
17 import javax.management.InstanceNotFoundException JavaDoc;
18 import javax.management.MBeanException JavaDoc;
19 import javax.management.MBeanServer JavaDoc;
20 import javax.management.MBeanServerFactory JavaDoc;
21 import javax.management.ObjectName JavaDoc;
22 import javax.management.ReflectionException JavaDoc;
23
24 import org.mule.config.i18n.Message;
25 import org.mule.config.i18n.Messages;
26 import org.mule.umo.UMOException;
27 import org.mule.umo.lifecycle.InitialisationException;
28 import org.mule.umo.manager.UMOAgent;
29
30 /**
31  * <code>JdmkAgent</code> configures an Jdmk Http Adaptor for Jmx management,
32  * statistics and configuration viewing of a Mule instance.
33  *
34  * @author Guillaume Nodet
35  * @version $Revision: 3798 $
36  */

37 public class JdmkAgent implements UMOAgent
38 {
39
40     private String JavaDoc name = "JDMK Agent";
41     private String JavaDoc jmxAdaptorUrl = "http://localhost:9092";
42     private Object JavaDoc adaptor;
43     private MBeanServer JavaDoc mBeanServer;
44     private ObjectName JavaDoc adaptorName;
45
46     protected Object JavaDoc createAdaptor() throws Exception JavaDoc
47     {
48         Object JavaDoc adaptor = null;
49         URI JavaDoc uri = new URI JavaDoc(jmxAdaptorUrl);
50         // adaptor = new HtmlAdaptorServer(uri.getPort());
51
return adaptor;
52     }
53
54     /*
55      * (non-Javadoc)
56      *
57      * @see org.mule.umo.manager.UMOAgent#getName()
58      */

59     public String JavaDoc getName()
60     {
61         return this.name;
62     }
63
64     /*
65      * (non-Javadoc)
66      *
67      * @see org.mule.umo.manager.UMOAgent#setName(java.lang.String)
68      */

69     public void setName(String JavaDoc name)
70     {
71         this.name = name;
72     }
73
74     /*
75      * (non-Javadoc)
76      *
77      * @see org.mule.umo.manager.UMOAgent#getDescription()
78      */

79     public String JavaDoc getDescription()
80     {
81         return "Jdmk Http adaptor: " + jmxAdaptorUrl;
82     }
83
84     /*
85      * (non-Javadoc)
86      *
87      * @see org.mule.umo.lifecycle.Startable#start()
88      */

89     public void start() throws UMOException
90     {
91         try
92         {
93             mBeanServer.invoke(adaptorName, "start", null, null);
94         }
95         catch (InstanceNotFoundException JavaDoc e)
96         {
97             throw new JmxManagementException(new Message(Messages.FAILED_TO_START_X, "Jdmk agent"),
98                 adaptorName, e);
99         }
100         catch (MBeanException JavaDoc e)
101         {
102             throw new JmxManagementException(new Message(Messages.FAILED_TO_START_X, "Jdmk agent"),
103                 adaptorName, e);
104         }
105         catch (ReflectionException JavaDoc e)
106         {
107             // ignore
108
}
109     }
110
111     /*
112      * (non-Javadoc)
113      *
114      * @see org.mule.umo.lifecycle.Stoppable#stop()
115      */

116     public void stop() throws UMOException
117     {
118         try
119         {
120             mBeanServer.invoke(adaptorName, "stop", null, null);
121         }
122         catch (InstanceNotFoundException JavaDoc e)
123         {
124             throw new JmxManagementException(new Message(Messages.FAILED_TO_STOP_X, "Jdmk agent"),
125                 adaptorName, e);
126         }
127         catch (MBeanException JavaDoc e)
128         {
129             throw new JmxManagementException(new Message(Messages.FAILED_TO_STOP_X, "Jdmk agent"),
130                 adaptorName, e);
131         }
132         catch (ReflectionException JavaDoc e)
133         {
134             // ignore
135
}
136     }
137
138     /*
139      * (non-Javadoc)
140      *
141      * @see org.mule.umo.lifecycle.Disposable#dispose()
142      */

143     public void dispose()
144     {
145         try
146         {
147             stop();
148         }
149         catch (Exception JavaDoc e)
150         {
151             // TODO: log an exception
152
}
153     }
154
155     /*
156      * (non-Javadoc)
157      *
158      * @see org.mule.umo.manager.UMOAgent#registered()
159      */

160     public void registered()
161     {
162         // nothing to do
163
}
164
165     /*
166      * (non-Javadoc)
167      *
168      * @see org.mule.umo.manager.UMOAgent#unregistered()
169      */

170     public void unregistered()
171     {
172         // nothing to do
173
}
174
175     /*
176      * (non-Javadoc)
177      *
178      * @see org.mule.umo.lifecycle.Initialisable#initialise()
179      */

180     public void initialise() throws InitialisationException
181     {
182         try
183         {
184             mBeanServer = (MBeanServer JavaDoc)MBeanServerFactory.findMBeanServer(null).get(0);
185             adaptor = createAdaptor();
186             adaptorName = new ObjectName JavaDoc("Adaptor:class=" + adaptor.getClass().getName());
187             mBeanServer.registerMBean(adaptor, adaptorName);
188         }
189         catch (Exception JavaDoc e)
190         {
191             throw new InitialisationException(new Message(Messages.FAILED_TO_START_X, "Jdmk Agent"), e);
192         }
193     }
194
195     /**
196      * @return Returns the jmxAdaptorUrl.
197      */

198     public String JavaDoc getJmxAdaptorUrl()
199     {
200         return jmxAdaptorUrl;
201     }
202
203     /**
204      * @param jmxAdaptorUrl The jmxAdaptorUrl to set.
205      */

206     public void setJmxAdaptorUrl(String JavaDoc jmxAdaptorUrl)
207     {
208         this.jmxAdaptorUrl = jmxAdaptorUrl;
209     }
210 }
211
Popular Tags