1 package org.apache.geronimo.deployment.mavenplugin; 2 3 import java.util.HashMap ; 4 import java.util.Map ; 5 import javax.management.MBeanServerConnection ; 6 import javax.management.remote.JMXConnector ; 7 import javax.management.remote.JMXConnectorFactory ; 8 import javax.management.remote.JMXServiceURL ; 9 10 import org.apache.geronimo.deployment.plugin.factories.DeploymentFactoryImpl; 11 import org.apache.geronimo.kernel.jmx.KernelDelegate; 12 import org.apache.geronimo.kernel.Kernel; 13 14 16 public class StopRemoteServer extends AbstractModuleCommand { 17 18 private MBeanServerConnection mbServerConnection; 19 private Kernel kernel; 20 21 public void execute() throws Exception { 22 String uri = getUri().substring(DeploymentFactoryImpl.URI_PREFIX.length()); 23 if (!uri.startsWith("jmx")) { 24 throw new Exception ("bad uri"); 25 } 26 27 Map environment = new HashMap (); 28 String [] credentials = new String []{getUsername(), getPassword()}; 29 environment.put(JMXConnector.CREDENTIALS, credentials); 30 31 JMXServiceURL address = new JMXServiceURL ("service:" + uri); 32 ClassLoader oldcl = Thread.currentThread().getContextClassLoader(); 33 try { 34 Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); 35 JMXConnector jmxConnector = JMXConnectorFactory.connect(address, environment); 36 mbServerConnection = jmxConnector.getMBeanServerConnection(); 37 kernel = new KernelDelegate(mbServerConnection); 38 kernel.shutdown(); 39 40 } finally { 41 Thread.currentThread().setContextClassLoader(oldcl); 42 } 43 44 } 45 46 } 47 | Popular Tags |