geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject cvs commit: incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel Kernel.java
Date Thu, 05 Feb 2004 00:41:30 GMT
adc         2004/02/04 16:41:30

  Modified:    modules/kernel/src/java/org/apache/geronimo/kernel
                        Kernel.java
  Log:
  Added constructors for times when people won't want to lookup
  the Kernel by a name.
  
  Revision  Changes    Path
  1.14      +43 -5     incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java
  
  Index: Kernel.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Kernel.java	4 Feb 2004 05:42:57 -0000	1.13
  +++ Kernel.java	5 Feb 2004 00:41:30 -0000	1.14
  @@ -73,6 +73,7 @@
   import java.io.File;
   import java.io.IOException;
   import java.io.Serializable;
  +import java.lang.ref.WeakReference;
   import java.net.URI;
   import java.net.URL;
   import java.util.Hashtable;
  @@ -88,6 +89,7 @@
   import org.apache.geronimo.kernel.config.NoSuchConfigException;
   import org.apache.geronimo.kernel.jmx.JMXUtil;
   
  +
   /**
    * The core of a Geronimo instance.
    * A Kernel is responsible for managing the Configurations that comprise a
  @@ -151,7 +153,22 @@
           this.storeInfo = storeInfo;
           this.configStore = configStore;
   
  -        kernels.put(kernelName, this);
  +        kernels.put(kernelName, new WeakReference(this));
  +    }
  +
  +    /**
  +     * Construct a Kernel using the specified JMX domain and supply the
  +     * information needed to create the ConfigurationStore.
  +     * @param domainName the domain name to be used for the JMX MBeanServer
  +     * @param storeInfo the info for the GBeanMBean to be used for the ConfigurationStore
  +     * @param configStore a local directory to be used by the ConfigurationStore;
  +     *                    this must be present and writable when the kernel is booted
  +     */
  +    public Kernel(String domainName, GBeanInfo storeInfo, File configStore) {
  +        this.kernelName = null;
  +        this.domainName = domainName;
  +        this.storeInfo = storeInfo;
  +        this.configStore = configStore;
       }
   
       /**
  @@ -164,6 +181,14 @@
       }
   
       /**
  +     * Construct a Kernel which does not have a config store.
  +     * @param domainName the domain name to be used for the JMX MBeanServer
  +     */
  +    public Kernel(String domainName) {
  +        this(domainName, null, null);
  +    }
  +
  +    /**
        * Get the MBeanServer used by this kernel
        * @return the MBeanServer used by this kernel
        */
  @@ -185,7 +210,15 @@
        * @return the kernel that was registered with that name
        */
       public static Kernel getKernel(String name) {
  -        return (Kernel) kernels.get(name);
  +        WeakReference reference = (WeakReference) kernels.get(name);
  +
  +        if (reference == null) return null;
  +
  +        Kernel result = (Kernel) reference.get();
  +        if (result == null) {
  +            kernels.remove(name);
  +        }
  +        return result;
       }
   
       /**
  @@ -200,7 +233,12 @@
           int size = kernels.size();
           if (size > 1) throw new IllegalStateException("More than one kernel has been
registered.");
           if (size < 1) return null;
  -        return (Kernel) kernels.values().iterator().next();
  +
  +        Kernel result = (Kernel) ((WeakReference) kernels.values().iterator().next()).get();
  +        if (result == null) {
  +            kernels.clear();
  +        }
  +        return result;
       }
   
       public static ObjectName getConfigObjectName(URI configID) throws MalformedObjectNameException
{
  @@ -213,7 +251,7 @@
        * @throws java.io.IOException if the CAR could not be read
        * @throws org.apache.geronimo.kernel.config.InvalidConfigException if there is a configuration
problem with the CAR
        */
  -    public void install(URL source) throws  IOException, InvalidConfigException {
  +    public void install(URL source) throws IOException, InvalidConfigException {
           if (store == null) {
               throw new UnsupportedOperationException("Kernel does not have a ConfigurationStore");
           }
  
  
  

Mime
View raw message