jboynes     2004/02/12 10:22:55

  Modified:    modules/kernel/src/java/org/apache/geronimo/kernel
                        Kernel.java KernelMBean.java
  Log:
  Expose more method over JMX allowing kernel to be used as a reference
  Referencing requires NotificationBroadcaster - use API supplied implementation
  Add ability to see if a config is loaded and to load parent configs
  
  Revision  Changes    Path
  1.17      +57 -86    
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.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- Kernel.java       8 Feb 2004 21:53:20 -0000       1.16
  +++ Kernel.java       12 Feb 2004 18:22:55 -0000      1.17
  @@ -55,6 +55,17 @@
    */
   package org.apache.geronimo.kernel;
   
  +import java.io.File;
  +import java.io.IOException;
  +import java.io.Serializable;
  +import java.lang.ref.ReferenceQueue;
  +import java.lang.ref.WeakReference;
  +import java.net.URI;
  +import java.net.URL;
  +import java.util.Hashtable;
  +import java.util.LinkedList;
  +import java.util.List;
  +import java.util.Map;
   import javax.management.InstanceAlreadyExistsException;
   import javax.management.InstanceNotFoundException;
   import javax.management.ListenerNotFoundException;
  @@ -70,15 +81,7 @@
   import javax.management.NotificationListener;
   import javax.management.ObjectName;
   import javax.management.ReflectionException;
  -import java.io.File;
  -import java.io.IOException;
  -import java.io.Serializable;
  -import java.lang.ref.ReferenceQueue;
  -import java.lang.ref.WeakReference;
  -import java.net.URI;
  -import java.net.URL;
  -import java.util.Hashtable;
  -import java.util.Map;
  +import javax.management.NotificationBroadcasterSupport;
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  @@ -110,7 +113,7 @@
    *
    * @version $Revision$ $Date$
    */
  -public class Kernel implements Serializable, KernelMBean, 
