KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > deployment > mavenplugin > StopRemoteServer


1 package org.apache.geronimo.deployment.mavenplugin;
2
3 import java.util.HashMap JavaDoc;
4 import java.util.Map JavaDoc;
5 import javax.management.MBeanServerConnection JavaDoc;
6 import javax.management.remote.JMXConnector JavaDoc;
7 import javax.management.remote.JMXConnectorFactory JavaDoc;
8 import javax.management.remote.JMXServiceURL JavaDoc;
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 /**
15  */

16 public class StopRemoteServer extends AbstractModuleCommand {
17
18     private MBeanServerConnection JavaDoc mbServerConnection;
19     private Kernel kernel;
20
21     public void execute() throws Exception JavaDoc {
22         String JavaDoc uri = getUri().substring(DeploymentFactoryImpl.URI_PREFIX.length());
23         if (!uri.startsWith("jmx")) {
24             throw new Exception JavaDoc("bad uri");
25         }
26
27         Map JavaDoc environment = new HashMap JavaDoc();
28         String JavaDoc[] credentials = new String JavaDoc[]{getUsername(), getPassword()};
29         environment.put(JMXConnector.CREDENTIALS, credentials);
30
31         JMXServiceURL JavaDoc address = new JMXServiceURL JavaDoc("service:" + uri);
32         ClassLoader JavaDoc oldcl = Thread.currentThread().getContextClassLoader();
33         try {
34             Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
35             JMXConnector JavaDoc 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