geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/classspace ClassSpace.java ClassSpaceException.java ClassSpaceLoader.java ClassSpaceUtil.java DefaultClassSpace.java classspace-mbean.xml
Date Mon, 27 Oct 2003 20:58:38 GMT
dain        2003/10/27 12:58:38

  Added:       modules/kernel/src/java/org/apache/geronimo/kernel/classspace
                        ClassSpace.java ClassSpaceException.java
                        ClassSpaceLoader.java ClassSpaceUtil.java
                        DefaultClassSpace.java classspace-mbean.xml
  Log:
  Rewrite of classspace from o.a.g.k.d.loader.  This implementation changes
  class sapce to be a holder of a class loader instead of a class loader
  itself. This allows the class loader instance to be swapped without
  effecting references to the class space.  This is important when we get
  into redeploying classes.  Class space is not a geronimo mbean, so it
  supports the J2EE management interface.
  
  Revision  Changes    Path
  1.1                  incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/classspace/ClassSpace.java
  
  Index: ClassSpace.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.kernel.classspace;
  
  import java.util.List;
  import javax.management.ObjectName;
  
  /**
   *
   * @version $Revision: 1.1 $ $Date: 2003/10/27 20:58:38 $
   */
  public interface ClassSpace {
      /**
       * Gets the parent of this class space.  If null the parent of this
       * class space is the system class loader.  This may not be
       * the same as the currentParent if the class space has not been
       * restarted since the last time the parent was set.
       *
       * @return the parent class space
       */
      ObjectName getParent();
  
      /**
       * Sets the parent of this class space.  If null the parent of this
       * class space will be the system class loader.  The current parent
       * will not be changed until the class space restarts.
       * @param parent the new parent of this class space
       */
      public void setParent(ObjectName parent);
  
      /**
       * Gets the current parent of this class space.  If null, the parent
       * of this class space is the system class loader. This may not
       * be the same as the parent if the class space has not been
       * restarted since the last time the parent was set.
       * @return the current parrent of this class space
       */
      public ObjectName getCurrentParent();
  
      /**
       * Gets the class loader instance used by this class space.  This
       * will be null if the class space is not running (or stopping).
       * @return the class loader used by this class space
       */
      ClassLoader getClassLoader();
  
      /**
       * Adds a deployment and associated URLs to this class space
       * @param deployment the deployment to add
       * @param urls the new urls to add
       */
      void addDeployment(ObjectName deployment, List urls);
  
      /**
       * Drops a deployment and associated URLs from this class space.
       * Deployment and urls are not actually dropped until the class space is restarted.
       * @param deployment the deployment to drop
       */
      void dropDeployment(ObjectName deployment);
  }
  
  
  
  1.1                  incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/classspace/ClassSpaceException.java
  
  Index: ClassSpaceException.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.kernel.classspace;
  
  /**
   * Unchecked exception thrown when problems occur when working with a class space
   * 
   * @version $Revision: 1.1 $ $Date: 2003/10/27 20:58:38 $
   */
  public class ClassSpaceException extends RuntimeException {
      public ClassSpaceException() {
      }
  
      public ClassSpaceException(String message) {
          super(message);
      }
  
      public ClassSpaceException(String message, Throwable cause) {
          super(message, cause);
      }
  
      public ClassSpaceException(Throwable cause) {
          super(cause);
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/classspace/ClassSpaceLoader.java
  
  Index: ClassSpaceLoader.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.kernel.classspace;
  
  import java.net.URL;
  import java.net.URLClassLoader;
  import java.util.Collections;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Map;
  import java.util.SortedSet;
  import java.util.TreeSet;
  
  /**
   * This is the class loader used internally by the default class space.
   * This is just a URLClassLoader with extra intrumentation.
   * 
   * @version $Revision: 1.1 $ $Date: 2003/10/27 20:58:38 $
   */
  class ClassSpaceLoader extends URLClassLoader {
      /**
       * Cache of loaded classesByName... used for debugging purposes
       */
      private final Map classesByName = new HashMap();
  
      /**
       * Unique name of this class loader
       */
      private String name;
  
      /**
       * Constructs a ClassSpaceLoader wich is a child of the specified parent.
       * @param parent parent of this class loader
       */
      public ClassSpaceLoader(ClassLoader parent, String name) {
          super(new URL[0], parent);
          this.name = name;
      }
  
      public String toString() {
          return "[ClassSpaceLoader: name=" + name + "]";
      }
  
      /**
       * Adds the specifiec URLs to this class loader.
       * @param urls the URLs to add
       */
      void addURLs(List urls) {
          for (Iterator iterator = urls.iterator(); iterator.hasNext();) {
              URL url = (URL) iterator.next();
              addURL(url);
          }
      }
  
      SortedSet listLoadedClassNames() {
          synchronized(classesByName) {
              return Collections.unmodifiableSortedSet(new TreeSet(classesByName.keySet()));
          }
      }
  
      protected Class findClass(final String className) throws ClassNotFoundException {
          // define the class
          Class clazz = super.findClass(className);
  
          // add it to our cache
          synchronized(classesByName) {
              classesByName.put(clazz.getName(), clazz);
          }
  
          return clazz;
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/classspace/ClassSpaceUtil.java
  
  Index: ClassSpaceUtil.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.kernel.classspace;
  
  import javax.management.JMException;
  import javax.management.MBeanServer;
  import javax.management.ObjectName;
  
  /**
   * Helper methods for class spaces.
   * 
   * @version $Revision: 1.1 $ $Date: 2003/10/27 20:58:38 $
   */
  public class ClassSpaceUtil {
      private ClassSpaceUtil() {
      }
  
      /**
       * Gets the class loader associated with the specified class space.
       * @param server the MBean server to search for the class space
       * @param classSpaceName name of the class space
       * @return the class loader associated with the class space
       * @throws ClassSpaceException if the class space was not found or if the class loader
is not running
       */
      public static ClassLoader getClassLoader(MBeanServer server, ObjectName classSpaceName)
throws ClassSpaceException {
          if(classSpaceName != null) {
              ClassLoader cl = null;
              try {
                  cl = (ClassLoader) server.invoke(classSpaceName, "getClassLoader", null,
null);
              } catch (JMException e) {
                  throw new ClassSpaceException("Could not get class loader from class space",
e);
              }
              if(cl == null) {
                  throw new ClassSpaceException("Class space is not in the running or stopping
state");
              }
              return cl;
          } else {
              return ClassLoader.getSystemClassLoader();
          }
      }
  
      /**
       * Sets the class loader associated with the specified class space into the thread context
class loader.
       * @param server the MBean server to search for the class space
       * @param classSpaceName name of the class space
       * @return the class loader that was set into the thread context class loader
       * @throws ClassSpaceException if the class space was not found or if the class loader
is not running
       */
      public static ClassLoader setContextClassLoader(MBeanServer server, ObjectName classSpaceName)
throws ClassSpaceException {
          ClassLoader newCL = getClassLoader(server, classSpaceName);
          Thread.currentThread().setContextClassLoader(newCL);
          return newCL;
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/classspace/DefaultClassSpace.java
  
  Index: DefaultClassSpace.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.kernel.classspace;
  
  import java.net.URL;
  import java.util.ArrayList;
  import java.util.Collections;
  import java.util.Iterator;
  import java.util.LinkedHashMap;
  import java.util.LinkedList;
  import java.util.List;
  import java.util.Map;
  import java.util.SortedSet;
  import java.util.TreeSet;
  import javax.management.ObjectName;
  
  import org.apache.geronimo.kernel.service.GeronimoMBeanContext;
  import org.apache.geronimo.kernel.service.GeronimoMBeanTarget;
  
  /**
   * This is the default implementation of ClassSpace used in Geronimo.
   *
   * @version $Revision: 1.1 $ $Date: 2003/10/27 20:58:38 $
   */
  public class DefaultClassSpace implements ClassSpace, GeronimoMBeanTarget {
      private static final SortedSet EMPTY_SORTED_SET = Collections.unmodifiableSortedSet(new
TreeSet());
  
      /**
       * Is this class space running?
       */
      private boolean running = false;
  
      /**
       * Current parent of this class space.
       * @todo remove when we have a endpoints
       */
      private ObjectName currentParent;
  
      /**
       * Parent of this class space.
       * @todo make an endpoint
       */
      private ObjectName parent;
  
      /**
       * Runtime context of the mbean in the server.
       */
      private GeronimoMBeanContext context;
  
      /**
       * Deployments currently handled by this class space.
       * This may contain more deployments then the urlsByDeployment because
       * URLs can not be removed until the class space restarts.
       */
      private LinkedHashMap currentURLsByDeployment;
  
      /**
       * Deployments that should be handled by this space.  This may
       * contain less deployments then the currentURLsByDeployment because
       * URLs can not be remove until the class space restarts
       */
      private final LinkedHashMap urlsByDeployment = new LinkedHashMap();
  
      /**
       * The class loader used by this instance
       */
      private ClassSpaceLoader classLoader;
  
      public synchronized ObjectName getParent() {
          return parent;
      }
  
      public synchronized void setParent(ObjectName parent) {
          this.parent = parent;
      }
  
      public ObjectName getCurrentParent() {
          if (running) {
              return currentParent;
          } else {
              return parent;
          }
      }
  
      public synchronized ClassLoader getClassLoader() {
          return classLoader;
      }
  
      public synchronized void addDeployment(ObjectName deployment, List urls) {
          if(urlsByDeployment.containsKey(deployment)) {
              throw new IllegalArgumentException("Deployment already exists in this class
space");
          }
  
          urlsByDeployment.put(deployment, Collections.unmodifiableList(new ArrayList(urls)));
          if (running) {
              classLoader.addURLs(urls);
              currentURLsByDeployment.put(deployment, Collections.unmodifiableList(new ArrayList(urls)));
          }
      }
  
      public synchronized void dropDeployment(ObjectName deployment) {
          urlsByDeployment.remove(deployment);
      }
  
      /**
       * Gets a list of all classes defined and loaded by this class space.
       * @return a sorted list of all loaded classes
       */
      public synchronized SortedSet getLoadedClassNames() {
          if (running) {
              return classLoader.listLoadedClassNames();
          }
          return EMPTY_SORTED_SET;
      }
  
      /**
       * Gets a map of URLs by deployment.
       * @return map of URLs by deployment
       */
      public synchronized Map getURLsByDeployment() {
          return Collections.unmodifiableMap(urlsByDeployment);
      }
  
      /**
       * Gets a map of the current URLs by deployment.
       * @return map of URLs by deployment
       */
      public synchronized Map getCurrentURLsByDeployment() {
          if (running) {
              return Collections.unmodifiableMap(currentURLsByDeployment);
          }
          return Collections.unmodifiableMap(urlsByDeployment);
      }
  
      /**
       * Gets all URLs used by this class space.
       * @return all of URLs referenced by this class space in search order
       */
      public synchronized List getURLs() {
          LinkedList urls = new LinkedList();
          for (Iterator iterator = urlsByDeployment.values().iterator(); iterator.hasNext();)
{
              urls.addAll((List) iterator.next());
          }
          return Collections.unmodifiableList(urls);
      }
  
      /**
       * Gets all URLs used by this class space.
       * @return sorted set of URLs referenced by this class space in search order
       */
      public synchronized List getCurrentURLs() {
          LinkedList urls = new LinkedList();
          if (running) {
              URL[] urlArray = classLoader.getURLs();
              for (int i = 0; i < urlArray.length; i++) {
                  urls.add(urlArray[i]);
              }
          } else {
              for (Iterator iterator = urlsByDeployment.values().iterator(); iterator.hasNext();)
{
                  urls.addAll((List) iterator.next());
              }
          }
          return Collections.unmodifiableList(urls);
      }
  
      /**
       * Loads and defines the specified class.
       * @param name name of class to load
       * @return the class
       * @throws ClassNotFoundException if the class could not be located
       */
      public synchronized Class loadClass(final String name) throws ClassNotFoundException
{
          if (!running) {
              throw new IllegalStateException("Classes may only be loaded while running or
stopping");
          }
          return classLoader.loadClass(name);
      }
  
      /**
       * Gets a URL for the specifed resource.
       * @param name name of resouce to locate
       * @return a url to the resource or null if the resouce could not be found
       */
      public synchronized URL findResource(final String name) {
          if (!running) {
              throw new IllegalStateException("Resources may only be loaded while running
or stopping");
          }
          return classLoader.findResource(name);
      }
  
      public void setMBeanContext(GeronimoMBeanContext context) {
          this.context = context;
      }
  
      public boolean canStart() {
          return true;
      }
  
      public synchronized void doStart() {
          ClassLoader parentClassLoader = null;
          if (parent != null) {
              parentClassLoader = ClassSpaceUtil.getClassLoader(context.getServer(), parent);
          } else {
              parentClassLoader = ClassLoader.getSystemClassLoader();
          }
          classLoader = new ClassSpaceLoader(parentClassLoader, context.getObjectName().toString());
          for (Iterator iterator = urlsByDeployment.values().iterator(); iterator.hasNext();)
{
              classLoader.addURLs((List) iterator.next());
          }
          currentParent = parent;
          currentURLsByDeployment = new LinkedHashMap(urlsByDeployment);
          running = true;
      }
  
      public boolean canStop() {
          return true;
      }
  
      public synchronized void doStop() {
          classLoader = null;
          currentParent = null;
          currentURLsByDeployment = null;
          running = false;
      }
  
      public synchronized void doFail() {
          classLoader = null;
          currentParent = null;
          currentURLsByDeployment = null;
          running = false;
      }
  }
  
  
  1.1                  incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/classspace/classspace-mbean.xml
  
  Index: classspace-mbean.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <mbean name="Simple" description="Simple MBean example"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="/Users/dain/work/geronimo/geronimo-head/modules/kernel/src/schema/mbean-descriptor.xsd">
  
      <target class="org.apache.geronimo.kernel.classspace.DefaultClassSpace"/>
      <attribute name="classLoader" description="Java ClassLoader for Class Space" writable="false"
/>
      <attribute name="parent" description="Parent of this Class Space"/>
      <operation name="addDeployment" impact="ACTION" description="Adds a URLs for a deployment">
          <parameter name="deployment" type="javax.management.ObjectName" description="Deployment
to add"/>
          <parameter name="urls" type="java.util.List" description="URLs to add"/>
      </operation>
      <operation name="dropDeployment" impact="ACTION" description="Drops the deployment
and associated URLs">
          <parameter name="deployment" type="javax.management.ObjectName" description="Deployment
to drop"/>
      </operation>
      <operation name="getLoadedClassNames" impact="INFO" description="Gets a list of all
classes defined and loaded by this class space"/>
      <operation name="getURLsByDeployment" impact="INFO" description="Gets a map of URLs
by deployment"/>
      <operation name="getCurrentURLsByDeployment" impact="INFO" description="Gets a map
of URLs by deployment"/>
      <operation name="getURLs" impact="INFO" description="Gets all URLs used by this class
space"/>
      <operation name="getCurrentURLs" impact="INFO" description="Gets all URLs used by
this class space"/>
      <operation name="loadClass" impact="ACTION_INFO" description="Loads and defines the
specified class">
          <parameter name="name" type="java.lang.String" description="Name of class to
load"/>
      </operation>
      <operation name="findResource" impact="ACTION_INFO" description="Gets a URL for the
specifed resource">
          <parameter name="name" type="java.lang.String" description="Name of resouce to
locate"/>
      </operation>
  </mbean>
  
  

Mime
View raw message