[Jboss-cvs] JBossAS SVN: r55171 - in branches/MC_VDF_WORK/system/src/main/org/jboss: deployment system/server/jmx
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Aug 4 02:50:08 EDT 2006
Author: scott.stark at jboss.org
Date: 2006-08-04 02:50:04 -0400 (Fri, 04 Aug 2006)
New Revision: 55171
Added:
branches/MC_VDF_WORK/system/src/main/org/jboss/system/server/jmx/JMXKernel.java
branches/MC_VDF_WORK/system/src/main/org/jboss/system/server/jmx/JMXKernelMBean.java
Modified:
branches/MC_VDF_WORK/system/src/main/org/jboss/deployment/SARDeployer.java
Log:
First pass at integrating the legacy SARDeployer into the new mc/vdf framework
Modified: branches/MC_VDF_WORK/system/src/main/org/jboss/deployment/SARDeployer.java
===================================================================
--- branches/MC_VDF_WORK/system/src/main/org/jboss/deployment/SARDeployer.java 2006-08-04 06:48:49 UTC (rev 55170)
+++ branches/MC_VDF_WORK/system/src/main/org/jboss/deployment/SARDeployer.java 2006-08-04 06:50:04 UTC (rev 55171)
@@ -21,49 +21,46 @@
*/
package org.jboss.deployment;
-import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.Serializable;
import java.net.URL;
-import java.net.URLClassLoader;
import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
-
+import java.util.concurrent.ConcurrentHashMap;
import javax.management.MBeanServer;
-import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
+import org.jboss.deployers.plugins.AbstractAspectDeployer;
+import org.jboss.deployers.spi.DeploymentContext;
+import org.jboss.deployers.spi.DeploymentException;
import org.jboss.mx.loading.LoaderRepositoryFactory;
+import org.jboss.mx.loading.RepositoryClassLoader;
import org.jboss.mx.loading.LoaderRepositoryFactory.LoaderRepositoryConfig;
import org.jboss.mx.util.MBeanProxyExt;
+import org.jboss.mx.util.MBeanServerLocator;
import org.jboss.net.protocol.URLLister;
import org.jboss.net.protocol.URLListerFactory;
+import org.jboss.system.ServiceController;
import org.jboss.system.ServiceControllerMBean;
-import org.jboss.system.server.ServerConfig;
-import org.jboss.system.server.ServerConfigLocator;
import org.jboss.util.StringPropertyReplacer;
-import org.jboss.util.Strings;
-import org.jboss.util.stream.Streams;
import org.jboss.util.xml.JBossEntityResolver;
+import org.jboss.vfs.spi.VirtualFile;
+import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
-import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap;
-
/**
- * This is the main Service Deployer API.
+ * This is the main Service Deployer API. This is a compatibility deployer that
+ * bridges between the old mbean service(*-service.xml) deployments and the
+ * MC BeanDeployer.
*
* @see org.jboss.system.Service
*
@@ -76,8 +73,7 @@
* @author <a href="mailto:dimitris at jboss.org">Dimitris Andreadis<a/>
* @version $Revision$
*/
-public class SARDeployer extends SubDeployerSupport
- implements SARDeployerMBean
+public class SARDeployer extends AbstractAspectDeployer
{
/** The suffixes we accept, along with their relative order */
private static final String[] DEFAULT_ENHANCED_SUFFIXES = new String[] {
@@ -88,28 +84,27 @@
};
/** The deployment descriptor to look for */
- private static final String JBOSS_SERVICE = "META-INF/jboss-service.xml";
+ public static final String SAR_DESCRIPTOR = "META-INF/jboss-service.xml";
- /** A proxy to the ServiceController. */
- private ServiceControllerMBean serviceController;
+ /** The MBeanServer for the jmx bus of the ServiceController */
+ private MBeanServer server;
+ /** The ServiceController. */
+ private ServiceController serviceController;
- /** The server data directory. */
- private File dataDir;
-
/** The server configuration base URL. For example,
file:/<jboss_dist_root>/server/default. Relative service
descriptor codebase elements are relative to this URL.
*/
private URL serverHomeURL;
- /** A HashMap<ObjectName, DeploymentInfo> for the deployed services */
- private HashMap serviceDeploymentMap = new HashMap();
-
+ /** A Map<ObjectName, DeploymentContext> for the deployed services */
+ private Map<ObjectName, DeploymentContext> serviceDeploymentMap = new ConcurrentHashMap<ObjectName, DeploymentContext>();
+
/**
* A Map<String, List<String>> of the suffix to accepted archive META-INF descriptor name
* @todo externalize this
*/
- private Map suffixToDescriptorMap = new ConcurrentReaderHashMap();
+ private Map<String, List<String>> suffixToDescriptorMap = new ConcurrentHashMap<String, List<String>>();
/** A flag indicating if the parser used for the service descriptor should be configured for namespaces */
private boolean useNamespaceAwareParser;
@@ -119,14 +114,20 @@
*/
public SARDeployer()
{
+ super("SARDeployer");
setEnhancedSuffixes(DEFAULT_ENHANCED_SUFFIXES);
// Add the .har to META-INF/{jboss-service.xml,hibernate-service.xml} mapping
ArrayList tmp = new ArrayList();
- tmp.add(JBOSS_SERVICE);
+ tmp.add(SAR_DESCRIPTOR);
tmp.add("META-INF/hibernate-service.xml");
suffixToDescriptorMap.put(".har", tmp);
}
+ public String getType()
+ {
+ return "sar";
+ }
+
public boolean isUseNamespaceAwareParser()
{
return useNamespaceAwareParser;
@@ -137,6 +138,19 @@
this.useNamespaceAwareParser = useNamespaceAwareParser;
}
+ public ServiceControllerMBean getServiceController()
+ {
+ return serviceController;
+ }
+ public MBeanServer getServer()
+ {
+ return server;
+ }
+ public void setMBeanServer(MBeanServer server)
+ {
+ this.server = server;
+ }
+
/**
* Get the associated service DeploymentInfo if found, null otherwise
*
@@ -144,113 +158,146 @@
* @return The associated service DeploymentInfo if found, null otherwise
* @jmx.managed-operation
*/
- public DeploymentInfo getService(ObjectName serviceName)
+ public DeploymentContext getService(ObjectName serviceName)
{
- DeploymentInfo di = null;
- synchronized( serviceDeploymentMap )
+ DeploymentContext ctx = serviceDeploymentMap.get(serviceName);
+ return ctx;
+ }
+
+ /**
+ * Start the deployer.
+ */
+ @Override
+ public void start() throws Exception
+ {
+ if( server == null )
{
- di = (DeploymentInfo) serviceDeploymentMap.get(serviceName);
+ // Locate the jboss domain server
+ server = MBeanServerLocator.locateJBoss();
}
- return di;
+ // Create the ServiceController
+ serviceController = new ServiceController();
+ serviceController.setKernel(getKernelContext().getKernel());
+ serviceController.setMBeanServer(server);
}
/**
- * Describe <code>init</code> method here.
- *
- * @param di a <code>DeploymentInfo</code> value
- * @exception DeploymentException if an error occurs
- * @jmx.managed-operation
+ * Analyze a deployment for sar artifacts.
+ * @param ctx - the current deployment to validate as a sar and analyze
+ * @throws DeploymentException - throw if ctx is a sar and we fail to
+ * analyze it.
*/
- public void init(DeploymentInfo di)
- throws DeploymentException
+ @Override
+ public boolean analyze(DeploymentContext ctx) throws DeploymentException
{
- try
+ boolean isSARDeployment = false;
+ String basename = ctx.getFile().getName();
+ VirtualFile vf = ctx.getFile();
+ if (endsWithOneOfTheSuffixes(basename))
{
- if (di.url.getPath().endsWith("/"))
+ isSARDeployment = true;
+
+ try
{
- // the URL is a unpacked collection, watch the deployment descriptor
- di.watch = new URL(di.url, JBOSS_SERVICE);
+ try
+ {
+ // If the context contains a SAR_DESCRIPTOR its a sar archive
+ @SuppressWarnings("unused")
+ VirtualFile descriptor = vf.findChild(SAR_DESCRIPTOR);
+ log.debug("Found "+SAR_DESCRIPTOR+": "+descriptor);
+ ctx.putContextData(getClass(), SAR_DESCRIPTOR, Boolean.TRUE);
+ // add deployment base to the classpath
+ ctx.addClasspathEntry("");
+ }
+ catch(IOException ignore)
+ {
+ // The deployment context has no service descriptor
+ log.debug("No "+SAR_DESCRIPTOR+", assuming *-service.xml");
+ }
+
+ // Get the document if not already present
+ parseDocument(ctx);
+
+ // In case there is a dependent classpath defined parse it
+ parseXMLClasspath(ctx);
+
+ /* TODO: Copy local directory if local-directory element is present
+ NodeList lds = ctx.document.getElementsByTagName("local-directory");
+ log.debug("about to copy " + lds.getLength() + " local directories");
+
+ for (int i = 0; i< lds.getLength(); i++)
+ {
+ Element ld = (Element)lds.item(i);
+ String path = ld.getAttribute("path");
+ log.debug("about to copy local directory at " + path);
+
+ // Get the url of the local copy from the classloader.
+ log.debug("copying from " + ctx.localUrl + path + " -> " + dataDir);
+
+ inflateJar(ctx.localUrl, dataDir, path);
+ }
+ */
}
- else
+ catch (DeploymentException de)
{
- // just watch the original URL
- di.watch = di.url;
+ throw de;
}
-
- // Get the document if not already present
- parseDocument(di);
-
- // Check for a custom loader-repository for scoping
- NodeList loaders = di.document.getElementsByTagName("loader-repository");
- if( loaders.getLength() > 0 )
+ catch (Exception e)
{
- Element loader = (Element) loaders.item(0);
- LoaderRepositoryConfig config = LoaderRepositoryFactory.parseRepositoryConfig(loader);
- di.setRepositoryInfo(config);
+ throw new DeploymentException(e);
}
+ } // if endsWithOneOfTheSuffixes
- // In case there is a dependent classpath defined parse it
- parseXMLClasspath(di);
+ return isSARDeployment;
+ }
- // Copy local directory if local-directory element is present
- NodeList lds = di.document.getElementsByTagName("local-directory");
- log.debug("about to copy " + lds.getLength() + " local directories");
-
- for (int i = 0; i< lds.getLength(); i++)
- {
- Element ld = (Element)lds.item(i);
- String path = ld.getAttribute("path");
- log.debug("about to copy local directory at " + path);
-
- // Get the url of the local copy from the classloader.
- log.debug("copying from " + di.localUrl + path + " -> " + dataDir);
-
- inflateJar(di.localUrl, dataDir, path);
- }
- }
- catch (DeploymentException de)
- {
- throw de;
- }
- catch (Exception e)
- {
- throw new DeploymentException(e);
- }
-
- // invoke super-class initialization
- super.init(di);
+ /**
+ * Return the profileservice managed object for the given ctx.
+ * TODO: need to define how a sar expresses its managed properties
+ */
+ public Object getManagedObject(DeploymentContext ctx)
+ {
+ return null;
}
/**
- * Describe <code>create</code> method here.
+ * deploy all mbeans in the sar deployment context.
*
- * @param di a <code>DeploymentInfo</code> value
+ * @param ctx - deployment context to deploy
* @exception DeploymentException if an error occurs
- * @jmx.managed-operation
*/
- public void create(DeploymentInfo di)
- throws DeploymentException
+ public void deploy(DeploymentContext ctx) throws DeploymentException
{
+ log.debug("Deploy, "+ctx);
try
{
- // install the MBeans in this descriptor
- log.debug("Deploying SAR, create step: url " + di.url);
+ // Check for a custom loader-repository for scoping
+ Document document = (Document) ctx.getContextData(getClass(), "document");
+ NodeList loaders = document.getElementsByTagName("loader-repository");
+ LoaderRepositoryConfig config = null;
+ if( loaders.getLength() > 0 )
+ {
+ Element loader = (Element) loaders.item(0);
+ config = LoaderRepositoryFactory.parseRepositoryConfig(loader);
+ }
+ // Create the legacy UCL
+ RepositoryClassLoader ucl = createClassLoaders(ctx, config);
// Register the SAR UCL as an mbean so we can use it as the service loader
- ObjectName uclName = di.ucl.getObjectName();
- if( getServer().isRegistered(uclName) == false )
+ ObjectName uclName = ucl.getObjectName();
+ if( server.isRegistered(uclName) == false )
{
log.debug("Registering service UCL="+uclName);
- getServer().registerMBean(di.ucl, uclName);
+ server.registerMBean(ucl, uclName);
}
- List mbeans = di.mbeans;
+ List<ObjectName> mbeans = (List<ObjectName>) ctx.getContextData(getClass(), "mbeans");
mbeans.clear();
- List descriptorMbeans = serviceController.install(di.document.getDocumentElement(), uclName);
+ List descriptorMbeans = serviceController.install(document.getDocumentElement(), uclName);
mbeans.addAll(descriptorMbeans);
// create the services
- for (Iterator iter = di.mbeans.iterator(); iter.hasNext(); )
+ for (Iterator<ObjectName> iter = mbeans.iterator(); iter.hasNext(); )
{
ObjectName service = (ObjectName)iter.next();
@@ -258,72 +305,43 @@
serviceController.create(service);
synchronized( this.serviceDeploymentMap )
{
- serviceDeploymentMap.put(service, di);
+ serviceDeploymentMap.put(service, ctx);
}
}
- // Generate a JMX notification for the create stage
- super.create(di);
- }
- catch(DeploymentException e)
- {
- log.debug("create operation failed for package "+ di.url, e);
- destroy(di);
- throw e;
- }
- catch (Exception e)
- {
- log.debug("create operation failed for package "+ di.url, e);
- destroy(di);
- throw new DeploymentException("create operation failed for package "
- + di.url, e);
- }
- }
+ // TODO: Generate a JMX notification for the create stage
+ // super.create(ctx);
- /**
- * The <code>start</code> method starts all the mbeans in this DeploymentInfo..
- *
- * @param di a <code>DeploymentInfo</code> value
- * @exception DeploymentException if an error occurs
- * @jmx.managed-operation
- */
- public void start(DeploymentInfo di) throws DeploymentException
- {
- log.debug("Deploying SAR, start step: url " + di.url);
- try
- {
- // start the services
-
- for (Iterator iter = di.mbeans.iterator(); iter.hasNext(); )
+ for (Iterator<ObjectName> iter = mbeans.iterator(); iter.hasNext(); )
{
- ObjectName service = (ObjectName)iter.next();
+ ObjectName service = iter.next();
// The service won't be started until explicitely dependent mbeans are started
serviceController.start(service);
}
- // Generate a JMX notification for the start stage
- super.start(di);
+ // TODO: Generate a JMX notification for the start stage
+ // super.start(ctx);
}
catch (Exception e)
{
- stop(di);
- destroy(di);
- throw new DeploymentException("start operation failed on package "
- + di.url, e);
+ throw new DeploymentException("Failed to deploy SAR: "+ctx, e);
}
+
+ // Generate a notification for the undeploy
+ generateDeployerEvent(ctx, DeploymentEvent.DEPLOY);
}
/** The stop method invokes stop on the mbeans associatedw ith the deployment
* in reverse order relative to create.
*
- * @param di the <code>DeploymentInfo</code> value to stop.
+ * @param ctx the <code>DeploymentInfo</code> value to stop.
* @jmx.managed-operation
*/
- public void stop(DeploymentInfo di)
+ public void undeploy(DeploymentContext ctx) throws DeploymentException
{
- log.debug("undeploying document " + di.url);
+ log.debug("Undeploy, " + ctx);
- List services = di.mbeans;
+ List<ObjectName> services = (List<ObjectName>) ctx.getContextData(getClass(), "mbeans");
int lastService = services.size();
// stop services in reverse order.
@@ -341,160 +359,24 @@
} // end of try-catch
}
- // Generate a JMX notification for the stop stage
- try
- {
- super.stop(di);
- }
- catch(Exception ignore)
- {
- }
+ // Generate a notification for the undeploy
+ generateDeployerEvent(ctx, DeploymentEvent.UNDEPLOY);
}
- /** The destroy method invokes destroy on the mbeans associated with
- * the deployment in reverse order relative to create.
- *
- * @param di a <code>DeploymentInfo</code> value
- * @jmx.managed-operation
- */
- public void destroy(DeploymentInfo di)
- {
- List services = di.mbeans;
- int lastService = services.size();
-
- for (ListIterator i = services.listIterator(lastService); i.hasPrevious();)
- {
- ObjectName name = (ObjectName)i.previous();
- log.debug("destroying mbean " + name);
- synchronized( serviceDeploymentMap )
- {
- serviceDeploymentMap.remove(name);
- }
-
- try
- {
- serviceController.destroy(name);
- }
- catch (Exception e)
- {
- log.error("Could not destroy mbean: " + name, e);
- } // end of try-catch
- }
-
- for (ListIterator i = services.listIterator(lastService); i.hasPrevious();)
- {
- ObjectName name = (ObjectName)i.previous();
- log.debug("removing mbean " + name);
- try
- {
- serviceController.remove(name);
- }
- catch (Exception e)
- {
- log.error("Could not remove mbean: " + name, e);
- } // end of try-catch
- }
-
- // Unregister the SAR UCL
- try
- {
- ObjectName uclName = di.ucl.getObjectName();
- if( getServer().isRegistered(uclName) == true )
- {
- log.debug("Unregistering service UCL="+uclName);
- getServer().unregisterMBean(uclName);
- }
- }
- catch(Exception ignore)
- {
- }
-
- // Generate a JMX notification for the destroy stage
- try
- {
- super.destroy(di);
- }
- catch(Exception ignore)
- {
- }
- }
-
- // ServiceMBeanSupport overrides --------------------------------
-
- /**
- * The startService method gets the mbeanProxies for MainDeployer
- * and ServiceController, used elsewhere.
- *
- * @exception Exception if an error occurs
- */
- protected void startService() throws Exception
- {
- super.startService();
-
- // get the controller proxy
- serviceController = (ServiceControllerMBean)
- MBeanProxyExt.create(ServiceControllerMBean.class,
- ServiceControllerMBean.OBJECT_NAME, server);
-
- // Get the data directory, install url & library url
- ServerConfig config = ServerConfigLocator.locate();
- dataDir = config.getServerDataDir();
- serverHomeURL = config.getServerHomeURL();
- }
-
- /**
- * This method stops all the applications in this server.
- */
- protected void stopService() throws Exception
- {
- // deregister with MainDeployer
- super.stopService();
-
- // Help GC
- serviceController = null;
- serverHomeURL = null;
- dataDir = null;
- }
-
-
- protected ObjectName getObjectName(MBeanServer server, ObjectName name)
- throws MalformedObjectNameException
- {
- return name == null ? OBJECT_NAME : name;
- }
-
// Protected -----------------------------------------------------
- protected File[] listFiles(final String urlspec) throws Exception
- {
- URL url = Strings.toURL(urlspec);
-
- // url is already canonical thanks to Strings.toURL
- File dir = new File(url.getFile());
-
- File[] files = dir.listFiles(new java.io.FileFilter()
- {
- public boolean accept(File pathname)
- {
- String name = pathname.getName().toLowerCase();
- return (name.endsWith(".jar") || name.endsWith(".zip"));
- }
- });
-
- return files;
- }
-
/**
- * @param di
+ * @param ctx
* @throws Exception
*/
- protected void parseXMLClasspath(DeploymentInfo di)
+ protected void parseXMLClasspath(DeploymentContext ctx)
throws Exception
{
ArrayList classpath = new ArrayList();
URLListerFactory listerFactory = new URLListerFactory();
- NodeList children = di.document.getDocumentElement().getChildNodes();
+ Document document = (Document) ctx.getContextData(getClass(), "document");
+ NodeList children = document.getDocumentElement().getChildNodes();
for (int i = 0; i < children.getLength(); i++)
{
if (children.item(i).getNodeType() == Node.ELEMENT_NODE)
@@ -530,7 +412,7 @@
URL codebaseUrl;
if (".".equals(codebase))
{
- codebaseUrl = new URL(di.url, "./");
+ codebaseUrl = ctx.getFile().toURL();
}
else
{
@@ -566,63 +448,72 @@
Iterator jars = classpath.iterator();
while (jars.hasNext())
{
- URL neededURL = (URL) jars.next();
- di.addLibraryJar(neededURL);
- log.debug("deployed classes for " + neededURL);
+ // TODO
+ throw new Exception("Have not ported sar classpath to VFS");
}
}
/** Parse the META-INF/jboss-service.xml descriptor
*/
- protected void parseDocument(DeploymentInfo di)
+ protected void parseDocument(DeploymentContext ctx)
throws Exception
{
InputStream stream = null;
try
{
- if (di.document == null)
+ Document document = (Document) ctx.getContextData(getClass(), "document");
+ if (document == null)
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(useNamespaceAwareParser);
DocumentBuilder parser = factory.newDocumentBuilder();
- URL docURL = di.localUrl;
- URLClassLoader localCL = di.localCl;
+ VirtualFile docFile = null;
// Load jboss-service.xml from the jar or directory
- if (di.isXML == false)
+ Boolean isJAR = (Boolean) ctx.getContextData(getClass(), SAR_DESCRIPTOR);
+ if ( isJAR )
{
// Check the suffix to descriptor mapping
- String[] descriptors = getDescriptorName(di);
+ VirtualFile ctxFile = ctx.getFile();
+ String[] descriptors = getDescriptorName(ctx);
for(int n = 0; n < descriptors.length; n ++)
{
String descriptor = descriptors[n];
- docURL = localCL.findResource(descriptor);
- if( docURL != null )
+ docFile = ctxFile.findChild(descriptor);
+ if( docFile != null )
{
// If this is a unpacked deployment, update the watch url
- if (di.url.getPath().endsWith("/"))
+ if (ctxFile.isDirectory())
{
- di.watch = new URL(di.url, descriptor);
- log.debug("Updated watch URL to: "+di.watch);
+ ctx.setWatchFile(docFile);
+ log.debug("Updated watch URL to: "+docFile);
}
break;
}
}
// No descriptors, use the default META-INF/jboss-service.xml
- if( docURL == null )
- docURL = localCL.findResource(JBOSS_SERVICE);
+ if( docFile == null )
+ docFile = ctxFile.findChild(SAR_DESCRIPTOR);
}
+ else
+ {
+ docFile = ctx.getFile();
+ }
// Validate that the descriptor was found
- if (docURL == null)
- throw new DeploymentException("Failed to find META-INF/jboss-service.xml for archive " + di.shortName);
+ if (docFile == null)
+ throw new DeploymentException("Failed to find META-INF/jboss-service.xml for archive: " + ctx);
- stream = docURL.openStream();
+ stream = docFile.openStream();
InputSource is = new InputSource(stream);
- is.setSystemId(docURL.toString());
+ is.setSystemId(docFile.toURL().toString());
parser.setEntityResolver(new JBossEntityResolver());
- di.document = parser.parse(is);
+ document = parser.parse(is);
+ // TODO: Need remove this dependency on org.w3c.dom.Document
+ Serializable serialDoc = (Serializable) document;
+ ctx.putContextData(getClass(), "document", serialDoc);
}
else
{
+ // TODO: when was this used?
log.debug("Using existing deployment.document");
}
}
@@ -639,55 +530,6 @@
}
}
- /**
- * The <code>inflateJar</code> copies the jar entries
- * from the jar url jarUrl to the directory destDir.
- * It can be used on the whole jar, a directory, or
- * a specific file in the jar.
- *
- * @param url the <code>URL</code> if the directory or entry to copy.
- * @param destDir the <code>File</code> value of the directory in which to
- * place the inflated copies.
- *
- * @exception DeploymentException if an error occurs
- * @exception IOException if an error occurs
- */
- protected void inflateJar(URL url, File destDir, String path)
- throws DeploymentException, IOException
- {
- String filename = url.getFile();
- JarFile jarFile = new JarFile(filename);
- try
- {
- for (Enumeration e = jarFile.entries(); e.hasMoreElements(); )
- {
- JarEntry entry = (JarEntry)e.nextElement();
- String name = entry.getName();
-
- if (path == null || name.startsWith(path))
- {
- File outFile = new File(destDir, name);
- if (!outFile.exists())
- {
- if (entry.isDirectory())
- {
- outFile.mkdirs();
- }
- else
- {
- Streams.copyb(jarFile.getInputStream(entry),
- new FileOutputStream(outFile));
- }
- } // end of if (outFile.exists())
- } // end of if (matches path)
- }
- }
- finally
- {
- jarFile.close();
- }
- }
-
// Private -------------------------------------------------------
/**
@@ -699,10 +541,10 @@
* there is no suffix to descriptor mapping, the default of {JBOSS_SERVICE} will be
* returned.
*/
- private String[] getDescriptorName(DeploymentInfo sdi)
+ private String[] getDescriptorName(DeploymentContext ctx)
{
- String[] descriptorNames = {JBOSS_SERVICE};
- String shortName = sdi.shortName;
+ String[] descriptorNames = {SAR_DESCRIPTOR};
+ String shortName = ctx.getFile().getName();
int dot = shortName.lastIndexOf('.');
if( dot >= 0 )
{
@@ -716,4 +558,64 @@
}
return descriptorNames;
}
+
+ /** Create a UnifiedClassLoader for the deployment that loads from
+ the localUrl and uses its parent deployments url as its orignal
+ url. Previously xml descriptors simply used the TCL but since the UCLs
+ are now registered as mbeans each must be unique.
+ */
+ private RepositoryClassLoader createClassLoaders(DeploymentContext ctx,
+ LoaderRepositoryConfig repositoryConfig) throws Exception
+ {
+ /* Walk the deployment tree to find the parent deployment and obtain its
+ url to use as our URL from which this deployment unit originated. This
+ is used to determine permissions using the original URL namespace.
+ Also pick up the LoaderRepository from the topmost ancestor.
+ */
+ DeploymentContext current = ctx;
+ while (current.getParentContext() != null)
+ {
+ current = current.getParentContext();
+ }
+
+ RepositoryClassLoader ucl = null;
+ DeploymentContext parent = ctx.getParentContext();
+ URL ctxURL = ctx.getFile().toURL();
+ if( parent == null )
+ {
+ if( repositoryConfig == null )
+ repositoryConfig = new LoaderRepositoryConfig();
+ // Make sure the specified LoaderRepository exists.
+ LoaderRepositoryFactory.createLoaderRepository(server, repositoryConfig);
+ log.debug("createLoaderRepository from config: "+repositoryConfig);
+ // the classes are passed to a UCL that will share the classes with the whole base
+ boolean isXML = ctx.getFile().getName().endsWith(".xml");
+ Object[] args = { isXML ? null : ctxURL, ctxURL, Boolean.TRUE };
+ String[] sig = { "java.net.URL", "java.net.URL", "boolean" };
+ ucl = (RepositoryClassLoader) server.invoke(repositoryConfig.repositoryName,
+ "newClassLoader",args, sig);
+ ctx.putContextData(getClass(), "ucl", ucl);
+ // TODO: add sar classpath jars
+ }
+ else
+ {
+ // Add a reference to the LoaderRepository
+ LoaderRepositoryFactory.createLoaderRepository(server, repositoryConfig);
+ // Add the deployment URL to the parent UCL
+ ucl = (RepositoryClassLoader) parent.getContextData(getClass(), "ucl");
+ if( ucl != null )
+ {
+ ucl.addURL(ctxURL);
+ }
+ /* TODO: there is a problem if parent ucl is null because its not a sar
+ for example.
+ */
+ else
+ {
+ log.warn("Null parent ucl for sar: "+ctx);
+ }
+ }
+ return ucl;
+ }
+
}
Added: branches/MC_VDF_WORK/system/src/main/org/jboss/system/server/jmx/JMXKernel.java
===================================================================
--- branches/MC_VDF_WORK/system/src/main/org/jboss/system/server/jmx/JMXKernel.java 2006-08-04 06:48:49 UTC (rev 55170)
+++ branches/MC_VDF_WORK/system/src/main/org/jboss/system/server/jmx/JMXKernel.java 2006-08-04 06:50:04 UTC (rev 55171)
@@ -0,0 +1,493 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.system.server.jmx;
+
+import java.io.File;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.logging.LogManager;
+
+import javax.management.ListenerNotFoundException;
+import javax.management.MBeanNotificationInfo;
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.Notification;
+import javax.management.NotificationFilter;
+import javax.management.NotificationListener;
+import javax.management.ObjectInstance;
+import javax.management.ObjectName;
+
+import org.jboss.logging.JBossJDKLogManager;
+import org.jboss.mx.loading.RepositoryClassLoader;
+import org.jboss.mx.server.ServerConstants;
+import org.jboss.mx.util.JBossNotificationBroadcasterSupport;
+import org.jboss.mx.util.JMXExceptionDecoder;
+import org.jboss.mx.util.MBeanServerLocator;
+import org.jboss.mx.util.ObjectNameFactory;
+import org.jboss.system.ServiceControllerMBean;
+import org.jboss.system.server.Server;
+import org.jboss.system.server.ServerConfig;
+import org.jboss.system.server.ServerConfigImplMBean;
+import org.jboss.system.server.ServerConfigLocator;
+import org.jboss.system.server.ServerImplMBean;
+import org.jboss.util.JBossObject;
+import org.jboss.util.file.FileSuffixFilter;
+
+/**
+ * A pojo that creates a legacy jmx kernel ala the jboss-4.x server bootstrap.
+ * This is used to support the SARDeployer and mbean integration.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class JMXKernel extends JBossObject
+ implements JMXKernelMBean
+{
+ private final static ObjectName DEFAULT_LOADER_NAME =
+ ObjectNameFactory.create(ServerConstants.DEFAULT_LOADER_NAME);
+
+ /** The JMX MBeanServer which will serve as our communication bus. */
+ private MBeanServer server;
+ private ServerImplMBean serverImpl;
+ private ServiceControllerMBean controller;
+ private ServerConfig config;
+ /** The NotificationBroadcaster implementation delegate */
+ private JBossNotificationBroadcasterSupport broadcasterSupport;
+
+ /** The bootstrap UCL class loader ObjectName */
+ private ObjectName bootstrapUCLName;
+ private boolean started;
+ /** A flag indicating if shutdown has been called */
+ private boolean isInShutdown;
+
+ public ServerImplMBean getServerImpl()
+ {
+ return serverImpl;
+ }
+ public void setServerImpl(ServerImplMBean serverImpl)
+ {
+ this.serverImpl = serverImpl;
+ }
+
+ public ServiceControllerMBean getServiceController()
+ {
+ return this.controller;
+ }
+ public void setServiceController(final ServiceControllerMBean controller)
+ {
+ this.controller = controller;
+ }
+
+ public void start() throws Exception
+ {
+ long start = System.currentTimeMillis();
+
+ // Create the MBeanServer
+ String builder = System.getProperty(ServerConstants.MBEAN_SERVER_BUILDER_CLASS_PROPERTY,
+ ServerConstants.DEFAULT_MBEAN_SERVER_BUILDER_CLASS);
+ System.setProperty(ServerConstants.MBEAN_SERVER_BUILDER_CLASS_PROPERTY, builder);
+
+ if( config == null )
+ config = ServerConfigLocator.locate();
+ // Check if we'll use the platform MBeanServer or instantiate our own
+ if (config.getPlatformMBeanServer() == true)
+ {
+ // jdk1.5+
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ Class clazz = cl.loadClass("java.lang.management.ManagementFactory");
+ Class[] sig = null;
+ Method method = clazz.getMethod("getPlatformMBeanServer", sig);
+ Object[] args = null;
+ server = (MBeanServer) method.invoke(null, args);
+ // Tell the MBeanServerLocator to point to this server
+ MBeanServerLocator.setJBoss(server);
+ /* If the LazyMBeanServer was used, we need to reset to the jboss
+ MBeanServer to use our implementation for the jboss services.
+ */
+ server = LazyMBeanServer.resetToJBossServer(server);
+ }
+ else
+ {
+ // Create our own MBeanServer
+ server = MBeanServerFactory.createMBeanServer("jboss");
+ }
+ log.debug("Created MBeanServer: " + server);
+
+ // Register server components
+ server.registerMBean(this, ServerImplMBean.OBJECT_NAME);
+ server.registerMBean(config, ServerConfigImplMBean.OBJECT_NAME);
+
+ // Initialize spine boot libraries
+ RepositoryClassLoader ucl = initBootLibraries();
+ bootstrapUCLName = ucl.getObjectName();
+ server.registerMBean(ucl, bootstrapUCLName);
+
+ // Set ServiceClassLoader as classloader for the construction of
+ // the basic system
+ Thread.currentThread().setContextClassLoader(ucl);
+
+ // General Purpose Architecture information
+ createMBean("org.jboss.system.server.ServerInfo",
+ "jboss.system:type=ServerInfo");
+
+ // Service Controller
+ server.registerMBean(controller, new ObjectName("jboss.system:service=ServiceController"));
+
+ log.info("Legacy JMX core initialized");
+ started = true;
+ long end = System.currentTimeMillis();
+
+ // Send a notification that the startup is complete
+ Notification msg = new Notification(Server.START_NOTIFICATION_TYPE, this, 1);
+ msg.setUserData(new Long(end - start));
+ sendNotification(msg);
+ }
+
+ /**
+ * Stop the mbeans
+ *
+ * @throws IllegalStateException - if not started.
+ */
+ public void stop() throws IllegalStateException
+ {
+ if (log.isTraceEnabled())
+ log.trace("stop caller:", new Throwable("Here"));
+
+ if (!started)
+ throw new IllegalStateException("Server not started");
+
+ isInShutdown = true;
+ // start in new thread to give positive
+ // feedback to requesting client of success.
+ new Thread()
+ {
+ public void run()
+ {
+ // just run the hook, don't call System.exit, as we may
+ // be embeded in a vm that would not like that very much
+ shutdown();
+ }
+ }.start();
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ // NotificationEmitter //
+ ///////////////////////////////////////////////////////////////////////////
+
+ public void addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback)
+ {
+ broadcasterSupport.addNotificationListener(listener, filter, handback);
+ }
+
+ public void removeNotificationListener(NotificationListener listener) throws ListenerNotFoundException
+ {
+ broadcasterSupport.removeNotificationListener(listener);
+ }
+
+ public void removeNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback)
+ throws ListenerNotFoundException
+ {
+ broadcasterSupport.removeNotificationListener(listener, filter, handback);
+ }
+
+ public MBeanNotificationInfo[] getNotificationInfo()
+ {
+ return broadcasterSupport.getNotificationInfo();
+ }
+
+ public void sendNotification(Notification notification)
+ {
+ broadcasterSupport.sendNotification(notification);
+ }
+
+ // ServerImplMBean delegation
+ public void exit()
+ {
+ serverImpl.exit();
+ }
+
+ public void exit(int exitcode)
+ {
+ serverImpl.exit(exitcode);
+ }
+
+ public String getBuildDate()
+ {
+ return serverImpl.getBuildDate();
+ }
+
+ public String getBuildID()
+ {
+ return serverImpl.getBuildID();
+ }
+
+ public String getBuildJVM()
+ {
+ return serverImpl.getBuildJVM();
+ }
+
+ public String getBuildNumber()
+ {
+ return serverImpl.getBuildNumber();
+ }
+
+ public String getBuildOS()
+ {
+ return serverImpl.getBuildOS();
+ }
+
+ public Date getStartDate()
+ {
+ return serverImpl.getStartDate();
+ }
+
+ public String getVersion()
+ {
+ return serverImpl.getVersion();
+ }
+
+ public String getVersionName()
+ {
+ return serverImpl.getVersionName();
+ }
+
+ public void halt()
+ {
+ serverImpl.halt();
+ }
+
+ public void halt(int exitcode)
+ {
+ serverImpl.halt(exitcode);
+ }
+
+ public boolean isInShutdown()
+ {
+ return serverImpl.isInShutdown();
+ }
+
+ public boolean isStarted()
+ {
+ return serverImpl.isStarted();
+ }
+
+ public void runFinalization()
+ {
+ serverImpl.runFinalization();
+ }
+
+ public void runGarbageCollector()
+ {
+ serverImpl.runGarbageCollector();
+ }
+
+ public void traceInstructions(Boolean flag)
+ {
+ serverImpl.traceInstructions(flag);
+ }
+
+ public void traceMethodCalls(Boolean flag)
+ {
+ serverImpl.traceMethodCalls(flag);
+ }
+
+ public void shutdown()
+ {
+ if (log.isTraceEnabled())
+ log.trace("Shutdown caller:", new Throwable("Here"));
+
+ // Execute the jdk JBossJDKLogManager doReset
+ LogManager lm = LogManager.getLogManager();
+ if (lm instanceof JBossJDKLogManager)
+ {
+ JBossJDKLogManager jbosslm = (JBossJDKLogManager)lm;
+ jbosslm.doReset();
+ }
+
+ // avoid entering twice; may happen when called directly
+ // from ServerImpl.shutdown(), then called again when all
+ // non-daemon threads have exited and the ShutdownHook runs.
+ if (isInShutdown)
+ return;
+ else
+ isInShutdown = true;
+
+ // Send a notification that server stop is initiated
+ Notification msg = new Notification(Server.STOP_NOTIFICATION_TYPE, this, 2);
+ sendNotification(msg);
+
+ // ServiceController.shutdown()
+ log.debug("Shutting down all services");
+ shutdownServices();
+
+ // Make sure all mbeans are unregistered
+ removeMBeans();
+
+ // Done
+ log.info("Legacy kernel shutdown complete");
+ System.out.println("Legacy kernel shutdown complete");
+ }
+
+ /**
+ * The <code>shutdownServices</code> method calls the one and only
+ * ServiceController to shut down all the mbeans registered with it.
+ */
+ protected void shutdownServices()
+ {
+ try
+ {
+ // get the deployed objects from ServiceController
+ controller.shutdown();
+ }
+ catch (Exception e)
+ {
+ Throwable t = JMXExceptionDecoder.decode(e);
+ log.error("Failed to shutdown services", t);
+ }
+ }
+
+ /**
+ * The <code>removeMBeans</code> method uses the mbean server to unregister
+ * all the mbeans registered here.
+ */
+ protected void removeMBeans()
+ {
+ try
+ {
+ server.unregisterMBean(ServiceControllerMBean.OBJECT_NAME);
+ server.unregisterMBean(ServerConfigImplMBean.OBJECT_NAME);
+ server.unregisterMBean(ServerImplMBean.OBJECT_NAME);
+ }
+ catch (Exception e)
+ {
+ Throwable t = JMXExceptionDecoder.decode(e);
+ log.error("Failed to unregister mbeans", t);
+ }
+ try
+ {
+ MBeanServer registeredServer = server;
+ if (config.getPlatformMBeanServer() == true)
+ registeredServer = LazyMBeanServer.getRegisteredMBeanServer(server);
+ MBeanServerFactory.releaseMBeanServer(registeredServer);
+ }
+ catch (Exception e)
+ {
+ Throwable t = JMXExceptionDecoder.decode(e);
+ log.error("Failed to release mbean server", t);
+ }
+ }
+
+
+ /**
+ * Initialize the boot libraries.
+ */
+ private RepositoryClassLoader initBootLibraries() throws Exception
+ {
+ // Build the list of URL for the spine to boot
+ List<URL> list = new ArrayList<URL>();
+
+ // Add the patch URL. If the url protocol is file, then
+ // add the contents of the directory it points to
+ URL patchURL = config.getPatchURL();
+ if (patchURL != null)
+ {
+ if (patchURL.getProtocol().equals("file"))
+ {
+ File dir = new File(patchURL.getFile());
+ if (dir.exists())
+ {
+ // Add the local file patch directory
+ list.add(dir.toURL());
+
+ // Add the contents of the directory too
+ File[] jars = dir.listFiles(new FileSuffixFilter(new String[] { ".jar", ".zip" }, true));
+
+ for (int j = 0; jars != null && j < jars.length; j++)
+ {
+ list.add(jars[j].getCanonicalFile().toURL());
+ }
+ }
+ }
+ else
+ {
+ list.add(patchURL);
+ }
+ }
+
+ // Add the server configuration directory to be able to load config files as resources
+ list.add(config.getServerConfigURL());
+ log.debug("Boot url list: " + list);
+
+ // Create loaders for each URL
+ RepositoryClassLoader loader = null;
+ for (Iterator iter = list.iterator(); iter.hasNext();)
+ {
+ URL url = (URL)iter.next();
+ log.debug("Creating loader for URL: " + url);
+
+ // This is a boot URL, so key it on itself.
+ Object[] args = {url, Boolean.TRUE};
+ String[] sig = {"java.net.URL", "boolean"};
+ loader = (RepositoryClassLoader) server.invoke(DEFAULT_LOADER_NAME, "newClassLoader", args, sig);
+ }
+ return loader;
+ }
+
+ /**
+ * Instantiate and register a service for the given classname into the MBean server.
+ */
+ private ObjectName createMBean(final String classname, String name)
+ throws Exception
+ {
+ ObjectName mbeanName = null;
+ if( name != null )
+ mbeanName = new ObjectName(name);
+ try
+ {
+ // See if there is an xmbean descriptor for the bootstrap mbean
+ URL xmbeanDD = new URL("resource:xmdesc/"+classname+"-xmbean.xml");
+ Object resource = server.instantiate(classname);
+ // Create the XMBean
+ Object[] args = {resource, xmbeanDD};
+ String[] sig = {Object.class.getName(), URL.class.getName()};
+ ObjectInstance instance = server.createMBean("org.jboss.mx.modelmbean.XMBean",
+ mbeanName,
+ bootstrapUCLName,
+ args,
+ sig);
+ mbeanName = instance.getObjectName();
+ log.debug("Created system XMBean: "+mbeanName);
+ }
+ catch(Exception e)
+ {
+ log.debug("Failed to create xmbean for: "+classname);
+ mbeanName = server.createMBean(classname, mbeanName).getObjectName();
+ log.debug("Created system MBean: " + mbeanName);
+ }
+
+ return mbeanName;
+ }
+}
Added: branches/MC_VDF_WORK/system/src/main/org/jboss/system/server/jmx/JMXKernelMBean.java
===================================================================
--- branches/MC_VDF_WORK/system/src/main/org/jboss/system/server/jmx/JMXKernelMBean.java 2006-08-04 06:48:49 UTC (rev 55170)
+++ branches/MC_VDF_WORK/system/src/main/org/jboss/system/server/jmx/JMXKernelMBean.java 2006-08-04 06:50:04 UTC (rev 55171)
@@ -0,0 +1,29 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.system.server.jmx;
+
+import org.jboss.system.server.ServerImplMBean;
+
+public interface JMXKernelMBean extends ServerImplMBean
+{
+
+}
More information about the jboss-cvs-commits
mailing list