You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by am...@apache.org on 2005/11/16 06:41:58 UTC

svn commit: r344897 [2/2] - in /geronimo/trunk: applications/console-standard/src/java/org/apache/geronimo/console/util/ applications/console-standard/src/java/org/apache/geronimo/console/webmanager/ applications/console-standard/src/webapp/WEB-INF/vie...

Added: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/EditableConfigurationManagerImpl.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/EditableConfigurationManagerImpl.java?rev=344897&view=auto
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/EditableConfigurationManagerImpl.java (added)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/EditableConfigurationManagerImpl.java Tue Nov 15 21:41:39 2005
@@ -0,0 +1,91 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.kernel.config;
+
+import java.util.Collection;
+import java.net.URI;
+import javax.management.ObjectName;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.GBeanNotFoundException;
+import org.apache.geronimo.kernel.management.State;
+import org.apache.geronimo.gbean.GBeanData;
+import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.GBeanInfoBuilder;
+
+/**
+ * Standard implementation of an editable ConfigurationManager.
+ *
+ * @version $Rev: 46019 $ $Date: 2004-09-14 05:56:06 -0400 (Tue, 14 Sep 2004) $
+ */
+public class EditableConfigurationManagerImpl extends ConfigurationManagerImpl implements EditableConfigurationManager {
+    public EditableConfigurationManagerImpl(Kernel kernel, Collection stores, ManageableAttributeStore attributeStore,
+                                            PersistentConfigurationList configurationList) {
+        super(kernel, stores, attributeStore, configurationList);
+    }
+
+    public void addGBeanToConfiguration(URI configID, GBeanData gbean, boolean start) throws InvalidConfigException {
+        //todo: when able to, save new GBean data in attribute store rather than in serialized state
+        //that is, replace the code below with only calls to the attribute store
+        try {
+            ObjectName name = Configuration.getConfigurationObjectName(configID);
+            kernel.invoke(name, "addGBean", new Object[]{gbean, start ? Boolean.TRUE : Boolean.FALSE}, new String[]{GBeanData.class.getName(), boolean.class.getName()});
+        } catch (Exception e) {
+            throw new InvalidConfigException("Unable to add GBean to configuration", e);
+        }
+    }
+
+    public void removeGBeanFromConfiguration(URI configID, ObjectName gbean) throws GBeanNotFoundException, InvalidConfigException {
+        // Make sure the specified configuration has the specified GBean
+        try {
+            ObjectName name = Configuration.getConfigurationObjectName(configID);
+            Boolean result = (Boolean) kernel.invoke(name, "containsGBean", new Object[]{gbean}, new String[]{ObjectName.class.getName()});
+            if(!result.booleanValue()) {
+                throw new GBeanNotFoundException(gbean);
+            }
+        } catch(GBeanNotFoundException e) {
+            throw e;
+        } catch (Exception e) {
+            throw new InvalidConfigException("Unable to add GBean to configuration", e);
+        }
+
+        // Stop and unload the GBean if necessary
+        try {
+            if (kernel.getGBeanState(gbean) == State.RUNNING_INDEX) {
+                kernel.stopGBean(gbean);
+            }
+            kernel.unloadGBean(gbean);
+        } catch (GBeanNotFoundException e) {
+            // Bean is no longer loaded
+        }
+
+        // Make sure it's not loaded next time the configuration is loaded
+        attributeStore.setShouldLoad(configID.toString(), gbean, false);
+    }
+
+    public static final GBeanInfo GBEAN_INFO;
+
+    static {
+        GBeanInfoBuilder infoFactory = new GBeanInfoBuilder(EditableConfigurationManagerImpl.class, ConfigurationManagerImpl.GBEAN_INFO, "ConfigurationManager");
+        infoFactory.addInterface(EditableConfigurationManager.class);
+        infoFactory.setConstructor(new String[]{"kernel", "Stores", "AttributeStore", "PersistentConfigurationList"});
+        GBEAN_INFO = infoFactory.getBeanInfo();
+    }
+
+    public static GBeanInfo getGBeanInfo() {
+        return GBEAN_INFO;
+    }
+}

