001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.catalina.ant.jmx;
018:
019: import javax.management.MBeanServerConnection;
020: import javax.management.ObjectName;
021:
022: import org.apache.tools.ant.BuildException;
023:
024: /**
025: * unregister a MBean at <em>JMX</em> JSR 160 MBeans Server.
026: * <ul>
027: * <li>unregister Mbeans</li>
028: * </ul>
029: * <p>
030: * Examples:
031: * <br/>
032: * unregister an existing Mbean at jmx.server connection
033: * <pre>
034: * <jmx:unregister
035: * ref="jmx.server"
036: * name="Catalina:type=MBeanFactory" />
037: * </pre>
038: * </p>
039: * <p>
040: * <b>WARNING</b>Not all Tomcat MBeans can successfully unregister remotely. The mbean
041: * unregistration don't remove valves, realm, .. from parent class.
042: * Please, use the MBeanFactory operation to remove valves and realms.
043: * </p>
044: * <p>
045: * First call to a remote MBeanserver save the JMXConnection a reference <em>jmx.server</em>
046: * </p>
047: * These tasks require Ant 1.6 or later interface.
048: *
049: * @author Peter Rossbach
050: * @version $Revision: 500684 $
051: * @since 5.5.12
052: */
053: public class JMXAccessorUnregisterTask extends JMXAccessorTask {
054:
055: // ----------------------------------------------------- Instance Info
056:
057: /**
058: * Descriptive information describing this implementation.
059: */
060: private static final String info = "org.apache.catalina.ant.JMXAccessorUnregisterTask/1.0";
061:
062: /**
063: * Return descriptive information about this implementation and the
064: * corresponding version number, in the format
065: * <code><description>/<version></code>.
066: * @return Returns the class info.
067: */
068: public String getInfo() {
069:
070: return (info);
071:
072: }
073:
074: // ------------------------------------------------------ protected Methods
075:
076: /**
077: * Execute the specified command, based on the configured properties. The
078: * input stream will be closed upon completion of this task, whether it was
079: * executed successfully or not.
080: *
081: * @exception Exception
082: * if an error occurs
083: */
084: public String jmxExecute(MBeanServerConnection jmxServerConnection)
085: throws Exception {
086:
087: if (getName() == null) {
088: throw new BuildException("Must specify a 'name'");
089: }
090: return jmxUuregister(jmxServerConnection, getName());
091: }
092:
093: /**
094: * Unregister Mbean
095: * @param jmxServerConnection
096: * @param name
097: * @return The value of the given named attribute
098: * @throws Exception
099: */
100: protected String jmxUuregister(
101: MBeanServerConnection jmxServerConnection, String name)
102: throws Exception {
103: String error = null;
104: if (isEcho()) {
105: handleOutput("Unregister MBean " + name);
106: }
107: jmxServerConnection.unregisterMBean(new ObjectName(name));
108: return error;
109: }
110:
111: }
|