KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: DefaultJmxSupportAgent.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 java.util.HashMap JavaDoc;
14 import java.util.Map JavaDoc;
15
16 import org.mule.MuleManager;
17 import org.mule.umo.UMOException;
18 import org.mule.umo.lifecycle.InitialisationException;
19 import org.mule.umo.lifecycle.RecoverableException;
20 import org.mule.umo.manager.UMOAgent;
21
22 /**
23  * todo document
24  *
25  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
26  * @version $Revision: 3798 $
27  */

28 public class DefaultJmxSupportAgent implements UMOAgent
29 {
30
31     public static final String JavaDoc DEFAULT_REMOTING_URI = "service:jmx:rmi:///jndi/rmi://localhost:1099/server";
32
33     private String JavaDoc name = "Default Jmx";
34     private boolean loadJdmkAgent = false;
35     private boolean loadMx4jAgent = false;
36
37     /**
38      * Gets the name of this agent
39      *
40      * @return the agent name
41      */

42     public String JavaDoc getName()
43     {
44         return name;
45     }
46
47     /**
48      * Sets the name of this agent
49      *
50      * @param name the name of the agent
51      */

52     public void setName(String JavaDoc name)
53     {
54         this.name = name;
55     }
56
57     /**
58      * Should be a 1 line description of the agent
59      *
60      * @return
61      */

62     public String JavaDoc getDescription()
63     {
64         return "Default Jmx Agent Support";
65     }
66
67     public void registered()
68     {
69         // nothing to do
70
}
71
72     public void unregistered()
73     {
74         // nothing to do
75
}
76
77     public void start() throws UMOException
78     {
79         // nothing to do
80
}
81
82     public void stop() throws UMOException
83     {
84         // nothing to do
85
}
86
87     /**
88      * A lifecycle method where implementor should free up any resources. If an
89      * exception is thrown it should just be logged and processing should continue.
90      * This method should not throw Runtime exceptions.
91      */

92     public void dispose()
93     {
94         // nothing to do
95
}
96
97     /**
98      * Method used to perform any initialisation work. If a fatal error occurs during
99      * initialisation an <code>InitialisationException</code> should be thrown,
100      * causing the Mule instance to shutdown. If the error is recoverable, say by
101      * retrying to connect, a <code>RecoverableException</code> should be thrown.
102      * There is no guarantee that by throwing a Recoverable exception that the Mule
103      * instance will not shut down.
104      *
105      * @throws org.mule.umo.lifecycle.InitialisationException if a fatal error occurs
106      * causing the Mule instance to shutdown
107      * @throws org.mule.umo.lifecycle.RecoverableException if an error occurs that
108      * can be recovered from
109      */

110     public void initialise() throws InitialisationException, RecoverableException
111     {
112
113         try
114         {
115             UMOAgent agent = createRmiAgent();
116             if (!isAgentRegistered(agent))
117             {
118                 MuleManager.getInstance().registerAgent(agent);
119             }
120             agent = createJmxAgent();
121             if (!isAgentRegistered(agent))
122             {
123                 MuleManager.getInstance().registerAgent(agent);
124             }
125             agent = createLog4jAgent();
126             if (!isAgentRegistered(agent))
127             {
128                 MuleManager.getInstance().registerAgent(agent);
129             }
130             agent = createJmxNotificationAgent();
131             if (!isAgentRegistered(agent))
132             {
133                 MuleManager.getInstance().registerAgent(agent);
134             }
135             if (loadJdmkAgent)
136             {
137                 agent = createJdmkAgent();
138                 if (!isAgentRegistered(agent))
139                 {
140                     MuleManager.getInstance().registerAgent(agent);
141                 }
142             }
143
144             if (loadMx4jAgent)
145             {
146                 agent = createMx4jAgent();
147                 if (!isAgentRegistered(agent))
148                 {
149                     MuleManager.getInstance().registerAgent(agent);
150                 }
151             }
152
153             // remove this agent once t has registered the other agents
154
MuleManager.getInstance().unregisterAgent(name);
155         }
156         catch (UMOException e)
157         {
158             throw new InitialisationException(e, this);
159         }
160     }
161
162     protected JmxAgent createJmxAgent()
163     {
164         JmxAgent agent = new JmxAgent();
165         agent.setConnectorServerUrl(DEFAULT_REMOTING_URI);
166         Map JavaDoc props = new HashMap JavaDoc();
167         props.put("jmx.remote.jndi.rebind", "true");
168         agent.setConnectorServerProperties(props);
169         return agent;
170     }
171
172     protected Log4jAgent createLog4jAgent()
173     {
174         return new Log4jAgent();
175     }
176
177     protected RmiRegistryAgent createRmiAgent()
178     {
179         return new RmiRegistryAgent();
180     }
181
182     protected JmxServerNotificationAgent createJmxNotificationAgent()
183     {
184         return new JmxServerNotificationAgent();
185     }
186
187     protected Mx4jAgent createMx4jAgent()
188     {
189         return new Mx4jAgent();
190     }
191
192     protected JdmkAgent createJdmkAgent()
193     {
194         return new JdmkAgent();
195     }
196
197     protected boolean isAgentRegistered(UMOAgent agent)
198     {
199         return MuleManager.getInstance().lookupAgent(agent.getName()) != null;
200     }
201
202     public boolean isLoadJdmkAgent()
203     {
204         return loadJdmkAgent;
205     }
206
207     public void setLoadJdmkAgent(boolean loadJdmkAgent)
208     {
209         this.loadJdmkAgent = loadJdmkAgent;
210     }
211
212     public boolean isLoadMx4jAgent()
213     {
214         return loadMx4jAgent;
215     }
216
217     public void setLoadMx4jAgent(boolean loadMx4jAgent)
218     {
219         this.loadMx4jAgent = loadMx4jAgent;
220     }
221 }
222
Popular Tags