NotificationBroadcaster {
  +public class Kernel extends NotificationBroadcasterSupport implements 
Serializable, KernelMBean{
   
       /**
        * The JMX name used by a Kernel to register itself when it boots.
  @@ -141,6 +144,16 @@
       private transient ConfigurationStore store;
   
       /**
  +     * No-arg constructor allowing this class to be used as a GBean 
reference.
  +     */
  +    public Kernel() {
  +        kernelName = null;
  +        domainName = null;
  +        storeInfo = null;
  +        configStore = null;
  +    }
  +
  +    /**
        * Construct a Kernel using the specified JMX domain and supply the
        * information needed to create the ConfigurationStore.
        * @param kernelName the name of the kernel that uniquely indentifies 
the kernel in a VM
  @@ -188,18 +201,10 @@
           this(domainName, null, null);
       }
   
  -    /**
  -     * Get the MBeanServer used by this kernel
  -     * @return the MBeanServer used by this kernel
  -     */
       public MBeanServer getMBeanServer() {
           return mbServer;
       }
   
  -    /**
  -     * Get the name of this kernel
  -     * @return the name of this kernel
  -     */
       public String getKernelName() {
           return kernelName;
       }
  @@ -251,12 +256,6 @@
           return new ObjectName("geronimo.config:name=" + 
ObjectName.quote(configID.toString()));
       }
   
  -    /**
  -     * Install the CAR at the supplied URL into this kernel's store
  -     * @param source the URL of a CAR format archive
  -     * @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 {
           if (store == null) {
               throw new UnsupportedOperationException("Kernel does not have a 
ConfigurationStore");
  @@ -264,15 +263,26 @@
           store.install(source);
       }
   
  -    /**
  -     * Load the specified Configuration from the store into this Kernel
  -     * @param configID the unique id of the Configuration to load
  -     * @return the JMX ObjectName the Kernel registered the Configuration 
under
  -     * @throws org.apache.geronimo.kernel.config.NoSuchConfigException if 
the store does not contain the specified Configuratoin
  -     * @throws java.io.IOException if the Configuration could not be read 
from the store
  -     * @throws org.apache.geronimo.kernel.config.InvalidConfigException if 
the Configuration is not valid
  -     * @throws java.lang.UnsupportedOperationException if this kernel does 
not have a store
  -     */
  +    public List loadRecursive(URI configID) throws NoSuchConfigException, 
IOException, InvalidConfigException {
  +        try {
  +            LinkedList ancestors = new LinkedList();
  +            while (configID != null && !isLoaded(configID)) {
  +                ObjectName name = load(configID);
  +                ancestors.addFirst(name);
  +                configID = (URI) mbServer.getAttribute(name, "ParentID");
  +            }
  +            return ancestors;
  +        } catch (NoSuchConfigException e) {
  +            throw e;
  +        } catch (IOException e) {
  +            throw e;
  +        } catch (InvalidConfigException e) {
  +            throw e;
  +        } catch (Exception e) {
  +            throw new InvalidConfigException(e);
  +        }
  +    }
  +
       public ObjectName load(URI configID) throws NoSuchConfigException, 
IOException, InvalidConfigException {
           if (!running) {
               throw new IllegalStateException("Kernel is not running");
  @@ -286,13 +296,6 @@
           return load(config, baseURL);
       }
   
  -    /**
  -     * Load the supplied Configuration into the Kernel and define its root 
using the specified URL.
  -     * @param config the GBeanMBean representing the Configuration
  -     * @param rootURL the URL to be used to resolve relative paths in the 
configuration
  -     * @return the JMX ObjectName the Kernel registered the Configuration 
under
  -     * @throws org.apache.geronimo.kernel.config.InvalidConfigException if 
the Configuration is not valid
  -     */
       public ObjectName load(GBeanMBean config, URL rootURL) throws 
InvalidConfigException {
           URI configID;
           try {
  @@ -343,11 +346,15 @@
           log.info("Loaded Configuration " + configName);
       }
   
  -    /**
  -     * Unload the specified Configuration from the Kernel
  -     * @param configName the JMX name of the Configuration that should be 
unloaded
  -     * @throws org.apache.geronimo.kernel.config.NoSuchConfigException if 
the specified Configuration is not loaded
  -     */
  +    public boolean isLoaded(URI configID) {
  +        try {
  +            ObjectName name = getConfigObjectName(configID);
  +            return mbServer.isRegistered(name);
  +        } catch (MalformedObjectNameException e) {
  +            return false;
  +        }
  +    }
  +
       public void unload(ObjectName configName) throws NoSuchConfigException {
           if (!running) {
               throw new IllegalStateException("Kernel is not running");
  @@ -362,14 +369,6 @@
           log.info("Unloaded Configuration " + configName);
       }
   
  -    /**
  -     * Load a specific GBean into this kernel.
  -     * This is intended for applications that are embedding the kernel.
  -     * @param name the name to register the GBean under
  -     * @param gbean the GBean to register
  -     * @throws InstanceAlreadyExistsException if the name is already used
  -     * @throws InvalidConfigException if there is a problem during 
registration
  -     */
       public void loadGBean(ObjectName name, GBeanMBean gbean) throws 
InstanceAlreadyExistsException, InvalidConfigException {
           try {
               mbServer.registerMBean(gbean, name);
  @@ -380,43 +379,32 @@
           }
       }
   
  -    /**
  -     * Start a specific GBean.
  -     * @param name the GBean to start
  -     * @throws InstanceNotFoundException if the GBean could not be found
  -     */
       public void startGBean(ObjectName name) throws 
InstanceNotFoundException, InvalidConfigException {
           try {
               mbServer.invoke(name, "start", null, null);
           } catch (MBeanException e) {
               // start is not supposed to throw anything
  +            // todo it can now throw Exception and we should let that through
               throw new InvalidConfigException("Invalid GBean configuration 
for " + name, e);
           } catch (ReflectionException e) {
  +            // @todo this is a bad exception - we should dig the cause out 
of the RE.ITE
               throw new InvalidConfigException("Invalid GBean configuration 
for " + name, e);
           }
       }
   
  -    /**
  -     * Start a specific GBean and its children.
  -     * @param name the GBean to start
  -     * @throws InstanceNotFoundException if the GBean could not be found
  -     */
       public void startRecursiveGBean(ObjectName name) throws 
InstanceNotFoundException, InvalidConfigException {
           try {
               mbServer.invoke(name, "startRecursive", null, null);
           } catch (MBeanException e) {
               // start is not supposed to throw anything
  +            // todo it can now throw Exception and we should let that through
               throw new InvalidConfigException("Invalid GBean configuration 
for " + name, e);
           } catch (ReflectionException e) {
  +            // @todo this is a bad exception - we should dig the cause out 
of the RE.ITE
               throw new InvalidConfigException("Invalid GBean configuration 
for " + name, e);
           }
       }
   
  -    /**
  -     * Stop a specific GBean.
  -     * @param name the GBean to stop
  -     * @throws InstanceNotFoundException if the GBean could not be found
  -     */
       public void stopGBean(ObjectName name) throws InstanceNotFoundException, 
InvalidConfigException {
           try {
               mbServer.invoke(name, "stop", null, null);
  @@ -428,12 +416,6 @@
           }
       }
   
  -    /**
  -     * Unload a specific GBean.
  -     * This is intended for applications that are embedding the kernel.
  -     * @param name the name of the GBean to unregister
  -     * @throws InstanceNotFoundException if the GBean could not be found
  -     */
       public void unloadGBean(ObjectName name) throws 
InstanceNotFoundException {
           try {
               mbServer.unregisterMBean(name);
  @@ -529,17 +511,6 @@
   
       public boolean isRunning() {
           return running;
  -    }
  -
  -    //NotificationBroadcaster support so Kernel can be an endpoint.
  -    public MBeanNotificationInfo[] getNotificationInfo() {
  -        return new MBeanNotificationInfo[0];
  -    }
  -
  -    public void addNotificationListener(NotificationListener listener, 
NotificationFilter filter, Object handback) throws IllegalArgumentException {
  -    }
  -
  -    public void removeNotificationListener(NotificationListener listener) 
throws ListenerNotFoundException {
       }
   
       private static void processQueue() {
  
  
  
  1.4       +110 -10   
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/KernelMBean.java
  
  Index: KernelMBean.java
  ===================================================================
  RCS file: 
/home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/KernelMBean.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- KernelMBean.java  4 Feb 2004 05:42:57 -0000       1.3
  +++ KernelMBean.java  12 Feb 2004 18:22:55 -0000      1.4
  @@ -58,12 +58,16 @@
   import java.io.IOException;
   import java.net.URI;
   import java.net.URL;
  +import java.util.List;
  +import javax.management.InstanceAlreadyExistsException;
  +import javax.management.InstanceNotFoundException;
   import javax.management.MBeanServer;
   import javax.management.ObjectName;
  +import javax.management.NotificationBroadcaster;
   
  +import org.apache.geronimo.gbean.jmx.GBeanMBean;
   import org.apache.geronimo.kernel.config.InvalidConfigException;
   import org.apache.geronimo.kernel.config.NoSuchConfigException;
  -import org.apache.geronimo.gbean.jmx.GBeanMBean;
   
   /**
    *
  @@ -71,13 +75,109 @@
    * @version $Revision$ $Date$
    */
   public interface KernelMBean {
  -    public MBeanServer getMBeanServer();
  -
  -    public String getKernelName();
  -
  -    public ObjectName load(GBeanMBean config, URL baseURL) throws 
InvalidConfigException;
  -
  -    public void unload(ObjectName configName) throws NoSuchConfigException;
  +    /**
  +     * Get the MBeanServer used by this kernel
  +     * @return the MBeanServer used by this kernel
  +     */
  +    MBeanServer getMBeanServer();
  +
  +    /**
  +     * Get the name of this kernel
  +     * @return the name of this kernel
  +     */
  +    String getKernelName();
  +
  +    /**
  +     * Load the specified configuration and all of its parents.
  +     * Stops at the root or when a previously loaded configuration is found.
  +     * @param configID the configuration to load
  +     * @return a List<ObjectName> of configurations that were actually 
loaded; an empty List if none were
  +     * @throws NoSuchConfigException if the store does not contain the 
specified Configuration
  +     * @throws IOException if the Configuration could not be read from the 
store
  +     * @throws InvalidConfigException if the Configuration is not valid
  +     */
  +    List loadRecursive(URI configID) throws NoSuchConfigException, 
IOException, InvalidConfigException;
  +
  +    /**
  +     * Load the specified Configuration from the store into this Kernel
  +     * @param configID the unique id of the Configuration to load
  +     * @return the JMX ObjectName the Kernel registered the Configuration 
under
  +     * @throws NoSuchConfigException if the store does not contain the 
specified Configuration
  +     * @throws IOException if the Configuration could not be read from the 
store
  +     * @throws InvalidConfigException if the Configuration is not valid
  +     * @throws UnsupportedOperationException if this kernel does not have a 
store
  +     */
  +    ObjectName load(URI configID) throws NoSuchConfigException, IOException, 
InvalidConfigException;
  +
  +    /**
  +     * Determine if the given configuration is loaded.
  +     * @param configID
  +     * @return true if the configuration is loaded
  +     */
  +    boolean isLoaded(URI configID);
  +
  +    /**
  +     * Unload the specified Configuration from the Kernel
  +     * @param configName the JMX name of the Configuration that should be 
unloaded
  +     * @throws NoSuchConfigException if the specified Configuration is not 
loaded
  +     */
  +    void unload(ObjectName configName) throws NoSuchConfigException;
  +
  +    /**
  +     * Load a specific GBean into this kernel.
  +     * This is intended for applications that are embedding the kernel.
  +     * @param name the name to register the GBean under
  +     * @param gbean the GBean to register
  +     * @throws InstanceAlreadyExistsException if the name is already used
  +     * @throws org.apache.geronimo.kernel.config.InvalidConfigException if 
there is a problem during registration
  +     */
  +    void loadGBean(ObjectName name, GBeanMBean gbean) throws 
InstanceAlreadyExistsException, InvalidConfigException;
  +
  +    /**
  +     * Start a specific GBean.
  +     * @param name the GBean to start
  +     * @throws InstanceNotFoundException if the GBean could not be found
  +     */
  +    void startGBean(ObjectName name) throws InstanceNotFoundException, 
InvalidConfigException;
  +
  +    /**
  +     * Start a specific GBean and its children.
  +     * @param name the GBean to start
  +     * @throws javax.management.InstanceNotFoundException if the GBean could 
not be found
  +     */
  +    void startRecursiveGBean(ObjectName name) throws 
InstanceNotFoundException, InvalidConfigException;
  +
  +    /**
  +     * Stop a specific GBean.
  +     * @param name the GBean to stop
  +     * @throws javax.management.InstanceNotFoundException if the GBean could 
not be found
  +     */
  +    void stopGBean(ObjectName name) throws InstanceNotFoundException, 
InvalidConfigException;
  +
  +    /**
  +     * Unload a specific GBean.
  +     * This is intended for applications that are embedding the kernel.
  +     * @param name the name of the GBean to unregister
  +     * @throws javax.management.InstanceNotFoundException if the GBean could 
not be found
  +     */
  +    void unloadGBean(ObjectName name) throws InstanceNotFoundException;
  +
  +    /**
  +     * Load the supplied Configuration into the Kernel and define its root 
using the specified URL.
  +     * @param config the GBeanMBean representing the Configuration
  +     * @param rootURL the URL to be used to resolve relative paths in the 
configuration
  +     * @return the JMX ObjectName the Kernel registered the Configuration 
under
  +     * @throws InvalidConfigException if the Configuration is not valid
  +     */
  +    ObjectName load(GBeanMBean config, URL rootURL) throws 
InvalidConfigException;
  +
  +    /**
  +     * Install the CAR at the supplied URL into this kernel's store
  +     * @param source the URL of a CAR format archive
  +     * @throws IOException if the CAR could not be read
  +     * @throws InvalidConfigException if there is a configuration problem 
with the CAR
  +     */
  +    void install(URL source) throws IOException, InvalidConfigException;
   
  -    public ObjectName load(URI configID) throws IOException, 
NoSuchConfigException, InvalidConfigException;
  +    boolean isRunning();
   }
  
  
  

Reply via email to