Propchange: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/EditableConfigurationManagerImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/ManageableAttributeStore.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/ManageableAttributeStore.java?rev=344897&r1=344896&r2=344897&view=diff
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/ManageableAttributeStore.java (original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/ManageableAttributeStore.java Tue Nov 15 21:41:39 2005
@@ -35,29 +35,18 @@
 
     public static final String ATTRIBUTE_STORE = "AttributeStore";
 
-    public Collection setAttributes(URI configurationName, Collection datas) throws InvalidConfigException;
-    /**
-     * Return the object name of this store
-     * @return the object name of this store
-     */
-//    public String getObjectName();
-
     /**
-     * Gets a stored value (if any) for a particular attribute.  The attribute
-     * is identified by the configuration name, GBean ObjectName, and attribute
-     * information.  Note: it is not possible to store a meaningful value of
-     * "null"; that would be treated the same as if no value was stored.
-     *
-     * @param configurationName The name of the configuration holding the GBean
-     *                          in question
-     * @param gbean The ObjectName of the GBean in question
-     * @param attribute The attribute in question
+     * Given a conifguration name and a set of GBeanDatas, apply all the saved
+     * attribute values to those GBeans before the caller attempts to load
+     * them.
      *
-     * @return An object of the correct type to populate into the attribute in
-     *         question, or null if this store has no value saved for the
-     *         specified attribute.
+     * @param configurationName The configuration in question
+     * @param datas             The initial GBeanData's for all the GBeans in
+     *                          the configuration
+     * @return                  The modified GBeanData's
+     * @throws InvalidConfigException If something bad happens
      */
-//    public Object getValue(String configurationName, ObjectName gbean, GAttributeInfo attribute);
+    public Collection setAttributes(URI configurationName, Collection datas) throws InvalidConfigException;
 
     /**
      * Sets the stored value for a particular attribute.  The attribute is
@@ -76,6 +65,18 @@
      * @param value The value to save, or null if no value should be saved
      */
     public void setValue(String configurationName, ObjectName gbean, GAttributeInfo attribute, Object value);
+
+    /**
+     * Sets whether a particular GBean should be loaded for this configuration.
+     * The GBean must already exist in the configuration, this just toggles the
+     * flag for whether to stop it from loading when the configuration is
+     * loaded.
+     *
+     * @param configurationName The configuration that the GBean belongs to
+     * @param gbean             The GBean in question
+     * @param load              True if the GBean should load with the configuration
+     */
+    public void setShouldLoad(String configurationName, ObjectName gbean, boolean load);
 
     /**
      * Saves the current values to persistent storage.  This should be called

Modified: geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java?rev=344897&r1=344896&r2=344897&view=diff
==============================================================================
--- geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java (original)
+++ geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java Tue Nov 15 21:41:39 2005
@@ -211,6 +211,30 @@
         }
     }
 
+    public synchronized void setShouldLoad(String configurationName, ObjectName gbean, boolean load) {
+        if (readOnly) {
+            return;
+        }
+        ConfigInfo config = (ConfigInfo) configurations.get(configurationName);
+        if (config == null) {
+            config = new ConfigInfo(true);
+            configurations.put(configurationName, config);
+        }
+        GBeanAttrsInfo atts = config.getGBean(gbean);
+        if (atts == null) {
+            atts = config.getGBean(gbean.getKeyProperty("name"));
+            if (atts == null) {
+                atts = new GBeanAttrsInfo(load);
+                config.addGBean(gbean, atts);
+            } else {
+                atts.setLoad(load);
+            }
+        } else {
+            atts.setLoad(load);
+        }
+        attributeChanged();
+    }
+
     public void load() throws IOException {
         ensureParentDirectory();
         if (!attributeFile.exists()) {
@@ -447,89 +471,6 @@
         };
         timer.schedule(currentTask, SAVE_BUFFER_MS);
     }
-
-
-    /**
-     * A thread that's notified on every attribute update.  5 seconds after
-     * being notified, it will save the changes to a file.
-     */
-/*
-    // todo: This code is not pleasing -- it uses lots of synchronization and still doesn't guarantee a timely shutdown.
-    private class UpdateThread extends Thread {
-        private boolean done = false;
-        private boolean pending = false;
-
-        public UpdateThread() {
-            super("Manageable-Attribute-Saver");
-            setDaemon(true);
-        }
-
-        public synchronized void setDone() {
-            this.done = true;
-        }
-
-        public synchronized boolean isDone() {
-            return done;
-        }
-
-        public void run() {
-            while (!isDone()) {
-                // Wait until at least one change has been made
-                synchronized (LocalAttributeManager.this) {
-                    if (!pending) {
-                        try {
-                            LocalAttributeManager.this.wait();
-                            pending = true;
-                        } catch (InterruptedException e) {
-                        }
-                    }
-                    if (done) {
-                        return;
-                    }
-                }
-
-                // Pause for effect (and to catch a flurry of changes)
-                // Don't synchronize this as it holds monitors while sleeping
-                try {
-                    sleep(SAVE_BUFFER_MS);
-                } catch (InterruptedException e) {
-                }
-
-                // Save
-                synchronized (LocalAttributeManager.this) {
-                    if (!isDone()) {
-                        try {
-                            save();
-                        } catch (IOException e) {
-                            log.error("Error saving attributes", e);
-                        }
-                        pending = false;
-                    }
-                }
-            }
-        }
-
-        public boolean isPending() {
-            synchronized (LocalAttributeManager.this) {
-                return pending;
-            }
-        }
-
-        public void attributeChanged() {
-            synchronized (LocalAttributeManager.this) {
-                pending = true;
-                LocalAttributeManager.this.notify();
-            }
-        }
-
-        public void shutdown() {
-            setDone();
-            synchronized (LocalAttributeManager.this) {
-                LocalAttributeManager.this.notify();
-            }
-        }
-    }
-*/
 
     private static class ConfigInfo {
         private boolean load;

Modified: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatManagerImpl.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatManagerImpl.java?rev=344897&r1=344896&r2=344897&view=diff
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatManagerImpl.java (original)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatManagerImpl.java Tue Nov 15 21:41:39 2005
@@ -21,6 +21,7 @@
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.Hashtable;
+import java.net.URISyntaxException;
 import javax.management.ObjectName;
 import javax.management.MalformedObjectNameException;
 import org.apache.geronimo.management.geronimo.WebManager;
@@ -33,6 +34,10 @@
 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
 import org.apache.geronimo.kernel.GBeanNotFoundException;
 import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.config.EditableConfigurationManager;
+import org.apache.geronimo.kernel.config.ConfigurationUtil;
+import org.apache.geronimo.kernel.config.Configuration;
+import org.apache.geronimo.kernel.config.InvalidConfigException;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -95,15 +100,25 @@
         connector.setAttribute("acceptQueueSize", new Integer(100));
         connector.setReferencePattern(ConnectorGBean.CONNECTOR_CONTAINER_REFERENCE, container);
         connector.setAttribute("name", uniqueName);
-        ObjectName config = Util.getConfiguration(kernel, container);
-        try {
-            kernel.invoke(config, "addGBean", new Object[]{connector, Boolean.FALSE}, new String[]{GBeanData.class.getName(), boolean.class.getName()});
-            kernel.invoke(config, "saveState");
-        } catch (Exception e) {
-            log.error("Unable to add GBean ", e);
+        EditableConfigurationManager mgr = ConfigurationUtil.getEditableConfigurationManager(kernel);
+        if(mgr != null) {
+            try {
+                ObjectName config = Util.getConfiguration(kernel, container);
+                mgr.addGBeanToConfiguration(Configuration.getConfigurationID(config), connector, false);
+                return name.getCanonicalName();
+            } catch (InvalidConfigException e) {
+                log.error("Unable to add GBean", e);
+                return null;
+            } catch (URISyntaxException e) {
+                log.error("Should never happen", e);
+                return null;
+            } finally {
+                ConfigurationUtil.releaseConfigurationManager(kernel, mgr);
+            }
+        } else {
+            log.warn("The ConfigurationManager in the kernel does not allow editing");
             return null;
         }
-        return name.getCanonicalName();
     }
 
     /**
@@ -153,8 +168,20 @@
                 throw new GBeanNotFoundException(name);
             }
             ObjectName config = Util.getConfiguration(kernel, name);
-            kernel.invoke(config, "removeGBean", new Object[]{name}, new String[]{ObjectName.class.getName()});
-            kernel.invoke(config, "saveState");
+            EditableConfigurationManager mgr = ConfigurationUtil.getEditableConfigurationManager(kernel);
+            if(mgr != null) {
+                try {
+                    mgr.removeGBeanFromConfiguration(Configuration.getConfigurationID(config), name);
+                } catch (InvalidConfigException e) {
+                    log.error("Unable to add GBean", e);
+                } catch (URISyntaxException e) {
+                    log.error("Should never happen", e);
+                } finally {
+                    ConfigurationUtil.releaseConfigurationManager(kernel, mgr);
+                }
+            } else {
+                log.warn("The ConfigurationManager in the kernel does not allow editing");
+            }
         } catch (GBeanNotFoundException e) {
             log.warn("No such GBean '"+objectName+"'"); //todo: what if we want to remove a failed GBean?
         } catch (Exception e) {

Modified: geronimo/trunk/plugins/geronimo-packaging-plugin/src/java/org/apache/geronimo/plugin/packaging/MavenAttributeStore.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/plugins/geronimo-packaging-plugin/src/java/org/apache/geronimo/plugin/packaging/MavenAttributeStore.java?rev=344897&r1=344896&r2=344897&view=diff
==============================================================================
--- geronimo/trunk/plugins/geronimo-packaging-plugin/src/java/org/apache/geronimo/plugin/packaging/MavenAttributeStore.java (original)
+++ geronimo/trunk/plugins/geronimo-packaging-plugin/src/java/org/apache/geronimo/plugin/packaging/MavenAttributeStore.java Tue Nov 15 21:41:39 2005
@@ -31,25 +31,17 @@
  * @version $Rev$ $Date$
  */
 public class MavenAttributeStore implements ManageableAttributeStore {
-    private final String objectName;
-
-    public MavenAttributeStore(String objectName) {
-        this.objectName = objectName;
+    public MavenAttributeStore() {
     }
 
     public Collection setAttributes(URI configurationName, Collection datas) {
         return datas;
     }
 
-    public String getObjectName() {
-        return objectName;
-    }
-
-    public Object getValue(String configurationName, ObjectName gbean, GAttributeInfo attribute) {
-        return null;
+    public void setValue(String configurationName, ObjectName gbean, GAttributeInfo attribute, Object value) {
     }
 
-    public void setValue(String configurationName, ObjectName gbean, GAttributeInfo attribute, Object value) {
+    public void setShouldLoad(String configurationName, ObjectName gbean, boolean load) {
     }
 
     public void save() throws IOException {
@@ -63,9 +55,7 @@
 
     static {
         GBeanInfoBuilder builder = new GBeanInfoBuilder(MavenAttributeStore.class);
-        builder.addAttribute("objectName", String.class, false);
         builder.addInterface(ManageableAttributeStore.class);
-        builder.setConstructor(new String[] {"objectName"});
         GBEAN_INFO = builder.getBeanInfo();
     }
 }