1 22 package org.objectweb.petals.tools.ant.managers; 23 24 import javax.management.MBeanServerConnection ; 25 import javax.management.remote.JMXConnector ; 26 27 import org.apache.tools.ant.BuildException; 28 import org.objectweb.petals.tools.ant.util.JBIJMXConnectorUtil; 29 30 35 public abstract class ServiceAssemblyAntTaskAbstract extends JBIAntTaskAbstract { 36 37 40 protected static final String SHUTDOWN = "shutDown"; 41 42 45 protected static final String START = "start"; 46 47 50 protected static final String STOP = "stop"; 51 52 55 protected static final String UNDEPLOY = "undeploy"; 56 57 60 protected String name; 61 62 66 protected void performAction(String action) { 67 if (name == null) { 68 throw new BuildException("Required attribute : name"); 69 } 70 try { 71 JMXConnector connector = JBIJMXConnectorUtil.getConnection(host, 72 port, username, password); 73 MBeanServerConnection connection = connector 74 .getMBeanServerConnection(); 75 Object [] objects = new Object [1]; 76 objects[0] = name; 77 String [] strings = new String [1]; 78 strings[0] = "java.lang.String"; 79 Object result = connection.invoke(JBIJMXConnectorUtil 80 .getDeploymentServiceMBeanName(connection), action, 81 objects, strings); 82 if (result instanceof String ) { 83 String xml = (String ) result; 85 if (xml.indexOf("Successfully") > -1) { 86 String saName = ""; 87 saName = xml.substring(xml.indexOf("<loc-param>") + 11, xml 88 .indexOf("</loc-param>")); 89 try { 90 log("Started service assembly name : " + saName); 91 } catch (NullPointerException e) { 92 } 95 } else { 96 try { 97 log("Problem during the " + action + " :\n" 98 + (String ) result); 99 } catch (NullPointerException e) { 100 } 103 } 104 } 105 connector.close(); 106 } catch (Exception e) { 107 if (Boolean.parseBoolean(failOnError)) { 108 throw new BuildException(e.getMessage(), e.getCause()); 109 } 110 } 111 } 112 113 public void setName(String name) { 114 this.name = name; 115 } 116 117 } 118 | Popular Tags |