KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > catalina > ant > jmx > JMXAccessorUnregisterTask


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.catalina.ant.jmx;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.List JavaDoc;
21
22 import javax.management.MBeanServerConnection JavaDoc;
23 import javax.management.ObjectName JavaDoc;
24
25 import org.apache.tools.ant.BuildException;
26
27 /**
28  * unregister a MBean at <em>JMX</em> JSR 160 MBeans Server.
29  * <ul>
30  * <li>unregister Mbeans</li>
31  * </ul>
32  * <p>
33  * Examples:
34  * <br/>
35  * unregister an existing Mbean at jmx.server connection
36  * <pre>
37  * &lt;jmx:unregister
38  * ref="jmx.server"
39  * name="Catalina:type=MBeanFactory" /&gt;
40  * </pre>
41  * </p>
42  * <p>
43  * <b>WARNING</b>Not all Tomcat MBeans can successfully unregister remotely. The mbean
44  * unregistration don't remove valves, realm, .. from parent class.
45  * Please, use the MBeanFactory operation to remove valves and realms.
46  * </p>
47  * <p>
48  * First call to a remote MBeanserver save the JMXConnection a reference <em>jmx.server</em>
49  * </p>
50  * These tasks require Ant 1.6 or later interface.
51  *
52  * @author Peter Rossbach
53  * @version $Revision: 467222 $
54  * @since 5.5.12
55  */

56 public class JMXAccessorUnregisterTask extends JMXAccessorTask {
57
58     // ----------------------------------------------------- Instance Info
59

60     /**
61      * Descriptive information describing this implementation.
62      */

63     private static final String JavaDoc info = "org.apache.catalina.ant.JMXAccessorUnregisterTask/1.0";
64
65     /**
66      * Return descriptive information about this implementation and the
67      * corresponding version number, in the format
68      * <code>&lt;description&gt;/&lt;version&gt;</code>.
69      * @return Returns the class info.
70      */

71     public String JavaDoc getInfo() {
72
73         return (info);
74
75     }
76     // ------------------------------------------------------ protected Methods
77

78     /**
79      * Execute the specified command, based on the configured properties. The
80      * input stream will be closed upon completion of this task, whether it was
81      * executed successfully or not.
82      *
83      * @exception Exception
84      * if an error occurs
85      */

86     public String JavaDoc jmxExecute(MBeanServerConnection JavaDoc jmxServerConnection)
87         throws Exception JavaDoc {
88
89         if (getName() == null) {
90             throw new BuildException("Must specify a 'name'");
91         }
92         return jmxUuregister(jmxServerConnection, getName());
93      }
94
95
96     /**
97      * Unregister Mbean
98      * @param jmxServerConnection
99      * @param name
100      * @return The value of the given named attribute
101      * @throws Exception
102      */

103     protected String JavaDoc jmxUuregister(MBeanServerConnection JavaDoc jmxServerConnection,String JavaDoc name) throws Exception JavaDoc {
104         String JavaDoc error = null;
105         if(isEcho()) {
106             handleOutput("Unregister MBean " + name );
107         }
108         jmxServerConnection.unregisterMBean(
109                 new ObjectName JavaDoc(name));
110         return error;
111     }
112
113 }
114
Popular Tags