1 17 package org.apache.geronimo.plugin.packaging; 18 19 import java.io.IOException ; 20 import java.net.URL ; 21 import java.util.HashMap ; 22 import java.util.Iterator ; 23 import java.util.Map ; 24 import java.util.Set ; 25 import javax.management.MBeanServerConnection ; 26 import javax.management.ObjectName ; 27 import javax.management.remote.JMXConnector ; 28 import javax.management.remote.JMXConnectorFactory ; 29 import javax.management.remote.JMXServiceURL ; 30 31 import org.apache.geronimo.kernel.config.NoSuchStoreException; 32 33 40 public class JMXDistributor extends AbstractDistributor { 41 public void execute() throws Exception { 42 if (!getArtifact().canRead()) { 43 throw new IOException ("Unable to read artifact " + getArtifact()); 44 } 45 46 Map environment = new HashMap (); 47 environment.put(JMXConnector.CREDENTIALS, new String []{getUser(), getPassword()}); 48 49 JMXServiceURL serviceURL = new JMXServiceURL (getUrl()); 50 JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, environment); 51 try { 52 MBeanServerConnection mbServer = jmxConnector.getMBeanServerConnection(); 53 54 ObjectName configStore = locateConfigStore(mbServer, storeName); 55 mbServer.invoke(configStore, "install", new Object []{getArtifact().toURL()}, new String []{URL .class.getName()}); 56 System.out.println("Distributed " + getArtifact() + " to " + getUrl()); 57 } finally { 58 jmxConnector.close(); 59 } 60 } 61 62 private ObjectName locateConfigStore(MBeanServerConnection mbServer, ObjectName storeName) throws Exception { 63 Set set = mbServer.queryNames(storeName, null); 64 Iterator i = set.iterator(); 65 if (!i.hasNext()) { 66 throw new NoSuchStoreException("No ConfigurationStore found matching " + storeName); 67 } 68 ObjectName configStore = (ObjectName ) i.next(); 69 if (i.hasNext()) { 70 throw new NoSuchStoreException("Multiple ConfigurationStores found matching " + storeName); 71 } 72 return configStore; 73 } 74 } 75 | Popular Tags |