1 22 package org.objectweb.petals.tools.jbiplugin; 23 24 import javax.jbi.management.LifeCycleMBean; 25 import javax.management.MBeanException ; 26 import javax.management.MBeanServerConnection ; 27 import javax.management.remote.JMXConnector ; 28 29 import org.objectweb.petals.tools.jbiplugin.util.JBIJMXConnectorUtil; 30 31 36 public abstract class JMXServiceAssemblyAbstractMojo extends JMXTaskAbstractMojo { 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 static final String DEPLOY = "deploy"; 57 58 61 protected static final String UNDEPLOY = "undeploy"; 62 63 66 protected static final String GET_STATE = "getState"; 67 68 74 protected String getState(String serviceAssemblyName) throws Exception { 75 JMXConnector connector = null; 76 String state = null; 77 try { 78 connector = JBIJMXConnectorUtil.getConnection(host, port, username, 79 password); 80 MBeanServerConnection connection = connector 81 .getMBeanServerConnection(); 82 Object [] objects = new Object [1]; 83 objects[0] = serviceAssemblyName; 84 String [] strings = new String [1]; 85 strings[0] = "java.lang.String"; 86 Object result = connection.invoke(JBIJMXConnectorUtil 87 .getDeploymentServiceMBeanName(connection), 88 JMXServiceAssemblyAbstractMojo.GET_STATE, objects, 89 strings); 90 if (result instanceof String ) { 91 state = (String )result; 92 } else if (result instanceof Exception ) { 93 state = LifeCycleMBean.UNKNOWN; 94 } 95 96 } catch (MBeanException e) { 97 state = LifeCycleMBean.UNKNOWN; 98 99 } catch (Exception e) { 100 if (failOnError) { 101 throw e; 102 } 103 } finally { 104 connector.close(); 105 } 106 107 System.out.println("Service Assembly: " 108 + serviceAssemblyName + " is in state: " + state); 109 return state; 110 111 } 112 113 117 protected void performAction(String action, String serviceAssembly) throws Exception { 118 try { 119 if (verbose) { 120 System.out.println("Start operation [" + action + "] on JBI Service Assembly archive: " 121 + serviceAssembly); 122 } 123 124 JMXConnector connector = JBIJMXConnectorUtil.getConnection(host, 125 port, username, password); 126 MBeanServerConnection connection = connector 127 .getMBeanServerConnection(); 128 Object [] objects = new Object [1]; 129 objects[0] = serviceAssembly; 130 String [] strings = new String [1]; 131 strings[0] = "java.lang.String"; 132 Object result = connection.invoke(JBIJMXConnectorUtil 133 .getDeploymentServiceMBeanName(connection), action, 134 objects, strings); 135 if (result instanceof String ) { 136 String xml = (String ) result; 138 if (xml.indexOf("Successfully") > -1) { 139 String saName = ""; 140 saName = xml.substring(xml.indexOf("<loc-param>") + 11, xml 141 .indexOf("</loc-param>")); 142 System.out.println("Operation succeeded on service assembly named : " + saName); 143 } else { 144 System.out.println("Problem during the " + action + " :\n" 145 + (String ) result); 146 } 147 } 148 connector.close(); 149 } catch (Exception e) { 150 if (failOnError) { 151 throw e; 152 } 153 } 154 } 155 } 156 | Popular Tags |