Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 42953 invoked from network); 8 May 2005 19:36:04 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 8 May 2005 19:36:04 -0000 Received: (qmail 73851 invoked by uid 500); 8 May 2005 19:39:03 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 73735 invoked by uid 500); 8 May 2005 19:39:03 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 73676 invoked by uid 99); 8 May 2005 19:39:00 -0000 X-ASF-Spam-Status: No, hits=0.2 required=10.0 tests=NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Sun, 08 May 2005 12:38:57 -0700 Received: (qmail 42930 invoked by uid 65534); 8 May 2005 19:35:55 -0000 Message-ID: <20050508193555.42928.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: svn commit: r169154 [3/6] - in /geronimo/trunk: applications/jmxdebug/src/java/org/apache/geronimo/jmxdebug/web/beanlib/ applications/jmxdebug/src/webapp/WEB-INF/ assemblies/j2ee-server/ etc/ modules/assembly/ modules/assembly/src/plan/ modules/axis-builder/ modules/axis/ modules/classloader-server/ modules/classloader-server/src/test/org/apache/geronimo/classloaderserver/http/ modules/client-builder/ modules/client-builder/src/java/org/apache/geronimo/client/builder/ modules/client-builder/src/test/org/apache/geronimo/client/builder/ modules/client/ modules/connector-builder/ modules/connector-builder/src/java/org/apache/geronimo/connector/deployment/ modules/connector-builder/src/test/org/apache/geronimo/connector/deployment/ modules/connector/ modules/connector/src/java/org/apache/geronimo/connector/ modules/connector/src/java/org/apache/geronimo/connector/outbound/ modules/connector/src/test/org/apache/geronimo/connector/ modules/connector/src/test/org/apache/geronimo/connector/outbound/ modules/deploy-tool/src/java/org/apache/geronimo/deployment/ modules/deploy-tool/src/java/org/apache/geronimo/deployment/plugin/jmx/ modules/deploy-tool/src/java/org/apache/geronimo/deployment/plugin/local/ modules/deployment/ modules/deployment/src/java/org/apache/geronimo/deployment/ modules/deployment/src/java/org/apache/geronimo/deployment/util/ modules/interop/ modules/interop/src/test/org/apache/geronimo/interop/ modules/j2ee-builder/ modules/j2ee-builder/src/java/org/apache/geronimo/j2ee/deployment/ modules/j2ee-builder/src/test/org/apache/geronimo/j2ee/deployment/ modules/j2ee/ modules/j2ee/src/java/org/apache/geronimo/j2ee/management/impl/ modules/j2ee/src/test/org/apache/geronimo/j2ee/management/ modules/jetty-builder/ modules/jetty-builder/src/java/org/apache/geronimo/jetty/deployment/ modules/jetty-builder/src/test/org/apache/geronimo/jetty/deployment/ modules/jetty/ modules/jetty/src/test/org/apache/geronimo/jetty/ modules/jmx-remoting/src/java/org/apache/geronimo/jmxremoting/ modules/kernel/ modules/kernel/src/java/org/apache/geronimo/gbean/jmx/ modules/kernel/src/java/org/apache/geronimo/gbean/runtime/ modules/kernel/src/java/org/apache/geronimo/kernel/ modules/kernel/src/java/org/apache/geronimo/kernel/basic/ modules/kernel/src/java/org/apache/geronimo/kernel/config/ modules/kernel/src/java/org/apache/geronimo/kernel/jmx/ modules/kernel/src/java/org/apache/geronimo/kernel/lifecycle/ modules/kernel/src/java/org/apache/geronimo/kernel/proxy/ modules/kernel/src/java/org/apache/geronimo/kernel/registry/ modules/kernel/src/test/org/apache/geronimo/gbean/ modules/kernel/src/test/org/apache/geronimo/gbean/runtime/ modules/kernel/src/test/org/apache/geronimo/kernel/ modules/mail/ modules/mail/src/java/org/apache/geronimo/mail/ modules/mail/src/test/org/apache/geronimo/mail/ modules/naming/src/java/org/apache/geronimo/naming/reference/ modules/naming/src/test/org/apache/geronimo/naming/java/ modules/security/ modules/security/src/java/org/apache/geronimo/security/jaas/ modules/security/src/java/org/apache/geronimo/security/realm/ modules/security/src/java/org/apache/geronimo/security/realm/providers/ modules/security/src/test/org/apache/geronimo/security/ modules/security/src/test/org/apache/geronimo/security/jaas/ modules/security/src/test/org/apache/geronimo/security/remoting/jmx/ modules/service-builder/ modules/service-builder/src/java/org/apache/geronimo/deployment/service/ modules/spring-builder/ modules/spring-builder/src/java/org/apache/geronimo/spring/deployment/ modules/spring/ modules/spring/src/java/org/apache/geronimo/spring/ modules/system/ modules/system/src/java/org/apache/geronimo/system/configuration/ modules/system/src/java/org/apache/geronimo/system/jmx/ modules/system/src/java/org/apache/geronimo/system/main/ modules/system/src/test/org/apache/geronimo/system/configuration/ modules/test-ddbean/src/java/org/apache/geronimo/deployment/tools/ modules/tomcat-builder/ modules/tomcat-builder/src/java/org/apache/geronimo/tomcat/deployment/ modules/tomcat-builder/src/test/org/apache/geronimo/tomcat/deployment/ modules/tomcat/ modules/tomcat/src/plan/ modules/tomcat/src/test/org/apache/geronimo/tomcat/ modules/webservices/ plugins/geronimo-packaging-plugin/ plugins/geronimo-packaging-plugin/src/java/org/apache/geronimo/plugin/packaging/ plugins/maven-geronimo-plugin/ plugins/maven-geronimo-plugin/src/java/org/apache/geronimo/deployment/mavenplugin/ Date: Sun, 08 May 2005 19:35:28 -0000 To: scm@geronimo.apache.org From: dain@apache.org X-Mailer: svnmailer-1.0.0-dev X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/= runtime/GBeanInstanceState.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/o= rg/apache/geronimo/gbean/runtime/GBeanInstanceState.java?rev=3D169154&r1=3D= 169153&r2=3D169154&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtim= e/GBeanInstanceState.java (original) +++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtim= e/GBeanInstanceState.java Sun May 8 12:35:23 2005 @@ -24,8 +24,8 @@ import org.apache.commons.logging.LogFactory; import org.apache.geronimo.kernel.DependencyManager; import org.apache.geronimo.kernel.GBeanNotFoundException; -import org.apache.geronimo.kernel.Kernel; import org.apache.geronimo.kernel.NoSuchAttributeException; +import org.apache.geronimo.kernel.Kernel; import org.apache.geronimo.kernel.lifecycle.LifecycleAdapter; import org.apache.geronimo.kernel.lifecycle.LifecycleListener; import org.apache.geronimo.kernel.management.State; @@ -190,9 +190,9 @@ ObjectName child =3D (ObjectName) iterator.next(); try { log.trace("Checking if child is running: child=3D" + child= ); - if (((Integer) kernel.getAttribute(child, "state")).intVal= ue() =3D=3D State.RUNNING_INDEX) { + if (kernel.getGBeanState(child) =3D=3D State.RUNNING_INDEX= ) { log.trace("Stopping child: child=3D" + child); - kernel.invoke(child, "stop", null, null); + kernel.stopGBean(child); log.trace("Stopped child: child=3D" + child); } } catch (Exception ignore) { @@ -306,14 +306,11 @@ } try { log.trace("Checking if parent is running: parent=3D" += parent); - if (((Integer) kernel.getAttribute(parent, "state")).i= ntValue() !=3D State.RUNNING_INDEX) { + if (kernel.getGBeanState(parent) !=3D State.RUNNING_IN= DEX) { log.trace("Cannot run because parent is not runnin= g: parent=3D" + parent); return; } log.trace("Parent is running: parent=3D" + parent); - } catch (NoSuchAttributeException e) { - // ok -- parent is not a startable - log.trace("Parent does not have a State attibute"); } catch (GBeanNotFoundException e) { // depended on instance was removed bewteen the regist= er check and the invoke log.trace("Cannot run because parent is not registered= : parent=3D" + parent); Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/= runtime/GBeanSingleReference.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/o= rg/apache/geronimo/gbean/runtime/GBeanSingleReference.java?rev=3D169154&r1= =3D169153&r2=3D169154&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtim= e/GBeanSingleReference.java (original) +++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtim= e/GBeanSingleReference.java Sun May 8 12:35:23 2005 @@ -25,8 +25,8 @@ import org.apache.commons.logging.LogFactory; import org.apache.geronimo.gbean.GReferenceInfo; import org.apache.geronimo.gbean.InvalidConfigurationException; -import org.apache.geronimo.kernel.Kernel; import org.apache.geronimo.kernel.DependencyManager; +import org.apache.geronimo.kernel.Kernel; import org.apache.geronimo.kernel.lifecycle.LifecycleAdapter; import org.apache.geronimo.kernel.lifecycle.LifecycleListener; import org.apache.geronimo.kernel.management.State; Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel= /ClassLoaderReference.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/o= rg/apache/geronimo/kernel/ClassLoaderReference.java?rev=3D169154&r1=3D16915= 3&r2=3D169154&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Class= LoaderReference.java (original) +++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Class= LoaderReference.java Sun May 8 12:35:23 2005 @@ -16,15 +16,13 @@ */ package org.apache.geronimo.kernel; =20 -import java.io.Serializable; import java.io.IOException; -import java.io.ObjectStreamException; +import java.io.Serializable; =20 /** * @version $Rev$ $Date$ */ public class ClassLoaderReference extends ClassLoader implements Serializa= ble { - private ClassLoader classloader; =20 public ClassLoaderReference(ClassLoader parent) { @@ -37,7 +35,7 @@ classloader =3D objectInputStreamExt.getClassloader(); } =20 - private Object readResolve() throws ObjectStreamException { + private Object readResolve() { return classloader; } } Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel= /ClassLoading.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/o= rg/apache/geronimo/kernel/ClassLoading.java?rev=3D169154&r1=3D169153&r2=3D1= 69154&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Class= Loading.java (original) +++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Class= Loading.java Sun May 8 12:35:23 2005 @@ -27,7 +27,6 @@ * @version $Rev$ $Date$ */ public class ClassLoading { - /** * Load a class for the given name. *

Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel= /DependencyManager.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/o= rg/apache/geronimo/kernel/DependencyManager.java?rev=3D169154&r1=3D169153&r= 2=3D169154&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Depen= dencyManager.java (original) +++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Depen= dencyManager.java Sun May 8 12:35:23 2005 @@ -18,72 +18,24 @@ package org.apache.geronimo.kernel; =20 import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; import java.util.Set; import javax.management.ObjectName; =20 -import org.apache.geronimo.kernel.lifecycle.LifecycleAdapter; -import org.apache.geronimo.kernel.lifecycle.LifecycleListener; -import org.apache.geronimo.kernel.lifecycle.LifecycleMonitor; - /** * DependencyManager is the record keeper of the dependencies in Geronimo.= The DependencyManager * does not enforce any dependencies, it is simply a place where component= s 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. + * to be dependent on another component. *

* The DependencyManager uses the nomenclature of parent-child where a chi= ld is dependent on a parent. * The names parent and child have no other meaning are just a convience t= o make the code readable. * * @version $Rev$ $Date$ */ -public class 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 asso= ciated with the dependency - */ - private final LifecycleListener lifecycleListener =3D new DependencyMa= nagerLifecycleListener(); - - /** - * A map from child names to a list of parents. - */ - private final Map childToParentMap =3D new HashMap(); - +public interface DependencyManager { /** - * A map from parent back to a list of its children. + * Closes the dependency manager releasing all resources */ - private final Map parentToChildMap =3D new HashMap(); - - /** - * A map from a component's ObjectName to the list of ObjectPatterns t= hat the component is blocking - * from starting. - */ - private final Map startHoldsMap =3D new HashMap(); - - public DependencyManager(LifecycleMonitor lifecycleMonitor) throws Exc= eption { - assert lifecycleMonitor !=3D null; - this.lifecycleMonitor =3D lifecycleMonitor; - lifecycleMonitor.addLifecycleListener(lifecycleListener, new Objec= tName("*:*")); - } - - public synchronized void close() { - lifecycleMonitor.removeLifecycleListener(lifecycleListener); - childToParentMap.clear(); - parentToChildMap.clear(); - startHoldsMap.clear(); - } + public void close(); =20 /** * Declares a dependency from a child to a parent. @@ -91,21 +43,7 @@ * @param child the dependent component * @param parent the component the child is depending on */ - public synchronized void addDependency(ObjectName child, ObjectName pa= rent) { - Set parents =3D (Set) childToParentMap.get(child); - if (parents =3D=3D null) { - parents =3D new HashSet(); - childToParentMap.put(child, parents); - } - parents.add(parent); - - Set children =3D (Set) parentToChildMap.get(parent); - if (children =3D=3D null) { - children =3D new HashSet(); - parentToChildMap.put(parent, children); - } - children.add(child); - } + public void addDependency(ObjectName child, ObjectName parent); =20 /** * Removes a dependency from a child to a parent @@ -113,37 +51,14 @@ * @param child the dependnet component * @param parent the component that the child wil no longer depend on */ - public synchronized void removeDependency(ObjectName child, ObjectName= parent) { - Set parents =3D (Set) childToParentMap.get(child); - if (parents !=3D null) { - parents.remove(parent); - } - - Set children =3D (Set) parentToChildMap.get(parent); - if (children !=3D null) { - children.remove(child); - } - } + public void removeDependency(ObjectName child, ObjectName parent); =20 /** * Removes all dependencies for a child * * @param child the component that will no longer depend on anything */ - public synchronized void removeAllDependencies(ObjectName child) { - Set parents =3D (Set) childToParentMap.remove(child); - if (parents =3D=3D null) { - return; - } - for (Iterator iterator =3D parents.iterator(); iterator.hasNext();= ) { - ObjectName parent =3D (ObjectName) iterator.next(); - Set children =3D (Set) parentToChildMap.get(parent); - if (children !=3D null) { - children.remove(child); - } - - } - } + public void removeAllDependencies(ObjectName child); =20 /** * Adds dependencies from the child to every parent in the parents set @@ -151,25 +66,7 @@ * @param child the dependent component * @param parents the set of components the child is depending on */ - public synchronized void addDependencies(ObjectName child, Set parents= ) { - Set existingParents =3D (Set) childToParentMap.get(child); - if (existingParents =3D=3D null) { - existingParents =3D new HashSet(parents); - childToParentMap.put(child, existingParents); - } else { - existingParents.addAll(parents); - } - - for (Iterator i =3D parents.iterator(); i.hasNext();) { - Object startParent =3D i.next(); - Set children =3D (Set) parentToChildMap.get(startParent); - if (children =3D=3D null) { - children =3D new HashSet(); - parentToChildMap.put(startParent, children); - } - children.add(child); - } - } + public void addDependencies(ObjectName child, Set parents); =20 /** * Gets the set of parents that the child is depending on @@ -177,13 +74,7 @@ * @param child the dependent component * @return a collection containing all of the components the child dep= ends on; will never be null */ - public synchronized Set getParents(ObjectName child) { - Set parents =3D (Set) childToParentMap.get(child); - if (parents =3D=3D null) { - return Collections.EMPTY_SET; - } - return new HashSet(parents); - } + public Set getParents(ObjectName child); =20 /** * Gets all of the MBeans that have a dependency on the specified star= tParent. @@ -191,13 +82,7 @@ * @param parent the component the returned childen set depend on * @return a collection containing all of the components that depend o= n the parent; will never be null */ - public synchronized Set getChildren(ObjectName parent) { - Set children =3D (Set) parentToChildMap.get(parent); - if (children =3D=3D null) { - return Collections.EMPTY_SET; - } - return new HashSet(children); - } + public Set getChildren(ObjectName parent); =20 /** * Adds a hold on a collection of object name patterns. If the name o= f a component matches an object name @@ -206,15 +91,7 @@ * @param objectName the name of the component placing the holds * @param holds a collection of object name patterns which should not = start */ - public synchronized void addStartHolds(ObjectName objectName, Collecti= on holds) { - Collection currentHolds =3D (Collection) startHoldsMap.get(objectN= ame); - if (currentHolds =3D=3D null) { - currentHolds =3D new LinkedList(holds); - startHoldsMap.put(objectName, currentHolds); - } else { - currentHolds.addAll(holds); - } - } + public void addStartHolds(ObjectName objectName, Collection holds); =20 /** * Removes a collection of holds. @@ -222,50 +99,20 @@ * @param objectName the object name of the components owning the holds * @param holds a collection of the holds to remove */ - public synchronized void removeStartHolds(ObjectName objectName, Colle= ction holds) { - Collection currentHolds =3D (Collection) startHoldsMap.get(objectN= ame); - if (currentHolds !=3D null) { - currentHolds.removeAll(holds); - } - } + public void removeStartHolds(ObjectName objectName, Collection holds); =20 /** * Removes all of the holds owned by a component. * * @param objectName the object name of the component that will no lon= ger have any holds */ - public synchronized void removeAllStartHolds(ObjectName objectName) { - startHoldsMap.remove(objectName); - } - - /** - * Gets the object name of the mbean blocking the start specified mbea= n=2E - * - * @param objectName the mbean to check for blockers - * @return the mbean blocking the specified mbean, or null if there ar= e no blockers - */ - public synchronized ObjectName checkBlocker(ObjectName objectName) { - // check if objectName name is on one of the hold lists - for (Iterator iterator =3D startHoldsMap.keySet().iterator(); iter= ator.hasNext();) { - ObjectName blocker =3D (ObjectName) iterator.next(); - List holds =3D (List) startHoldsMap.get(blocker); - for (Iterator holdsIterator =3D holds.iterator(); holdsIterato= r=2EhasNext();) { - ObjectName pattern =3D (ObjectName) holdsIterator.next(); - if (pattern.apply(objectName)) { - return blocker; - } - } - } - return null; - } - - private class DependencyManagerLifecycleListener extends LifecycleAdap= ter { - public void unloaded(ObjectName objectName) { - synchronized (DependencyManager.this) { - removeAllDependencies(objectName); - removeAllStartHolds(objectName); - } + public void removeAllStartHolds(ObjectName objectName); =20 - } - } + /** + * Gets the object name of the bean blocking the start specified bean. + * + * @param objectName the bean to check for blockers + * @return the bean blocking the specified bean, or null if there are = no blockers + */ + public ObjectName checkBlocker(ObjectName objectName); } Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel= /Kernel.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/o= rg/apache/geronimo/kernel/Kernel.java?rev=3D169154&r1=3D169153&r2=3D169154&= view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Kerne= l=2Ejava (original) +++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Kerne= l=2Ejava Sun May 8 12:35:23 2005 @@ -1,6 +1,6 @@ /** * - * Copyright 2003-2004 The Apache Software Foundation + * Copyright 2005 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. @@ -14,561 +14,260 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.geronimo.kernel; =20 -import java.io.IOException; -import java.lang.ref.ReferenceQueue; -import java.lang.ref.WeakReference; -import java.net.URI; -import java.util.Collections; import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; import java.util.Set; -import javax.management.MalformedObjectNameException; import javax.management.ObjectName; =20 -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.apache.geronimo.gbean.GBeanData; import org.apache.geronimo.gbean.GBeanInfo; -import org.apache.geronimo.gbean.GBeanName; -import org.apache.geronimo.gbean.runtime.GBeanInstance; -import org.apache.geronimo.kernel.config.Configuration; -import org.apache.geronimo.kernel.config.ConfigurationManager; -import org.apache.geronimo.kernel.config.ConfigurationManagerImpl; -import org.apache.geronimo.kernel.config.InvalidConfigException; -import org.apache.geronimo.kernel.config.NoSuchConfigException; -import org.apache.geronimo.kernel.config.NoSuchStoreException; -import org.apache.geronimo.kernel.jmx.JMXLifecycleBroadcaster; import org.apache.geronimo.kernel.jmx.JMXUtil; -import org.apache.geronimo.kernel.lifecycle.BasicLifecycleMonitor; import org.apache.geronimo.kernel.lifecycle.LifecycleMonitor; -import org.apache.geronimo.kernel.lifecycle.LifecycleMonitorFlyweight; import org.apache.geronimo.kernel.proxy.ProxyManager; -import org.apache.geronimo.kernel.registry.BasicGBeanRegistry; -import org.apache.geronimo.kernel.registry.GBeanRegistry; - =20 /** - * The core of a Geronimo instance. - * A Kernel is responsible for managing the Configurations that comprise a - * Geronimo system and exposing them using JMX. Each Kernel is associated - * with an MBeanServer that is used to register the Configurations themsel= ves - * and the MBeans they define. - *

- * Dependencies between MBeans are handled by a dedicated DependencyManager - * that is responsible for tracking those dependencies and ensuring that t= he - * dependent objects follow the appropriate lifecycle and receive appropri= ate - * notifications. - *

- * The Kernel also provides a ConfigurationStore which is used to stage - * installed Configurations (providing a local filesystem based classpath)= and - * used hold the persistent state of each Configuration. This allows - * Configurations to restart in the event of system failure. - *=20 - * TODO: Describe the order of method invocation (e.g. if loadGbean may be= before boot) - * * @version $Rev$ $Date$ */ -public class Kernel { - +public interface Kernel { /** * The JMX name used by a Kernel to register itself when it boots. - * todo drop "geronimo.boot:" from this name so the kernel shows up in= the kernel default domain */ - public static final ObjectName KERNEL =3D JMXUtil.getObjectName("geron= imo.boot:role=3DKernel"); + ObjectName KERNEL =3D JMXUtil.getObjectName(":role=3DKernel"); =20 /** - * Index of kernel (Weak) references by kernel name + * Get the name of this kernel + * + * @return the name of this kernel */ - private static final Map kernels =3D new HashMap(); + String getKernelName(); =20 /** - * ReferenceQueue that watches the weak references to our kernels + * Gets the dependency manager kernel service + * @return the dependency manager or null if the kernel is not running */ - private static final ReferenceQueue queue =3D new ReferenceQueue(); + DependencyManager getDependencyManager(); =20 /** - * Helper objects for invoke and getAttribute + * Gets the lifecycle monitor kernel service + * @return the lifecycle monitor or null if the kernel is not running */ - private static final String[] NO_TYPES =3D new String[0]; - private static final Object[] NO_ARGS =3D new Object[0]; + LifecycleMonitor getLifecycleMonitor(); =20 /** - * Name of the configuration manager - * todo drop "geronimo.boot:" from this name so the configuration mang= er shows up in the kernel default domain + * Gets the proxy manager kernel service + * @return the proxy manager or null if the kernel is not running */ - private static final ObjectName CONFIGURATION_MANAGER_NAME =3D JMXUtil= .getObjectName("geronimo.boot:role=3DConfigurationManager"); + ProxyManager getProxyManager(); =20 /** - * Te pattern we use to find all the configuation stores registered wi= th the kernel + * Load a specific GBean into this kernel. + * This is intended for applications that are embedding the kernel. + * + * @param gbeanData the GBean to load + * @param classLoader the class loader to use to load the gbean + * @throws org.apache.geronimo.kernel.GBeanAlreadyExistsException if t= he name is already used + * @throws org.apache.geronimo.kernel.InternalKernelException if there= is a problem during registration */ - private static final ObjectName CONFIGURATION_STORE_PATTERN =3D JMXUti= l=2EgetObjectName("*:j2eeType=3DConfigurationStore,*"); + void loadGBean(GBeanData gbeanData, ClassLoader classLoader) throws GB= eanAlreadyExistsException, InternalKernelException; =20 /** - * Name of this kernel + * Is there a GBean registered with the kernel under the specified nam= e? + * @param name the name to check + * @return true if there is a gbean registered under the specified nam= e; false otherwise */ - private final String kernelName; + boolean isLoaded(ObjectName name); =20 /** - * The log + * Start a specific GBean. + * + * @param name the GBean to start + * @throws org.apache.geronimo.kernel.GBeanNotFoundException if the GB= ean could not be found + * @throws InternalKernelException if there GBean is not state managea= ble or if there is a general error + * @throws IllegalStateException If the gbean is disabled */ - private Log log; + void startGBean(ObjectName name) throws GBeanNotFoundException, Intern= alKernelException, IllegalStateException; =20 /** - * Is this kernel running? + * Start a specific GBean and its children. + * + * @param name the GBean to start + * @throws GBeanNotFoundException if the GBean could not be found + * @throws InternalKernelException if there GBean is not state managea= ble or if there is a general error + * @throws IllegalStateException If the gbean is disabled */ - private boolean running; + void startRecursiveGBean(ObjectName name) throws GBeanNotFoundExceptio= n, InternalKernelException, IllegalStateException; =20 /** - * The timestamp when the kernel was started + * Stop a specific GBean. + * + * @param name the GBean to stop + * @throws GBeanNotFoundException if the GBean could not be found + * @throws InternalKernelException if there GBean is not state managea= ble or if there is a general error + * @throws IllegalStateException If the gbean is disabled */ - private Date bootTime; + void stopGBean(ObjectName name) throws GBeanNotFoundException, Interna= lKernelException, IllegalStateException; =20 /** - * The gbean registry + * Unload a specific GBean. + * This is intended for applications that are embedding the kernel. + * + * @param name the name of the GBean to unregister + * @throws GBeanNotFoundException if the GBean could not be found + * @throws InternalKernelException if there GBean is a problem while u= nloading the GBean */ - private final GBeanRegistry gbeanRegistry; + void unloadGBean(ObjectName name) throws GBeanNotFoundException, Inter= nalKernelException, IllegalStateException; =20 /** - * Listeners for when the kernel shutdown + * Gets the state of the specified GBean. + * @param name the name of the GBean + * @return the state of the GBean + * @throws GBeanNotFoundException if the GBean could not be found */ - private LinkedList shutdownHooks =3D new LinkedList(); + int getGBeanState(ObjectName name) throws GBeanNotFoundException; =20 /** - * This manager is used by the kernel to manage dependencies between g= beans + * Gets the time the specified GBean was started + * @param name the name of the GBean + * @return the start time of the GBean or 0 if not running + * @throws GBeanNotFoundException if the GBean could not be found */ - private DependencyManager dependencyManager; + long getGBeanStartTime(ObjectName name) throws GBeanNotFoundException; =20 /** - * The kernel uses this manager to load configurations which are colle= ctions of GBeans + * Is the specified GBean enabled? + * @param name the name if the GBean + * @return true if the gbean is enabled + * @throws GBeanNotFoundException if the GBean could not be found */ - private ConfigurationManager configurationManager; + boolean isGBeanEnabled(ObjectName name) throws GBeanNotFoundException; =20 /** - * The GBeanMbean that wraps the configuration manager + * Sets the eneabled status of the specified GBean. A disabled gbean = can not be started, and + * will not be started via startRecursive. + * @param name the name if the GBean + * @param enabled the new enabled status + * @throws GBeanNotFoundException if the GBean could not be found */ - private GBeanInstance configurationManagerInstance; + void setGBeanEnabled(ObjectName name, boolean enabled) throws GBeanNot= FoundException; =20 /** - * Monitors the lifecycle of all gbeans. + * Gets the ClassLoader used to register the specified GBean + * @param name the name of the gbean from which the class loader shoul= d be extracted + * @return the class loader associated with the specified GBean + * @throws GBeanNotFoundException if the specified GBean is not regist= ered with the kernel */ - private BasicLifecycleMonitor lifecycleMonitor; - private LifecycleMonitor publicLifecycleMonitor; + ClassLoader getClassLoaderFor(ObjectName name) throws GBeanNotFoundExc= eption; =20 /** - * This factory gbean proxies, and tracks all proxies in the system + * Return the GBeanInfo for a registered GBean instance. + * @param name the name of the GBean whose info should be returned + * @return the info for that instance + * @throws GBeanNotFoundException if there is no instance with the sup= plied name */ - private ProxyManager proxyManager; + GBeanInfo getGBeanInfo(ObjectName name) throws GBeanNotFoundException; =20 /** - * No-arg constructor allowing this class to be used as a GBean refere= nce. + * Return the GBeanData for a GBean instance. + * @param name the name of the GBean whose info should be returned + * @return the info for that instance + * @throws GBeanNotFoundException if there is no instance with the sup= plied name */ - protected Kernel() { - kernelName =3D null; - gbeanRegistry =3D null; - } + GBeanData getGBeanData(ObjectName name) throws GBeanNotFoundException,= InternalKernelException; =20 /** - * Construct a Kernel with the specified name and GBeanRegistry implem= entation. - * - * @param kernelName the name of the kernel - * @param gbeanRegistry the GBeanRegistry implementation to use for th= is contianer + * Returns a Set of all GBeans matching the object name pattern + * @return a List of javax.management.ObjectName of matching GBeans re= gistered with this kernel */ - public Kernel(String kernelName, GBeanRegistry gbeanRegistry) { - if (kernelName.indexOf(':') >=3D 0 || kernelName.indexOf('*') >=3D= 0 || kernelName.indexOf('?') >=3D 0) { - throw new IllegalArgumentException("Kernel name may not contai= n a ':', '*' or '?' character"); - } - this.kernelName =3D kernelName; - this.gbeanRegistry =3D gbeanRegistry; - } + Set listGBeans(ObjectName pattern); =20 /** - * Construct a Kernel with the specified name and an unspecified GBean= Registry implementation. - * - * @param kernelName the name of the kernel + * Returns a Set of all GBeans matching the set of object name pattern + * @return a List of javax.management.ObjectName of matching GBeans re= gistered with this kernel */ - public Kernel(String kernelName) { - this(kernelName, new BasicGBeanRegistry()); - } - - public String getKernelName() { - return kernelName; - } - - public static Set getKernelNames() { - synchronized(kernels) { - return Collections.unmodifiableSet(kernels.keySet()); - } - } - =20 + Set listGBeans(Set patterns); + /** - * Get a particular kernel indexed by a name - * - * @param name the name of the kernel to be obtained - * @return the kernel that was registered with that name + * Gets the value of an attribute on the specified gbean + * @param objectName the name of the gbean from which the attribute wi= ll be retrieved + * @param attributeName the name of the attribute to fetch + * @return the value of the attribute + * @throws GBeanNotFoundException if there is not a gbean under the sp= ecified name + * @throws NoSuchAttributeException if the gbean does not contain the = specified attribute + * @throws Exception if the gbean throws an exception from the getter */ - public static Kernel getKernel(String name) { - if (name =3D=3D null) { - return getSingleKernel(); - } - synchronized (kernels) { - processQueue(); - KernelReference ref =3D (KernelReference) kernels.get(name); - if (ref !=3D null) { - return (Kernel) ref.get(); - } - } - return null; - } - - /** - * Obtain the single kernel that's registered. - *

- *

This method assumes that there is only one kernel registered and= will throw an - * IllegalStateException if more than one has been regist= ered. - * - * @return the single kernel that's registered - * @throws IllegalStateException if more than one + Object getAttribute(ObjectName objectName, String attributeName) throw= s GBeanNotFoundException, NoSuchAttributeException, Exception; + + /** + * Sets the value of an attribute on the specified gbean + * @param objectName the name of the gbean from in which the new attri= bute value will be set + * @param attributeName the name of the attribute to set + * @param attributeValue the new value of the attribute + * @throws GBeanNotFoundException if there is not a gbean under the sp= ecified name + * @throws NoSuchAttributeException if the gbean does not contain the = specified attribute + * @throws Exception if the gbean throws an exception from the setter */ - public static Kernel getSingleKernel() { - synchronized (kernels) { - processQueue(); - - int size =3D kernels.size(); - if (size > 1) throw new IllegalStateException("More than one k= ernel has been registered."); - if (size < 1) return null; - - Kernel result =3D (Kernel) ((KernelReference) kernels.values()= .iterator().next()).get(); - if (result =3D=3D null) { - kernels.clear(); - } - return result; - } - } - - /** - * @deprecated this will be removed as when we add generalized depende= ncies to gbeans... the only current user is Configuration - */ - public DependencyManager getDependencyManager() { - return dependencyManager; - } - - public ConfigurationManager getConfigurationManager() { - return configurationManager; - } - - /** - * Gets the lifecycle monitor. - * @deprecated don't use this yet... it may change or go away - */ - public LifecycleMonitor getLifecycleMonitor() { - return publicLifecycleMonitor; - } - - /** - * Gets the proxy manager. - * @deprecated don't use this yet... it may change or go away - */ - public ProxyManager getProxyManager() { - return proxyManager; - } - - public Object getAttribute(ObjectName objectName, String attributeName= ) throws GBeanNotFoundException, NoSuchAttributeException, Exception { - GBeanInstance gbeanInstance =3D gbeanRegistry.getGBeanInstance(new= GBeanName(objectName)); - return gbeanInstance.getAttribute(attributeName); - } - - public void setAttribute(ObjectName objectName, String attributeName, = Object attributeValue) throws GBeanNotFoundException, NoSuchAttributeExcept= ion, Exception { - GBeanInstance gbeanInstance =3D gbeanRegistry.getGBeanInstance(new= GBeanName(objectName)); - gbeanInstance.setAttribute(attributeName, attributeValue); - } - - public Object invoke(ObjectName objectName, String methodName) throws = GBeanNotFoundException, NoSuchOperationException, InternalKernelException, = Exception { - return invoke(objectName, methodName, NO_ARGS, NO_TYPES); - } - - public Object invoke(ObjectName objectName, String methodName, Object[= ] args, String[] types) throws GBeanNotFoundException, NoSuchOperationExcep= tion, InternalKernelException, Exception { - GBeanInstance gbeanInstance =3D gbeanRegistry.getGBeanInstance(new= GBeanName(objectName)); - return gbeanInstance.invoke(methodName, args, types); - } - - public boolean isLoaded(ObjectName name) { - return gbeanRegistry.isRegistered(new GBeanName(name)); - } - - public GBeanInfo getGBeanInfo(ObjectName name) throws GBeanNotFoundExc= eption { - GBeanInstance gbeanInstance =3D gbeanRegistry.getGBeanInstance(new= GBeanName(name)); - return gbeanInstance.getGBeanInfo(); - } - - public GBeanData getGBeanData(ObjectName name) throws GBeanNotFoundExc= eption, InternalKernelException { - GBeanInstance gbeanInstance =3D gbeanRegistry.getGBeanInstance(new= GBeanName(name)); - return gbeanInstance.getGBeanData(); - } - - public void loadGBean(GBeanData gbeanData, ClassLoader classLoader) th= rows GBeanAlreadyExistsException, InternalKernelException { - ObjectName objectName =3D gbeanData.getName(); - GBeanInstance gbeanInstance =3D new GBeanInstance(gbeanData, this,= dependencyManager, lifecycleMonitor.createLifecycleBroadcaster(objectName)= , classLoader); - gbeanRegistry.register(gbeanInstance); - } - - /** - * @deprecated use loadGBean(GBeanData gbeanData, ClassLoader classLoa= der) - */ - public void loadGBean(ObjectName name, org.apache.geronimo.gbean.jmx.G= BeanMBean gbean) throws GBeanAlreadyExistsException, InternalKernelExceptio= n { - GBeanData gbeanData =3D gbean.getGBeanData(); - gbeanData.setName(name); - ClassLoader classLoader =3D gbean.getClassLoader(); - loadGBean(gbeanData, classLoader); - } - - public void startGBean(ObjectName name) throws GBeanNotFoundException,= InternalKernelException, IllegalStateException { - GBeanInstance gbeanInstance =3D gbeanRegistry.getGBeanInstance(new= GBeanName(name)); - gbeanInstance.start(); - } - - public void startRecursiveGBean(ObjectName name) throws GBeanNotFoundE= xception, InternalKernelException, IllegalStateException { - GBeanInstance gbeanInstance =3D gbeanRegistry.getGBeanInstance(new= GBeanName(name)); - gbeanInstance.startRecursive(); - } - - public void stopGBean(ObjectName name) throws GBeanNotFoundException, = InternalKernelException, IllegalStateException { - GBeanInstance gbeanInstance =3D gbeanRegistry.getGBeanInstance(new= GBeanName(name)); - gbeanInstance.stop(); - } - - public void unloadGBean(ObjectName name) throws GBeanNotFoundException= , InternalKernelException, IllegalStateException { - GBeanName gbeanName =3D new GBeanName(name); - GBeanInstance gbeanInstance =3D gbeanRegistry.getGBeanInstance(gbe= anName); - gbeanInstance.die(); - gbeanRegistry.unregister(gbeanName); - } - - public Set listGBeans(ObjectName pattern) { - String domain =3D (pattern =3D=3D null || pattern.isDomainPattern(= )) ? null : pattern.getDomain(); - Map props =3D pattern =3D=3D null ? null : pattern.getKeyPropertyL= ist(); - Set gbeans =3D gbeanRegistry.listGBeans(domain, props); - Set result =3D new HashSet(gbeans.size()); - for (Iterator i =3D gbeans.iterator(); i.hasNext();) { - GBeanInstance instance =3D (GBeanInstance) i.next(); - result.add(instance.getObjectNameObject()); - } - return result; - } - - public Set listGBeans(Set patterns) { - Set gbeans =3D new HashSet(); - for (Iterator iterator =3D patterns.iterator(); iterator.hasNext()= ;) { - ObjectName pattern =3D (ObjectName) iterator.next(); - gbeans.addAll(listGBeans(pattern)); - } - return gbeans; - } - - public List listConfigurationStores() { - return getConfigurationManager().listStores(); - } - - public List listConfigurations(ObjectName storeName) throws NoSuchStor= eException { - return getConfigurationManager().listConfigurations(storeName); - } - - public ObjectName startConfiguration(URI configID) throws NoSuchConfig= Exception, IOException, InvalidConfigException, InternalKernelException { - ObjectName configName =3D getConfigurationManager().load(configID); - try { - startRecursiveGBean(configName); - } catch (GBeanNotFoundException e) { - // should not happen as we just loaded it - throw new InvalidConfigException(e); - } - return configName; - } - - public void stopConfiguration(URI configID) throws NoSuchConfigExcepti= on, InternalKernelException { - ConfigurationManager configurationManager =3D getConfigurationMana= ger(); - try { - ObjectName configName =3D Configuration.getConfigurationObject= Name(configID); - stopGBean(configName); - } catch (MalformedObjectNameException e) { - throw new NoSuchConfigException(e); - } catch (GBeanNotFoundException e) { - throw new NoSuchConfigException(e); - } - configurationManager.unload(configID); - } - - public int getConfigurationState(URI configID) throws NoSuchConfigExce= ption, InternalKernelException { - GBeanInstance gbeanInstance =3D null; - try { - ObjectName configName =3D Configuration.getConfigurationObject= Name(configID); - gbeanInstance =3D gbeanRegistry.getGBeanInstance(new GBeanName= (configName)); - } catch (MalformedObjectNameException e) { - throw new NoSuchConfigException(e); - } catch (GBeanNotFoundException e) { - throw new NoSuchConfigException(e); - } - return gbeanInstance.getState(); - } + void setAttribute(ObjectName objectName, String attributeName, Object = attributeValue) throws GBeanNotFoundException, NoSuchAttributeException, Ex= ception; =20 /** - * Boot this Kernel, triggering the instantiation of the MBeanServer a= nd DependencyManager, - * and the registration of ConfigurationStore - * - * @throws java.lang.Exception if the boot fails + * Invokes a no-argument method on the specified GBean + * @param objectName the name of the gbean from in which the new attri= bute value will be set + * @param methodName the name of the method to invoke + * @return the return value of the method or null if the specified met= hod does not return a value + * @throws GBeanNotFoundException if there is not a gbean under the sp= ecified name + * @throws NoSuchOperationException if the gbean does not have the spe= cified operation + * @throws InternalKernelException if an error occurs within the kerne= l itself + * @throws Exception if the method throws an exception + */ + Object invoke(ObjectName objectName, String methodName) throws GBeanNo= tFoundException, NoSuchOperationException, InternalKernelException, Excepti= on; + + /** + * Invokes a method on the specified GBean with the specified arguments + * @param objectName the name of the gbean from in which the new attri= bute value will be set + * @param methodName the name of the method to invoke + * @param args the arguments to pass to the method + * @param types the types of the arguments; the types are used to dete= rmine the signature of the mehod that should be invoked + * @return the return value of the method or null if the specified met= hod does not return a value + * @throws GBeanNotFoundException if there is not a gbean under the sp= ecified name + * @throws NoSuchOperationException if the gbean does not have the spe= cified operation + * @throws InternalKernelException if an error occurs within the kerne= l itself + * @throws Exception if the method throws an exception + */ + Object invoke(ObjectName objectName, String methodName, Object[] args,= String[] types) throws GBeanNotFoundException, NoSuchOperationException, I= nternalKernelException, Exception; + + /** + * Brings the kernel online + * @throws Exception if the kernel can not boot + */ + void boot() throws Exception; + + /** + * Returns the time this kernel was last booted. + * @return the time this kernel was last booted; null if the kernel ha= s not been + */ + Date getBootTime(); + + /** + * Registers a runnable to execute when the kernel is shutdown + * @param hook a runnable to execute when the kernel is shutdown */ - public void boot() throws Exception { - if (running) { - return; - } - bootTime =3D new Date(); - log =3D LogFactory.getLog(Kernel.class.getName()); - log.info("Starting boot"); - - // todo cleanup when boot fails - synchronized (kernels) { - if (kernels.containsKey(kernelName)) { - throw new IllegalStateException("A kernel is already runni= ng this kernel name: " + kernelName); - } - kernels.put(kernelName, new KernelReference(kernelName, this)); - } - - gbeanRegistry.start(this); - - lifecycleMonitor =3D new BasicLifecycleMonitor(this); - publicLifecycleMonitor =3D new LifecycleMonitorFlyweight(lifecycle= Monitor); - dependencyManager =3D new DependencyManager(publicLifecycleMonitor= ); - proxyManager =3D new ProxyManager(this); - - // set up the data for the new configuration manager instance - GBeanData configurationData =3D new GBeanData(CONFIGURATION_MANAGE= R_NAME, ConfigurationManagerImpl.GBEAN_INFO); - configurationData.setReferencePatterns("Stores", Collections.singl= eton(CONFIGURATION_STORE_PATTERN)); - - // create the connfiguration manager instance - JMXLifecycleBroadcaster lifecycleBroadcaster =3D new JMXLifecycleB= roadcaster(CONFIGURATION_MANAGER_NAME, lifecycleMonitor.createLifecycleBroa= dcaster(CONFIGURATION_MANAGER_NAME)); - configurationManagerInstance =3D new GBeanInstance(configurationDa= ta, this, dependencyManager, lifecycleBroadcaster, getClass().getClassLoade= r()); - configurationManagerInstance.start(); - configurationManager =3D (ConfigurationManager) configurationManag= erInstance.getTarget(); - assert configurationManager !=3D null: "ConfigurationManager faile= d to start"; - gbeanRegistry.register(configurationManagerInstance); - - // load and start the kernel gbean - GBeanData kernelGBeanData =3D new GBeanData(KERNEL, KernelGBean.GB= EAN_INFO); - loadGBean(kernelGBeanData, getClass().getClassLoader()); - startGBean(KERNEL); - - running =3D true; - log.info("Booted"); - } - - public Date getBootTime() { - return bootTime; - } - - public void registerShutdownHook(Runnable hook) { - assert hook !=3D null : "Shutdown hook was null"; - synchronized (shutdownHooks) { - shutdownHooks.add(hook); - } - } - - public void unregisterShutdownHook(Runnable hook) { - synchronized (shutdownHooks) { - shutdownHooks.remove(hook); - } - } - - /** - * Shut down this kernel instance, unregistering the MBeans and releas= ing - * the MBeanServer. - */ - public void shutdown() { - if (!running) { - return; - } - running =3D false; - log.info("Starting kernel shutdown"); - - notifyShutdownHooks(); - shutdownConfigManager(); - - gbeanRegistry.stop(); - - dependencyManager.close(); - dependencyManager =3D null; - - synchronized (this) { - notify(); - } - - synchronized (kernels) { - kernels.remove(kernelName); - } - - log.info("Kernel shutdown complete"); - } - - private void notifyShutdownHooks() { - while (!shutdownHooks.isEmpty()) { - Runnable hook; - synchronized (shutdownHooks) { - hook =3D (Runnable) shutdownHooks.removeFirst(); - } - try { - hook.run(); - } catch (Throwable e) { - log.warn("Error from kernel shutdown hook", e); - } - } - } - - private void shutdownConfigManager() { - configurationManager =3D null; - if (configurationManagerInstance !=3D null) { - try { - configurationManagerInstance.stop(); - } catch (Exception e) { - // ignore - } - try { - gbeanRegistry.unregister(new GBeanName(CONFIGURATION_MANAG= ER_NAME)); - } catch (Exception e) { - // ignore - } - configurationManagerInstance =3D null; - } - } - - public boolean isRunning() { - return running; - } - - public ClassLoader getClassLoaderFor(ObjectName name) throws GBeanNotF= oundException { - GBeanInstance gbeanInstance =3D gbeanRegistry.getGBeanInstance(new= GBeanName(name)); - return gbeanInstance.getClassLoader(); - } - - private static void processQueue() { - KernelReference kernelRef; - while ((kernelRef =3D (KernelReference) queue.poll()) !=3D null) { - synchronized (kernels) { - kernels.remove(kernelRef.key); - } - } - } - - private static class KernelReference extends WeakReference { - private final Object key; - - public KernelReference(Object key, Object kernel) { - super(kernel, queue); - this.key =3D key; - } - } + void registerShutdownHook(Runnable hook); + + /** + * Unregisters a runnable from the list to execute when the kernel is = shutdown + * @param hook the runnable that should be removed + */ + void unregisterShutdownHook(Runnable hook); + + /** + * Stops the kernel + */ + void shutdown(); + + /** + * Has the kernel been booted + * @return true if the kernel has been booted; false otherwise + */ + boolean isRunning(); + } Added: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Ke= rnelFactory.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/o= rg/apache/geronimo/kernel/KernelFactory.java?rev=3D169154&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Kerne= lFactory.java (added) +++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Kerne= lFactory.java Sun May 8 12:35:23 2005 @@ -0,0 +1,89 @@ +/** + * + * Copyright 2005 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 implie= d=2E + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geronimo.kernel; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +import org.apache.geronimo.kernel.basic.BasicKernelFactory; + +/** + * @version $Rev$ $Date$ + */ +public abstract class KernelFactory { + public static final String KERNEL_FACTORY_KEY =3D KernelFactory.class.= getName(); + + public static KernelFactory newInstance() { + ClassLoader classLoader =3D Thread.currentThread().getContextClass= Loader(); + if (classLoader =3D=3D null) { + classLoader =3D KernelFactory.class.getClassLoader(); + } + + // System property + try { + String kernelFactoryName =3D System.getProperty(KERNEL_FACTORY= _KEY); + if (kernelFactoryName !=3D null) { + return createKernelFactory(kernelFactoryName, classLoader); + } + } catch (SecurityException se) { + } + + // Jar Service Specification - http://java.sun.com/j2se/1.3/docs/g= uide/jar/jar.html + String serviceId =3D "META-INF/services/" + KERNEL_FACTORY_KEY; + InputStream inputStream =3D null; + try { + inputStream =3D classLoader.getResourceAsStream(serviceId); + if (inputStream !=3D null) { + BufferedReader reader =3D new BufferedReader(new InputStre= amReader(inputStream, "UTF-8")); + String kernelFactoryName =3D reader.readLine(); + reader.close(); + + if (kernelFactoryName !=3D null && kernelFactoryName.lengt= h() > 0) { + return createKernelFactory(kernelFactoryName, classLoa= der); + } + } + } catch (Exception ignored) { + } finally { + if (inputStream !=3D null) { + try { + inputStream.close(); + } catch (IOException ignored) { + } + inputStream =3D null; + } + } + + // Default is the basic kernel + return new BasicKernelFactory(); + } + + private static KernelFactory createKernelFactory(String className, Cla= ssLoader classLoader) { + try { + return (KernelFactory) classLoader.loadClass(className).newIns= tance(); + } catch (ClassCastException e) { + throw new KernelFactoryError("Kernel factory class does not im= plement KernelFactory: " + className); + } catch (ClassNotFoundException e) { + throw new KernelFactoryError("Kernel factory class not found: = " + className); + } catch (Exception e) { + throw new KernelFactoryError("Unable to instantiate kernel fac= tory class: " + className, e); + } + } + + public abstract Kernel createKernel(String kernelName); +} Added: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Ke= rnelFactoryError.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/o= rg/apache/geronimo/kernel/KernelFactoryError.java?rev=3D169154&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Kerne= lFactoryError.java (added) +++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Kerne= lFactoryError.java Sun May 8 12:35:23 2005 @@ -0,0 +1,38 @@ +/** + * + * Copyright 2005 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 implie= d=2E + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geronimo.kernel; + +/** + * @version $Rev$ $Date$ + */ +public class KernelFactoryError extends Error { + public KernelFactoryError() { + super(); + } + + public KernelFactoryError(String message) { + super(message); + } + + public KernelFactoryError(String message, Throwable cause) { + super(message, cause); + } + + public KernelFactoryError(Throwable cause) { + super(cause); + } +} Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel= /KernelGBean.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/o= rg/apache/geronimo/kernel/KernelGBean.java?rev=3D169154&r1=3D169153&r2=3D16= 9154&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Kerne= lGBean.java (original) +++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Kerne= lGBean.java Sun May 8 12:35:23 2005 @@ -16,31 +16,42 @@ */ package org.apache.geronimo.kernel; =20 -import java.io.IOException; -import java.net.URI; import java.util.Date; -import java.util.List; import java.util.Set; import javax.management.ObjectName; =20 import org.apache.geronimo.gbean.GBeanData; import org.apache.geronimo.gbean.GBeanInfo; import org.apache.geronimo.gbean.GBeanInfoBuilder; -import org.apache.geronimo.kernel.config.ConfigurationManager; -import org.apache.geronimo.kernel.config.InvalidConfigException; -import org.apache.geronimo.kernel.config.NoSuchConfigException; -import org.apache.geronimo.kernel.config.NoSuchStoreException; +import org.apache.geronimo.kernel.lifecycle.LifecycleMonitor; +import org.apache.geronimo.kernel.proxy.ProxyManager; =20 /** * @version $Rev$ $Date$ */ -public class KernelGBean { +public class KernelGBean implements Kernel{ private final Kernel kernel; =20 public KernelGBean(Kernel kernel) { this.kernel =3D kernel; } =20 + public DependencyManager getDependencyManager() { + return kernel.getDependencyManager(); + } + + public LifecycleMonitor getLifecycleMonitor() { + return kernel.getLifecycleMonitor(); + } + + public ProxyManager getProxyManager() { + return kernel.getProxyManager(); + } + + public void boot() throws Exception { + throw new UnsupportedOperationException(); + } + public Date getBootTime() { return kernel.getBootTime(); } @@ -69,32 +80,24 @@ kernel.unloadGBean(name); } =20 - public boolean isRunning() { - return kernel.isRunning(); - } - - public ConfigurationManager getConfigurationManager() { - return kernel.getConfigurationManager(); + public int getGBeanState(ObjectName name) throws GBeanNotFoundExceptio= n { + return kernel.getGBeanState(name); } =20 - public List listConfigurationStores() { - return kernel.listConfigurationStores(); + public long getGBeanStartTime(ObjectName name) throws GBeanNotFoundExc= eption { + return kernel.getGBeanStartTime(name); } =20 - public List listConfigurations(ObjectName storeName) throws NoSuchStor= eException { - return kernel.listConfigurations(storeName); + public boolean isGBeanEnabled(ObjectName name) throws GBeanNotFoundExc= eption { + return kernel.isGBeanEnabled(name); } =20 - public ObjectName startConfiguration(URI configID) throws NoSuchConfig= Exception, IOException, InvalidConfigException { - return kernel.startConfiguration(configID); + public void setGBeanEnabled(ObjectName name, boolean enabled) throws G= BeanNotFoundException { + kernel.setGBeanEnabled(name, enabled); } =20 - public void stopConfiguration(URI configID) throws NoSuchConfigExcepti= on { - kernel.stopConfiguration(configID); - } - - public int getConfigurationState(URI configId) throws NoSuchConfigExce= ption { - return kernel.getConfigurationState(configId); + public boolean isRunning() { + return kernel.isRunning(); } =20 public ClassLoader getClassLoaderFor(ObjectName name) throws GBeanNotF= oundException, InternalKernelException { Added: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Ke= rnelRegistry.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/o= rg/apache/geronimo/kernel/KernelRegistry.java?rev=3D169154&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Kerne= lRegistry.java (added) +++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Kerne= lRegistry.java Sun May 8 12:35:23 2005 @@ -0,0 +1,124 @@ +/** + * + * Copyright 2005 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 implie= d=2E + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geronimo.kernel; + +import java.lang.ref.WeakReference; +import java.lang.ref.ReferenceQueue; +import java.util.Map; +import java.util.HashMap; +import java.util.Set; +import java.util.Collections; + +/** + * @version $Rev$ $Date$ + */ +public final class KernelRegistry { + /** + * Index of kernel references by kernel name + */ + private static final Map kernels =3D new HashMap(); + + /** + * ReferenceQueue that watches the weak references to our kernels + */ + private static final ReferenceQueue queue =3D new ReferenceQueue(); + + public static Set getKernelNames() { + synchronized(kernels) { + return Collections.unmodifiableSet(kernels.keySet()); + } + } + + /** + * Get a particular kernel indexed by a name + * + * @param name the name of the kernel to be obtained + * @return the kernel that was registered with that name + */ + public static Kernel getKernel(String name) { + if (name =3D=3D null) { + return getSingleKernel(); + } + synchronized (kernels) { + processQueue(); + KernelReference ref =3D (KernelReference) kernels.get(name); + if (ref !=3D null) { + return (Kernel) ref.get(); + } + } + return null; + } + + /** + * Obtain the single kernel that's registered. + *

+ *

This method assumes that there is only one kernel registered and= will throw an + * IllegalStateException if more than one has been regist= ered. + * + * @return the single kernel that's registered + * @throws IllegalStateException if more than one + */ + public static Kernel getSingleKernel() { + synchronized (kernels) { + processQueue(); + + int size =3D kernels.size(); + if (size > 1) throw new IllegalStateException("More than one k= ernel has been registered."); + if (size < 1) return null; + + Kernel result =3D (Kernel) ((KernelReference) kernels.values()= .iterator().next()).get(); + if (result =3D=3D null) { + kernels.clear(); + } + return result; + } + } + + public static void registerKernel(Kernel kernel) { + synchronized (kernels) { + String kernelName =3D kernel.getKernelName(); + if (kernels.containsKey(kernelName)) { + throw new IllegalStateException("A kernel is already runni= ng this kernel name: " + kernelName); + } + kernels.put(kernelName, new KernelReference(kernelName, kernel= )); + } + } + + public static void unregisterKernel(Kernel kernel) { + synchronized (kernels) { + kernels.remove(kernel.getKernelName()); + } + } + + private static void processQueue() { + KernelReference kernelRef; + while ((kernelRef =3D (KernelReference) queue.poll()) !=3D null) { + synchronized (kernels) { + kernels.remove(kernelRef.key); + } + } + } + + private static class KernelReference extends WeakReference { + private final Object key; + + public KernelReference(Object key, Object kernel) { + super(kernel, queue); + this.key =3D key; + } + } +} Added: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/ba= sic/BasicDependencyManager.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/o= rg/apache/geronimo/kernel/basic/BasicDependencyManager.java?rev=3D169154&vi= ew=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/basic= /BasicDependencyManager.java (added) +++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/basic= /BasicDependencyManager.java Sun May 8 12:35:23 2005 @@ -0,0 +1,272 @@ +/** + * + * 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 implie= d=2E + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.geronimo.kernel.basic; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import javax.management.ObjectName; + +import org.apache.geronimo.kernel.lifecycle.LifecycleAdapter; +import org.apache.geronimo.kernel.lifecycle.LifecycleListener; +import org.apache.geronimo.kernel.lifecycle.LifecycleMonitor; +import org.apache.geronimo.kernel.DependencyManager; + +/** + * DependencyManager is the record keeper of the dependencies in Geronimo.= The DependencyManager + * does not enforce any dependencies, it is simply a place where component= s 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. + *

+ * The DependencyManager uses the nomenclature of parent-child where a chi= ld is dependent on a parent. + * The names parent and child have no other meaning are just a convience t= o make the code readable. + * + * @version $Rev: 124822 $ $Date: 2005-01-10 11:01:13 -0800 (Mon, 10 Jan 2= 005) $ + */ +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 asso= ciated with the dependency + */ + private final LifecycleListener lifecycleListener =3D new DependencyMa= nagerLifecycleListener(); + + /** + * A map from child names to a list of parents. + */ + private final Map childToParentMap =3D new HashMap(); + + /** + * A map from parent back to a list of its children. + */ + private final Map parentToChildMap =3D new HashMap(); + + /** + * A map from a component's ObjectName to the list of ObjectPatterns t= hat the component is blocking + * from starting. + */ + private final Map startHoldsMap =3D new HashMap(); + + public BasicDependencyManager(LifecycleMonitor lifecycleMonitor) throw= s Exception { + assert lifecycleMonitor !=3D null; + this.lifecycleMonitor =3D lifecycleMonitor; + lifecycleMonitor.addLifecycleListener(lifecycleListener, new Objec= tName("*:*")); + } + + public synchronized void close() { + lifecycleMonitor.removeLifecycleListener(lifecycleListener); + childToParentMap.clear(); + parentToChildMap.clear(); + startHoldsMap.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(ObjectName child, ObjectName pa= rent) { + Set parents =3D (Set) childToParentMap.get(child); + if (parents =3D=3D null) { + parents =3D new HashSet(); + childToParentMap.put(child, parents); + } + parents.add(parent); + + Set children =3D (Set) parentToChildMap.get(parent); + if (children =3D=3D null) { + children =3D 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(ObjectName child, ObjectName= parent) { + Set parents =3D (Set) childToParentMap.get(child); + if (parents !=3D null) { + parents.remove(parent); + } + + Set children =3D (Set) parentToChildMap.get(parent); + if (children !=3D 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(ObjectName child) { + Set parents =3D (Set) childToParentMap.remove(child); + if (parents =3D=3D null) { + return; + } + for (Iterator iterator =3D parents.iterator(); iterator.hasNext();= ) { + ObjectName parent =3D (ObjectName) iterator.next(); + Set children =3D (Set) parentToChildMap.get(parent); + if (children !=3D 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(ObjectName child, Set parents= ) { + Set existingParents =3D (Set) childToParentMap.get(child); + if (existingParents =3D=3D null) { + existingParents =3D new HashSet(parents); + childToParentMap.put(child, existingParents); + } else { + existingParents.addAll(parents); + } + + for (Iterator i =3D parents.iterator(); i.hasNext();) { + Object startParent =3D i.next(); + Set children =3D (Set) parentToChildMap.get(startParent); + if (children =3D=3D null) { + children =3D 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 dep= ends on; will never be null + */ + public synchronized Set getParents(ObjectName child) { + Set parents =3D (Set) childToParentMap.get(child); + if (parents =3D=3D null) { + return Collections.EMPTY_SET; + } + return new HashSet(parents); + } + + /** + * Gets all of the MBeans that have a dependency on the specified star= tParent. + * + * @param parent the component the returned childen set depend on + * @return a collection containing all of the components that depend o= n the parent; will never be null + */ + public synchronized Set getChildren(ObjectName parent) { + Set children =3D (Set) parentToChildMap.get(parent); + if (children =3D=3D null) { + return Collections.EMPTY_SET; + } + return new HashSet(children); + } + + /** + * Adds a hold on a collection of object name patterns. If the name o= f a component matches an object name + * pattern in the collection, the component should not start. + * + * @param objectName the name of the component placing the holds + * @param holds a collection of object name patterns which should not = start + */ + public synchronized void addStartHolds(ObjectName objectName, Collecti= on holds) { + Collection currentHolds =3D (Collection) startHoldsMap.get(objectN= ame); + if (currentHolds =3D=3D null) { + currentHolds =3D new LinkedList(holds); + startHoldsMap.put(objectName, currentHolds); + } else { + currentHolds.addAll(holds); + } + } + + /** + * Removes a collection of holds. + * + * @param objectName the object name of the components owning the holds + * @param holds a collection of the holds to remove + */ + public synchronized void removeStartHolds(ObjectName objectName, Colle= ction holds) { + Collection currentHolds =3D (Collection) startHoldsMap.get(objectN= ame); + if (currentHolds !=3D null) { + currentHolds.removeAll(holds); + } + } + + /** + * Removes all of the holds owned by a component. + * + * @param objectName the object name of the component that will no lon= ger have any holds + */ + public synchronized void removeAllStartHolds(ObjectName objectName) { + startHoldsMap.remove(objectName); + } + + /** + * Gets the object name of the mbean blocking the start specified mbea= n=2E + * + * @param objectName the mbean to check for blockers + * @return the mbean blocking the specified mbean, or null if there ar= e no blockers + */ + public synchronized ObjectName checkBlocker(ObjectName objectName) { + // check if objectName name is on one of the hold lists + for (Iterator iterator =3D startHoldsMap.keySet().iterator(); iter= ator.hasNext();) { + ObjectName blocker =3D (ObjectName) iterator.next(); + List holds =3D (List) startHoldsMap.get(blocker); + for (Iterator holdsIterator =3D holds.iterator(); holdsIterato= r=2EhasNext();) { + ObjectName pattern =3D (ObjectName) holdsIterator.next(); + if (pattern.apply(objectName)) { + return blocker; + } + } + } + return null; + } + + private class DependencyManagerLifecycleListener extends LifecycleAdap= ter { + public void unloaded(ObjectName objectName) { + synchronized (BasicDependencyManager.this) { + removeAllDependencies(objectName); + removeAllStartHolds(objectName); + } + + } + } +} Added: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/ba= sic/BasicKernel.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/o= rg/apache/geronimo/kernel/basic/BasicKernel.java?rev=3D169154&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/basic= /BasicKernel.java (added) +++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/basic= /BasicKernel.java Sun May 8 12:35:23 2005 @@ -0,0 +1,369 @@ +/** + * + * 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 implie= d=2E + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.geronimo.kernel.basic; + +import java.util.Date; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.Map; +import java.util.Set; +import javax.management.ObjectName; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.geronimo.gbean.GBeanData; +import org.apache.geronimo.gbean.GBeanInfo; +import org.apache.geronimo.gbean.GBeanName; +import org.apache.geronimo.gbean.runtime.GBeanInstance; +import org.apache.geronimo.kernel.DependencyManager; +import org.apache.geronimo.kernel.GBeanAlreadyExistsException; +import org.apache.geronimo.kernel.GBeanNotFoundException; +import org.apache.geronimo.kernel.InternalKernelException; +import org.apache.geronimo.kernel.Kernel; +import org.apache.geronimo.kernel.KernelGBean; +import org.apache.geronimo.kernel.KernelRegistry; +import org.apache.geronimo.kernel.NoSuchAttributeException; +import org.apache.geronimo.kernel.NoSuchOperationException; +import org.apache.geronimo.kernel.lifecycle.LifecycleMonitor; +import org.apache.geronimo.kernel.proxy.ProxyManager; + + +/** + * The core of a Geronimo instance. + * A Kernel is responsible for managing the Configurations that comprise a + * Geronimo system and exposing them using JMX. Each Kernel is associated + * with an MBeanServer that is used to register the Configurations themsel= ves + * and the MBeans they define. + *

+ * Dependencies between MBeans are handled by a dedicated DependencyManager + * that is responsible for tracking those dependencies and ensuring that t= he + * dependent objects follow the appropriate lifecycle and receive appropri= ate + * notifications. + *

+ * The Kernel also provides a ConfigurationStore which is used to stage + * installed Configurations (providing a local filesystem based classpath)= and + * used hold the persistent state of each Configuration. This allows + * Configurations to restart in the event of system failure. + *=20 + * TODO: Describe the order of method invocation (e.g. if loadGbean may be= before boot) + * + * @version $Rev: 154947 $ $Date: 2005-02-22 20:10:45 -0800 (Tue, 22 Feb 2= 005) $ + */ +public class BasicKernel implements Kernel { + /** + * Helper objects for invoke and getAttribute + */ + private static final String[] NO_TYPES =3D new String[0]; + private static final Object[] NO_ARGS =3D new Object[0]; + + /** + * Name of this kernel + */ + private final String kernelName; + + /** + * The log + */ + private Log log; + + /** + * Is this kernel running? + */ + private boolean running; + + /** + * The timestamp when the kernel was started + */ + private Date bootTime; + + /** + * The registry + */ + private final BasicRegistry registry; + + /** + * Listeners for when the kernel shutdown + */ + private LinkedList shutdownHooks =3D new LinkedList(); + + /** + * This manager is used by the kernel to manage dependencies between g= beans + */ + private DependencyManager dependencyManager; + + /** + * Monitors the lifecycle of all gbeans. + */ + private BasicLifecycleMonitor lifecycleMonitor; + private LifecycleMonitor publicLifecycleMonitor; + + /** + * This factory gbean proxies, and tracks all proxies in the system + */ + private ProxyManager proxyManager; + + /** + * Construct a Kernel with the specified name. + * + * @param kernelName the name of the kernel + */ + public BasicKernel(String kernelName) { + if (kernelName.indexOf(':') >=3D 0 || kernelName.indexOf('*') >=3D= 0 || kernelName.indexOf('?') >=3D 0) { + throw new IllegalArgumentException("Kernel name may not contai= n a ':', '*' or '?' character"); + } + this.kernelName =3D kernelName; + this.registry =3D new BasicRegistry(); + } + + public String getKernelName() { + return kernelName; + } + + /** + * @deprecated this will be removed as when we add generalized depende= ncies to gbeans... the only current user is Configuration + */ + public DependencyManager getDependencyManager() { + return dependencyManager; + } + + /** + * Gets the lifecycle monitor. + * @deprecated don't use this yet... it may change or go away + */ + public LifecycleMonitor getLifecycleMonitor() { + return publicLifecycleMonitor; + } + + /** + * Gets the proxy manager. + * @deprecated don't use this yet... it may change or go away + */ + public ProxyManager getProxyManager() { + return proxyManager; + } + + public Object getAttribute(ObjectName objectName, String attributeName= ) throws GBeanNotFoundException, NoSuchAttributeException, Exception { + GBeanInstance gbeanInstance =3D registry.getGBeanInstance(createGB= eanName(objectName)); + return gbeanInstance.getAttribute(attributeName); + } + + public void setAttribute(ObjectName objectName, String attributeName, = Object attributeValue) throws GBeanNotFoundException, NoSuchAttributeExcept= ion, Exception { + GBeanInstance gbeanInstance =3D registry.getGBeanInstance(createGB= eanName(objectName)); + gbeanInstance.setAttribute(attributeName, attributeValue); + } + + public Object invoke(ObjectName objectName, String methodName) throws = GBeanNotFoundException, NoSuchOperationException, InternalKernelException, = Exception { + return invoke(objectName, methodName, NO_ARGS, NO_TYPES); + } + + public Object invoke(ObjectName objectName, String methodName, Object[= ] args, String[] types) throws GBeanNotFoundException, NoSuchOperationExcep= tion, InternalKernelException, Exception { + GBeanInstance gbeanInstance =3D registry.getGBeanInstance(createGB= eanName(objectName)); + return gbeanInstance.invoke(methodName, args, types); + } + + public boolean isLoaded(ObjectName name) { + return registry.isRegistered(createGBeanName(name)); + } + + public GBeanInfo getGBeanInfo(ObjectName name) throws GBeanNotFoundExc= eption { + GBeanInstance gbeanInstance =3D registry.getGBeanInstance(createGB= eanName(name)); + return gbeanInstance.getGBeanInfo(); + } + + public GBeanData getGBeanData(ObjectName name) throws GBeanNotFoundExc= eption, InternalKernelException { + GBeanInstance gbeanInstance =3D registry.getGBeanInstance(createGB= eanName(name)); + return gbeanInstance.getGBeanData(); + } + + public void loadGBean(GBeanData gbeanData, ClassLoader classLoader) th= rows GBeanAlreadyExistsException, InternalKernelException { + ObjectName objectName =3D gbeanData.getName(); + GBeanInstance gbeanInstance =3D new GBeanInstance(gbeanData, this,= dependencyManager, lifecycleMonitor.createLifecycleBroadcaster(objectName)= , classLoader); + registry.register(gbeanInstance); + } + + public void startGBean(ObjectName name) throws GBeanNotFoundException,= InternalKernelException, IllegalStateException { + GBeanInstance gbeanInstance =3D registry.getGBeanInstance(createGB= eanName(name)); + gbeanInstance.start(); + } + + public void startRecursiveGBean(ObjectName name) throws GBeanNotFoundE= xception, InternalKernelException, IllegalStateException { + GBeanInstance gbeanInstance =3D registry.getGBeanInstance(createGB= eanName(name)); + gbeanInstance.startRecursive(); + } + + public void stopGBean(ObjectName name) throws GBeanNotFoundException, = InternalKernelException, IllegalStateException { + GBeanInstance gbeanInstance =3D registry.getGBeanInstance(createGB= eanName(name)); + gbeanInstance.stop(); + } + + public void unloadGBean(ObjectName name) throws GBeanNotFoundException= , InternalKernelException, IllegalStateException { + GBeanName gbeanName =3D createGBeanName(name); + GBeanInstance gbeanInstance =3D registry.getGBeanInstance(gbeanNam= e); + gbeanInstance.die(); + registry.unregister(gbeanName); + } + + public int getGBeanState(ObjectName name) throws GBeanNotFoundExceptio= n { + GBeanInstance gbeanInstance =3D registry.getGBeanInstance(createGB= eanName(name)); + return gbeanInstance.getState(); + } + + public long getGBeanStartTime(ObjectName name) throws GBeanNotFoundExc= eption { + GBeanInstance gbeanInstance =3D registry.getGBeanInstance(createGB= eanName(name)); + return gbeanInstance.getStartTime(); + } + + public boolean isGBeanEnabled(ObjectName name) throws GBeanNotFoundExc= eption { + GBeanInstance gbeanInstance =3D registry.getGBeanInstance(createGB= eanName(name)); + return gbeanInstance.isEnabled(); + } + + public void setGBeanEnabled(ObjectName name, boolean enabled) throws G= BeanNotFoundException { + GBeanInstance gbeanInstance =3D registry.getGBeanInstance(createGB= eanName(name)); + gbeanInstance.setEnabled(enabled); + } + + public Set listGBeans(ObjectName pattern) { + String domain =3D (pattern =3D=3D null || pattern.isDomainPattern(= )) ? null : pattern.getDomain(); + Map props =3D pattern =3D=3D null ? null : pattern.getKeyPropertyL= ist(); + Set gbeans =3D registry.listGBeans(domain, props); + Set result =3D new HashSet(gbeans.size()); + for (Iterator i =3D gbeans.iterator(); i.hasNext();) { + GBeanInstance instance =3D (GBeanInstance) i.next(); + result.add(instance.getObjectNameObject()); + } + return result; + } + + public Set listGBeans(Set patterns) { + Set gbeans =3D new HashSet(); + for (Iterator iterator =3D patterns.iterator(); iterator.hasNext()= ;) { + ObjectName pattern =3D (ObjectName) iterator.next(); + gbeans.addAll(listGBeans(pattern)); + } + return gbeans; + } + + /** + * Boot this Kernel, triggering the instantiation of the MBeanServer a= nd DependencyManager, + * and the registration of ConfigurationStore + * + * @throws java.lang.Exception if the boot fails + */ + public void boot() throws Exception { + if (running) { + return; + } + bootTime =3D new Date(); + log =3D LogFactory.getLog(BasicKernel.class.getName()); + log.info("Starting boot"); + + // todo cleanup when boot fails + KernelRegistry.registerKernel(this); + + registry.start(this); + + lifecycleMonitor =3D new BasicLifecycleMonitor(this); + publicLifecycleMonitor =3D new LifecycleMonitorFlyweight(lifecycle= Monitor); + dependencyManager =3D new BasicDependencyManager(publicLifecycleMo= nitor); + proxyManager =3D new BasicProxyManager(this); + + // load and start the kernel gbean + GBeanData kernelGBeanData =3D new GBeanData(KERNEL, KernelGBean.GB= EAN_INFO); + loadGBean(kernelGBeanData, getClass().getClassLoader()); + startGBean(KERNEL); + + running =3D true; + log.info("Booted"); + } + + public Date getBootTime() { + return bootTime; + } + + public void registerShutdownHook(Runnable hook) { + assert hook !=3D null : "Shutdown hook was null"; + synchronized (shutdownHooks) { + shutdownHooks.add(hook); + } + } + + public void unregisterShutdownHook(Runnable hook) { + synchronized (shutdownHooks) { + shutdownHooks.remove(hook); + } + } + + /** + * Shut down this kernel instance, unregistering the MBeans and releas= ing + * the MBeanServer. + */ + public void shutdown() { + if (!running) { + return; + } + running =3D false; + log.info("Starting kernel shutdown"); + + notifyShutdownHooks(); + + registry.stop(); + + dependencyManager.close(); + dependencyManager =3D null; + + synchronized (this) { + notify(); + } + + KernelRegistry.unregisterKernel(this); + + log.info("Kernel shutdown complete"); + } + + private void notifyShutdownHooks() { + while (!shutdownHooks.isEmpty()) { + Runnable hook; + synchronized (shutdownHooks) { + hook =3D (Runnable) shutdownHooks.removeFirst(); + } + try { + hook.run(); + } catch (Throwable e) { + log.warn("Error from kernel shutdown hook", e); + } + } + } + + public boolean isRunning() { + return running; + } + + public ClassLoader getClassLoaderFor(ObjectName name) throws GBeanNotF= oundException { + GBeanInstance gbeanInstance =3D registry.getGBeanInstance(createGB= eanName(name)); + return gbeanInstance.getClassLoader(); + } + + private GBeanName createGBeanName(ObjectName objectName) { + if (objectName.getDomain().length() =3D=3D 0) { + return new GBeanName(kernelName, objectName.getKeyPropertyList= ()); + } + return new GBeanName(objectName); + } +} Added: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/ba= sic/BasicKernelFactory.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/o= rg/apache/geronimo/kernel/basic/BasicKernelFactory.java?rev=3D169154&view= =3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/basic= /BasicKernelFactory.java (added) +++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/basic= /BasicKernelFactory.java Sun May 8 12:35:23 2005 @@ -0,0 +1,29 @@ +/** + * + * Copyright 2005 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 implie= d=2E + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geronimo.kernel.basic; + +import org.apache.geronimo.kernel.Kernel; +import org.apache.geronimo.kernel.KernelFactory; + +/** + * @version $Rev$ $Date$ + */ +public class BasicKernelFactory extends KernelFactory { + public Kernel createKernel(String kernelName) { + return new BasicKernel(kernelName); + } +}