1 22 package org.objectweb.petals.tools.ant.managers; 23 24 import javax.management.MBeanServerConnection ; 25 import javax.management.ObjectName ; 26 import javax.management.remote.JMXConnector ; 27 28 import org.apache.tools.ant.BuildException; 29 import org.objectweb.petals.tools.ant.util.JBIJMXConnectorUtil; 30 31 36 public abstract class ComponentAntTaskAbstract extends JBIAntTaskAbstract { 37 38 41 protected static final String SHUTDOWN = "shutDown"; 42 43 46 protected static final String START = "start"; 47 48 51 protected static final String STOP = "stop"; 52 53 56 protected String name; 57 58 64 protected void performAction(String action) { 65 if (name == null) { 66 throw new BuildException("Required attribute : name"); 67 } 68 try { 69 JMXConnector connector = JBIJMXConnectorUtil.getConnection(host, 70 port, username, password); 71 MBeanServerConnection connection = connector 72 .getMBeanServerConnection(); 73 Object [] objects = new Object [0]; 74 String [] strings = new String [0]; 75 ObjectName objectName = JBIJMXConnectorUtil.getComponentMBeanName( 76 connection, name); 77 if (objectName == null) { 78 throw new BuildException("The component is not installed"); 79 } 80 connection.invoke(objectName, action, objects, strings); 81 try { 82 log("Shutdown component name : " + name); 83 } catch (NullPointerException e) { 84 } 86 connector.close(); 87 } catch (Exception e) { 88 if (Boolean.parseBoolean(failOnError)) { 89 throw new BuildException(e.getMessage(), e.getCause()); 90 } 91 } 92 } 93 94 98 protected void performUninstall() { 99 if (name == null) { 100 throw new BuildException("Required attribute : name"); 101 } 102 try { 103 JMXConnector connector = JBIJMXConnectorUtil.getConnection(host, 104 port, username, password); 105 MBeanServerConnection connection = connector 106 .getMBeanServerConnection(); 107 Object [] objects = new Object [2]; 108 objects[0] = name; 109 objects[1] = true; 110 String [] strings = new String [2]; 111 strings[0] = "java.lang.String"; 112 strings[1] = "boolean"; 113 connection.invoke(JBIJMXConnectorUtil 115 .getInstallationServiceMBeanName(connection), 116 "unloadInstaller", objects, strings); 117 try { 118 log("Uninstalled component name : " + name); 119 } catch (NullPointerException e) { 120 } 122 } catch (Exception e) { 123 if (Boolean.parseBoolean(failOnError)) { 124 throw new BuildException(e.getMessage(), e.getCause()); 125 } 126 } 127 } 128 129 public void setName(String name) { 130 this.name = name; 131 } 132 133 } 134 | Popular Tags |