geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r1100682 - in /geronimo/server/branches/3.0-osgi/framework/modules: geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/ geronimo-kernel/src/main/java/org/apache/geronimo/kernel/ geronimo-kernel/src/main/java/org/apache/geronimo...
Date Sun, 08 May 2011 05:39:22 GMT
Author: djencks
Date: Sun May  8 05:39:22 2011
New Revision: 1100682

URL: http://svn.apache.org/viewvc?rev=1100682&view=rev
Log:
restore kernel DependencyManager accidently removed by Kevan's commit

Added:
    geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/DependencyManager.java
  (with props)
    geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/basic/BasicDependencyManager.java
  (with props)
Modified:
    geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/GBeanDependency.java
    geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java
    geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/GBeanInstanceState.java
    geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/Kernel.java
    geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/KernelGBean.java
    geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/basic/BasicKernel.java
    geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/gbean/runtime/GBeanAttributeTest.java
    geronimo/server/branches/3.0-osgi/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/jmx/KernelDelegate.java

Modified: geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/GBeanDependency.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/GBeanDependency.java?rev=1100682&r1=1100681&r2=1100682&view=diff
==============================================================================
--- geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/GBeanDependency.java
(original)
+++ geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/GBeanDependency.java
Sun May  8 05:39:22 2011
@@ -78,7 +78,7 @@ public final class GBeanDependency
     public synchronized boolean start() {
         if (targetRunning && !dependencyRegistered) {
             AbstractName abstractName = gbeanInstance.getAbstractName();
-//             kernel.getDependencyManager().addDependency(abstractName, targetName);
+            kernel.getDependencyManager().addDependency(abstractName, targetName);
             dependencyRegistered = true;
         }
         return targetRunning;
@@ -88,7 +88,7 @@ public final class GBeanDependency
     public synchronized void stop() {
         if (dependencyRegistered) {
             AbstractName abstractName = gbeanInstance.getAbstractName();
-//             kernel.getDependencyManager().removeDependency(abstractName, targetName);
+            kernel.getDependencyManager().removeDependency(abstractName, targetName);
             dependencyRegistered = false;
         }
     }

Modified: geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java?rev=1100682&r1=1100681&r2=1100682&view=diff
==============================================================================
--- geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java
(original)
+++ geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java
Sun May  8 05:39:22 2011
@@ -50,7 +50,7 @@ import org.apache.geronimo.gbean.GOperat
 import org.apache.geronimo.gbean.GReferenceInfo;
 import org.apache.geronimo.gbean.InvalidConfigurationException;
 import org.apache.geronimo.gbean.ReferencePatterns;
-// import org.apache.geronimo.kernel.DependencyManager;
+import org.apache.geronimo.kernel.DependencyManager;
 import org.apache.geronimo.kernel.GBeanNotFoundException;
 import org.apache.geronimo.kernel.Kernel;
 import org.apache.geronimo.kernel.NoSuchAttributeException;
@@ -232,13 +232,11 @@ public final class GBeanInstance impleme
      *          if the gbeanInfo is inconsistent with the actual java classes, such as
      *          mismatched attribute types or the intial data cannot be set
      */
-//     public GBeanInstance(GBeanData gbeanData, Kernel kernel, DependencyManager dependencyManager,
LifecycleBroadcaster lifecycleBroadcaster, Bundle bundle) throws InvalidConfigurationException
{
-    public GBeanInstance(GBeanData gbeanData, Kernel kernel, LifecycleBroadcaster lifecycleBroadcaster,
Bundle bundle) throws InvalidConfigurationException {
+     public GBeanInstance(GBeanData gbeanData, Kernel kernel, DependencyManager dependencyManager,
LifecycleBroadcaster lifecycleBroadcaster, Bundle bundle) throws InvalidConfigurationException
{
         this.abstractName = gbeanData.getAbstractName();
         this.kernel = kernel;
         this.lifecycleBroadcaster = lifecycleBroadcaster;
-//         this.gbeanInstanceState = new GBeanInstanceState(abstractName, kernel, dependencyManager,
this, lifecycleBroadcaster);
-        this.gbeanInstanceState = new GBeanInstanceState(abstractName, kernel, this, lifecycleBroadcaster);
+        this.gbeanInstanceState = new GBeanInstanceState(abstractName, kernel, dependencyManager,
this, lifecycleBroadcaster);
         this.bundle = bundle;
         this.classLoader = new BundleClassLoader(bundle);
 

Modified: geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/GBeanInstanceState.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/GBeanInstanceState.java?rev=1100682&r1=1100681&r2=1100682&view=diff
==============================================================================
--- geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/GBeanInstanceState.java
(original)
+++ geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/runtime/GBeanInstanceState.java
Sun May  8 05:39:22 2011
@@ -19,7 +19,7 @@ package org.apache.geronimo.gbean.runtim
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.geronimo.gbean.AbstractName;
-// import org.apache.geronimo.kernel.DependencyManager;
+import org.apache.geronimo.kernel.DependencyManager;
 import org.apache.geronimo.kernel.GBeanNotFoundException;
 import org.apache.geronimo.kernel.Kernel;
 import org.apache.geronimo.kernel.management.State;
@@ -54,7 +54,7 @@ public class GBeanInstanceState
     /**
      * The dependency manager
      */
-//     private final DependencyManager dependencyManager;
+    private final DependencyManager dependencyManager;
 
     /**
      * The broadcaster of lifecycle events
@@ -65,11 +65,10 @@ public class GBeanInstanceState
     // objects check if each other are in one state or another (i.e., classic A calls B while
B calls A)
     private volatile State state = State.STOPPED;
 
-//     GBeanInstanceState(AbstractName abstractName, Kernel kernel, DependencyManager dependencyManager,
GBeanInstance gbeanInstance, LifecycleBroadcaster lifecycleBroadcaster) {
-    GBeanInstanceState(AbstractName abstractName, Kernel kernel, GBeanInstance gbeanInstance,
LifecycleBroadcaster lifecycleBroadcaster) {
+     GBeanInstanceState(AbstractName abstractName, Kernel kernel, DependencyManager dependencyManager,
GBeanInstance gbeanInstance, LifecycleBroadcaster lifecycleBroadcaster) {
         this.abstractName = abstractName;
         this.kernel = kernel;
-//         this.dependencyManager = dependencyManager;
+        this.dependencyManager = dependencyManager;
         this.gbeanInstance = gbeanInstance;
         this.lifecycleBroadcaster = lifecycleBroadcaster;
     }
@@ -128,18 +127,17 @@ public class GBeanInstanceState
         start();
 
         // startRecursive all of objects that depend on me
-//         Set dependents = dependencyManager.getChildren(abstractName);
-        Set dependents = null;
-//         for (Iterator iterator = dependents.iterator(); iterator.hasNext();) {
-//             AbstractName dependent = (AbstractName) iterator.next();
-//             try {
-//                 kernel.startRecursiveGBean(dependent);
-//             } catch (GBeanNotFoundException e) {
-//                 // this is ok the gbean died before we could start it
-//             } catch (Exception e) {
-//                 // there is something wrong with this gbean... skip it
-//             }
-//         }
+        Set dependents = dependencyManager.getChildren(abstractName);
+        for (Iterator iterator = dependents.iterator(); iterator.hasNext();) {
+            AbstractName dependent = (AbstractName) iterator.next();
+            try {
+                kernel.startRecursiveGBean(dependent);
+            } catch (GBeanNotFoundException e) {
+                // this is ok the gbean died before we could start it
+            } catch (Exception e) {
+                // there is something wrong with this gbean... skip it
+            }
+        }
     }
 
     /**
@@ -175,21 +173,20 @@ public class GBeanInstanceState
         // Don't try to stop dependents from within a synchronized block... this should reduce
deadlocks
 
         // stop all of my dependent objects
-//         Set dependents = dependencyManager.getChildren(abstractName);
-        Set dependents = null;
-//         for (Iterator iterator = dependents.iterator(); iterator.hasNext();) {
-//             AbstractName child = (AbstractName) iterator.next();
-//             try {
-//                 log.trace("Checking if child is running: child={}", child);
-//                 if (kernel.getGBeanState(child) == State.RUNNING_INDEX) {
-//                     log.trace("Stopping child: child={}", child);
-//                     kernel.stopGBean(child);
-//                     log.trace("Stopped child: child={}", child);
-//                 }
-//             } catch (Exception ignore) {
-//                 // not a big deal... did my best
-//             }
-//         }
+        Set dependents = dependencyManager.getChildren(abstractName);
+        for (Iterator iterator = dependents.iterator(); iterator.hasNext();) {
+            AbstractName child = (AbstractName) iterator.next();
+            try {
+                log.trace("Checking if child is running: child={}", child);
+                if (kernel.getGBeanState(child) == State.RUNNING_INDEX) {
+                    log.trace("Stopping child: child={}", child);
+                    kernel.stopGBean(child);
+                    log.trace("Stopped child: child={}", child);
+                }
+            } catch (Exception ignore) {
+                // not a big deal... did my best
+            }
+        }
 
         attemptFullStop();
     }
@@ -243,31 +240,30 @@ public class GBeanInstanceState
             }
 
             // check if all of the gbeans we depend on are running
-//             Set parents = dependencyManager.getParents(abstractName);
-            Set parents = null;
-//             for (Iterator i = parents.iterator(); i.hasNext();) {
-//                 AbstractName parent = (AbstractName) i.next();
-//                 if (!kernel.isLoaded(parent)) {
-//                     log.trace("Cannot run because parent is not registered: parent={}",
parent);
-//                     return;
-//                 }
-//                 try {
-//                     log.trace("Checking if parent is running: parent={}", parent);
-//                     if (kernel.getGBeanState(parent) != State.RUNNING_INDEX) {
-//                         log.trace("Cannot run because parent is not running: parent={}",
parent);
-//                         return;
-//                     }
-//                     log.trace("Parent is running: parent={}", parent);
-//                 } catch (GBeanNotFoundException e) {
-//                     // depended on instance was removed bewteen the register check and
the invoke
-//                     log.trace("Cannot run because parent is not registered: parent={}",
parent);
-//                     return;
-//                 } catch (Exception e) {
-//                     // problem getting the attribute, parent has most likely failed
-//                     log.trace("Cannot run because an error occurred while checking if
parent is running: parent={}", parent);
-//                     return;
-//                 }
-//             }
+            Set parents = dependencyManager.getParents(abstractName);
+            for (Iterator i = parents.iterator(); i.hasNext();) {
+                AbstractName parent = (AbstractName) i.next();
+                if (!kernel.isLoaded(parent)) {
+                    log.trace("Cannot run because parent is not registered: parent={}", parent);
+                    return;
+                }
+                try {
+                    log.trace("Checking if parent is running: parent={}", parent);
+                    if (kernel.getGBeanState(parent) != State.RUNNING_INDEX) {
+                        log.trace("Cannot run because parent is not running: parent={}",
parent);
+                        return;
+                    }
+                    log.trace("Parent is running: parent={}", parent);
+                } catch (GBeanNotFoundException e) {
+                    // depended on instance was removed bewteen the register check and the
invoke
+                    log.trace("Cannot run because parent is not registered: parent={}", parent);
+                    return;
+                } catch (Exception e) {
+                    // problem getting the attribute, parent has most likely failed
+                    log.trace("Cannot run because an error occurred while checking if parent
is running: parent={}", parent);
+                    return;
+                }
+            }
         }
 
         try {
@@ -323,27 +319,26 @@ public class GBeanInstanceState
             }
 
             // check if all of the mbeans depending on us are stopped
-//             Set children = dependencyManager.getChildren(abstractName);
-            Set children = null;
-//             for (Iterator i = children.iterator(); i.hasNext();) {
-//                 AbstractName child = (AbstractName) i.next();
-//                 if (kernel.isLoaded(child)) {
-//                     try {
-//                         log.trace("Checking if child is stopped: child={}", child);
-//                         int state = kernel.getGBeanState(child);
-//                         if (state == State.RUNNING_INDEX) {
-//                             log.trace("Cannot stop because child is still running: child={}",
child);
-//                             return;
-//                         }
-//                     } catch (GBeanNotFoundException e) {
-//                         // depended on instance was removed between the register check
and the invoke
-//                     } catch (Exception e) {
-//                         // problem getting the attribute, depended on bean has most likely
failed
-//                         log.trace("Cannot run because an error occurred while checking
if child is stopped: child={}", child);
-//                         return;
-//                     }
-//                 }
-//             }
+            Set children = dependencyManager.getChildren(abstractName);
+            for (Iterator i = children.iterator(); i.hasNext();) {
+                AbstractName child = (AbstractName) i.next();
+                if (kernel.isLoaded(child)) {
+                    try {
+                        log.trace("Checking if child is stopped: child={}", child);
+                        int state = kernel.getGBeanState(child);
+                        if (state == State.RUNNING_INDEX) {
+                            log.trace("Cannot stop because child is still running: child={}",
child);
+                            return;
+                        }
+                    } catch (GBeanNotFoundException e) {
+                        // depended on instance was removed between the register check and
the invoke
+                    } catch (Exception e) {
+                        // problem getting the attribute, depended on bean has most likely
failed
+                        log.trace("Cannot run because an error occurred while checking if
child is stopped: child={}", child);
+                        return;
+                    }
+                }
+            }
         }
 
         // all is clear to stop... try to stop

Added: geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/DependencyManager.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/DependencyManager.java?rev=1100682&view=auto
==============================================================================
--- geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/DependencyManager.java
(added)
+++ geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/DependencyManager.java
Sun May  8 05:39:22 2011
@@ -0,0 +1,87 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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;
+
+import org.apache.geronimo.gbean.AbstractName;
+
+import java.util.Set;
+
+/**
+ * DependencyManager is the record keeper of the dependencies in Geronimo.  The DependencyManager
+ * does not enforce any dependencies, it is simply a place where components can register
their intent
+ * to be dependent on another component.
+ * <p/>
+ * The DependencyManager uses the nomenclature of parent-child where a child is dependent
on a parent.
+ * The names parent and child have no other meaning are just a convience to make the code
readable.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface DependencyManager {
+    /**
+     * Closes the dependency manager releasing all resources
+     */
+    public void close();
+
+    /**
+     * Declares a dependency from a child to a parent.
+     *
+     * @param child the dependent component
+     * @param parent the component the child is depending on
+     */
+    public void addDependency(AbstractName child, AbstractName parent);
+
+    /**
+     * Removes a dependency from a child to a parent
+     *
+     * @param child the dependnet component
+     * @param parent the component that the child wil no longer depend on
+     */
+    public void removeDependency(AbstractName child, AbstractName parent);
+
+    /**
+     * Removes all dependencies for a child
+     *
+     * @param child the component that will no longer depend on anything
+     */
+    public void removeAllDependencies(AbstractName child);
+
+    /**
+     * Adds dependencies from the child to every parent in the parents set
+     *
+     * @param child the dependent component
+     * @param parents the set of components the child is depending on
+     */
+    public void addDependencies(AbstractName child, Set parents);
+
+    /**
+     * Gets the set of parents that the child is depending on
+     *
+     * @param child the dependent component
+     * @return a collection containing all of the components the child depends on; will never
be null
+     */
+    public Set getParents(AbstractName child);
+
+    /**
+     * Gets all of the MBeans that have a dependency on the specified startParent.
+     *
+     * @param parent the component the returned childen set depend on
+     * @return a collection containing all of the components that depend on the parent; will
never be null
+     */
+    public Set getChildren(AbstractName parent);
+
+}

Propchange: geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/DependencyManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/DependencyManager.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/DependencyManager.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/Kernel.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/Kernel.java?rev=1100682&r1=1100681&r2=1100682&view=diff
==============================================================================
--- geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/Kernel.java
(original)
+++ geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/Kernel.java
Sun May  8 05:39:22 2011
@@ -58,7 +58,7 @@ public interface Kernel {
      * Gets the dependency manager kernel service
      * @return the dependency manager or null if the kernel is not running
      */
-//     DependencyManager getDependencyManager();
+     DependencyManager getDependencyManager();
 
     /**
      * Gets the lifecycle monitor kernel service

Modified: geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/KernelGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/KernelGBean.java?rev=1100682&r1=1100681&r2=1100682&view=diff
==============================================================================
--- geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/KernelGBean.java
(original)
+++ geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/KernelGBean.java
Sun May  8 05:39:22 2011
@@ -48,9 +48,9 @@ public class KernelGBean implements Kern
         return kernel.getNaming();
     }
 
-//     public DependencyManager getDependencyManager() {
-//         return kernel.getDependencyManager();
-//     }
+    public DependencyManager getDependencyManager() {
+        return kernel.getDependencyManager();
+    }
 
     public LifecycleMonitor getLifecycleMonitor() {
         return kernel.getLifecycleMonitor();

Added: geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/basic/BasicDependencyManager.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/basic/BasicDependencyManager.java?rev=1100682&view=auto
==============================================================================
--- geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/basic/BasicDependencyManager.java
(added)
+++ geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/basic/BasicDependencyManager.java
Sun May  8 05:39:22 2011
@@ -0,0 +1,204 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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.basic;
+
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.AbstractNameQuery;
+import org.apache.geronimo.kernel.DependencyManager;
+import org.apache.geronimo.kernel.lifecycle.LifecycleAdapter;
+import org.apache.geronimo.kernel.lifecycle.LifecycleListener;
+import org.apache.geronimo.kernel.lifecycle.LifecycleMonitor;
+
+import javax.management.ObjectName;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * DependencyManager is the record keeper of the dependencies in Geronimo.  The DependencyManager
+ * does not enforce any dependencies, it is simply a place where components can register
their intent
+ * to be dependent on another component.  Since a JMX Component can pretty much do whatever
it wants
+ * a component must watch the components it depends on to assure that they are following
the
+ * J2EE-Management state machine.
+ * <p/>
+ * The DependencyManager uses the nomenclature of parent-child where a child is dependent
on a parent.
+ * The names parent and child have no other meaning are just a convience to make the code
readable.
+ *
+ * @version $Rev$ $Date$
+ */
+public class BasicDependencyManager implements DependencyManager {
+    /**
+     * The lifecycleMonitor informs us when gbeans go off line,
+     * so we can clean up the lingering dependencies.
+     */
+    private final LifecycleMonitor lifecycleMonitor;
+
+    /**
+     * Listenes for GBeans to unregister and removes all dependencies associated with the
dependency
+     */
+    private final LifecycleListener lifecycleListener = new DependencyManagerLifecycleListener();
+
+    /**
+     * A map from child names to a list of parents.
+     */
+    private final Map childToParentMap = new HashMap();
+
+    /**
+     * A map from parent back to a list of its children.
+     */
+    private final Map parentToChildMap = new HashMap();
+
+    public BasicDependencyManager(LifecycleMonitor lifecycleMonitor) {
+        assert lifecycleMonitor != null;
+        this.lifecycleMonitor = lifecycleMonitor;
+        lifecycleMonitor.addLifecycleListener(lifecycleListener, new AbstractNameQuery(null,
Collections.EMPTY_MAP, Collections.EMPTY_SET));
+    }
+
+    public synchronized void close() {
+        lifecycleMonitor.removeLifecycleListener(lifecycleListener);
+        childToParentMap.clear();
+        parentToChildMap.clear();
+    }
+
+    /**
+     * Declares a dependency from a child to a parent.
+     *
+     * @param child the dependent component
+     * @param parent the component the child is depending on
+     */
+    public synchronized void addDependency(AbstractName child, AbstractName parent) {
+        Set parents = (Set) childToParentMap.get(child);
+        if (parents == null) {
+            parents = new HashSet();
+            childToParentMap.put(child, parents);
+        }
+        parents.add(parent);
+
+        Set children = (Set) parentToChildMap.get(parent);
+        if (children == null) {
+            children = new HashSet();
+            parentToChildMap.put(parent, children);
+        }
+        children.add(child);
+    }
+
+    /**
+     * Removes a dependency from a child to a parent
+     *
+     * @param child the dependnet component
+     * @param parent the component that the child wil no longer depend on
+     */
+    public synchronized void removeDependency(AbstractName child, AbstractName parent) {
+        Set parents = (Set) childToParentMap.get(child);
+        if (parents != null) {
+            parents.remove(parent);
+        }
+
+        Set children = (Set) parentToChildMap.get(parent);
+        if (children != null) {
+            children.remove(child);
+        }
+    }
+
+    /**
+     * Removes all dependencies for a child
+     *
+     * @param child the component that will no longer depend on anything
+     */
+    public synchronized void removeAllDependencies(AbstractName child) {
+        Set parents = (Set) childToParentMap.remove(child);
+        if (parents == null) {
+            return;
+        }
+        for (Iterator iterator = parents.iterator(); iterator.hasNext();) {
+            ObjectName parent = (ObjectName) iterator.next();
+            Set children = (Set) parentToChildMap.get(parent);
+            if (children != null) {
+                children.remove(child);
+            }
+
+        }
+    }
+
+    /**
+     * Adds dependencies from the child to every parent in the parents set
+     *
+     * @param child the dependent component
+     * @param parents the set of components the child is depending on
+     */
+    public synchronized void addDependencies(AbstractName child, Set parents) {
+        Set existingParents = (Set) childToParentMap.get(child);
+        if (existingParents == null) {
+            existingParents = new HashSet(parents);
+            childToParentMap.put(child, existingParents);
+        } else {
+            existingParents.addAll(parents);
+        }
+
+        for (Iterator i = parents.iterator(); i.hasNext();) {
+            Object startParent = i.next();
+            Set children = (Set) parentToChildMap.get(startParent);
+            if (children == null) {
+                children = new HashSet();
+                parentToChildMap.put(startParent, children);
+            }
+            children.add(child);
+        }
+    }
+
+    /**
+     * Gets the set of parents that the child is depending on
+     *
+     * @param child the dependent component
+     * @return a collection containing all of the components the child depends on; will never
be null
+     */
+    public synchronized Set getParents(AbstractName child) {
+        Set parents = (Set) childToParentMap.get(child);
+        if (parents == null) {
+            return Collections.EMPTY_SET;
+        }
+        return new HashSet(parents);
+    }
+
+    /**
+     * Gets all of the MBeans that have a dependency on the specified startParent.
+     *
+     * @param parent the component the returned childen set depend on
+     * @return a collection containing all of the components that depend on the parent; will
never be null
+     */
+    public synchronized Set getChildren(AbstractName parent) {
+        Set children = (Set) parentToChildMap.get(parent);
+        if (children == null) {
+            return Collections.EMPTY_SET;
+        }
+        return new HashSet(children);
+    }
+
+
+    private class DependencyManagerLifecycleListener extends LifecycleAdapter {
+        public void unloaded(AbstractName abstractName) {
+            synchronized (BasicDependencyManager.this) {
+                removeAllDependencies(abstractName);
+            }
+
+        }
+    }
+}

Propchange: geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/basic/BasicDependencyManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/basic/BasicDependencyManager.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/basic/BasicDependencyManager.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/basic/BasicKernel.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/basic/BasicKernel.java?rev=1100682&r1=1100681&r2=1100682&view=diff
==============================================================================
--- geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/basic/BasicKernel.java
(original)
+++ geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/basic/BasicKernel.java
Sun May  8 05:39:22 2011
@@ -36,7 +36,7 @@ import org.apache.geronimo.gbean.Abstrac
 import org.apache.geronimo.gbean.AbstractName;
 import org.apache.geronimo.gbean.runtime.GBeanInstance;
 import org.apache.geronimo.gbean.runtime.LifecycleBroadcaster;
-// import org.apache.geronimo.kernel.DependencyManager;
+import org.apache.geronimo.kernel.DependencyManager;
 import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
 import org.apache.geronimo.kernel.GBeanNotFoundException;
 import org.apache.geronimo.kernel.InternalKernelException;
@@ -125,7 +125,7 @@ public class
     /**
      * This manager is used by the kernel to manage dependencies between gbeans
      */
-//     private DependencyManager dependencyManager = new BasicDependencyManager(publicLifecycleMonitor);
+     private DependencyManager dependencyManager = new BasicDependencyManager(publicLifecycleMonitor);
 
     /**
      * This factory gbean proxies, and tracks all proxies in the system
@@ -184,8 +184,8 @@ public class
 
         registry.stop();
 
-//         dependencyManager.close();
-//         dependencyManager = null;
+         dependencyManager.close();
+         dependencyManager = null;
 
         synchronized (this) {
             notify();
@@ -208,9 +208,9 @@ public class
     /**
      * @deprecated this will be removed as when we add generalized dependencies to gbeans...
the only current user is Configuration
      */
-//     public DependencyManager getDependencyManager() {
-//         return dependencyManager;
-//     }
+     public DependencyManager getDependencyManager() {
+         return dependencyManager;
+     }
 
     /**
      * Gets the lifecycle monitor.
@@ -419,8 +419,7 @@ public class
         AbstractName abstractName = gbeanData.getAbstractName();
         Set interfaces = gbeanData.getGBeanInfo().getInterfaces();
         LifecycleBroadcaster lifecycleBroadcaster = lifecycleMonitor.createLifecycleBroadcaster(abstractName,
interfaces);
-//         GBeanInstance gbeanInstance = new GBeanInstance(gbeanData, this, dependencyManager,
lifecycleBroadcaster, bundle);
-        GBeanInstance gbeanInstance = new GBeanInstance(gbeanData, this, lifecycleBroadcaster,
bundle);
+        GBeanInstance gbeanInstance = new GBeanInstance(gbeanData, this, dependencyManager,
lifecycleBroadcaster, bundle);
         registry.register(gbeanInstance);
         lifecycleBroadcaster.fireLoadedEvent();
     }

Modified: geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/gbean/runtime/GBeanAttributeTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/gbean/runtime/GBeanAttributeTest.java?rev=1100682&r1=1100681&r2=1100682&view=diff
==============================================================================
--- geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/gbean/runtime/GBeanAttributeTest.java
(original)
+++ geronimo/server/branches/3.0-osgi/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/gbean/runtime/GBeanAttributeTest.java
Sun May  8 05:39:22 2011
@@ -341,7 +341,7 @@ public class GBeanAttributeTest extends 
         AbstractName name = kernel.getNaming().createRootName(new Artifact("test", "foo",
"1", "car"), "test", "test");
         gbeanInstance = new GBeanInstance(new GBeanData(name, MockGBean.getGBeanInfo()),
                 kernel,
-//                 kernel.getDependencyManager(),
+                kernel.getDependencyManager(),
                 new MyLifecycleBroadcaster(),
                 bundleContext.getBundle());
 

Modified: geronimo/server/branches/3.0-osgi/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/jmx/KernelDelegate.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0-osgi/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/jmx/KernelDelegate.java?rev=1100682&r1=1100681&r2=1100682&view=diff
==============================================================================
--- geronimo/server/branches/3.0-osgi/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/jmx/KernelDelegate.java
(original)
+++ geronimo/server/branches/3.0-osgi/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/jmx/KernelDelegate.java
Sun May  8 05:39:22 2011
@@ -30,7 +30,7 @@ import org.apache.geronimo.gbean.GBeanDa
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.AbstractName;
 import org.apache.geronimo.gbean.AbstractNameQuery;
-// import org.apache.geronimo.kernel.DependencyManager;
+import org.apache.geronimo.kernel.DependencyManager;
 import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
 import org.apache.geronimo.kernel.GBeanNotFoundException;
 import org.apache.geronimo.kernel.InternalKernelException;
@@ -864,9 +864,9 @@ public class KernelDelegate implements K
     /**
      * Throws UnsupportedOperationException.  The dependency manager is not accesable over
a remote connection.
      */
-//     public DependencyManager getDependencyManager() {
-//         throw new UnsupportedOperationException("Dependency manager is not accessable
by way of a remote connection");
-//     }
+     public DependencyManager getDependencyManager() {
+         throw new UnsupportedOperationException("Dependency manager is not accessable by
way of a remote connection");
+     }
 
     /**
      * Throws UnsupportedOperationException.  The lifecycle monitor is not accesable over
a remote connection.



Mime
View raw message