dain 2004/06/05 13:33:40
Modified: modules/kernel/src/java/org/apache/geronimo/gbean/jmx
AbstractManagedObject.java SingleProxy.java
modules/kernel/src/java/org/apache/geronimo/kernel/config
Configuration.java ConfigurationManagerImpl.java
modules/kernel/src/java/org/apache/geronimo/kernel
Kernel.java
Added: modules/kernel/src/java/org/apache/geronimo/kernel
DependencyManager.java
Removed: modules/kernel/src/java/org/apache/geronimo/gbean/jmx
DependencyService.java DependencyServiceMBean.java
DependencyServiceProxy.java
Log:
DependencyService is no longer an mbean and is now accessable from the kernel
Renamed DependencyService to DependencyManager and moved it to kernel module
Revision Changes Path
1.12 +21 -12
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/AbstractManagedObject.java
Index: AbstractManagedObject.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/AbstractManagedObject.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- AbstractManagedObject.java 4 Jun 2004 22:31:56 -0000 1.11
+++ AbstractManagedObject.java 5 Jun 2004 20:33:40 -0000 1.12
@@ -40,6 +40,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.geronimo.gbean.WaitingException;
+import org.apache.geronimo.kernel.DependencyManager;
+import org.apache.geronimo.kernel.Kernel;
import org.apache.geronimo.kernel.jmx.JMXUtil;
import org.apache.geronimo.kernel.management.EventProvider;
import org.apache.geronimo.kernel.management.ManagedObject;
@@ -73,9 +75,9 @@
private final Set notificationTypes = new HashSet();
/**
- * A dynamic proxy to the dependency service.
+ * The dependency manager
*/
- private DependencyServiceMBean dependencyService;
+ private DependencyManager dependencyManager;
/**
* The sequence number of the events.
@@ -141,7 +143,14 @@
public synchronized ObjectName preRegister(MBeanServer server,
ObjectName objectName) throws Exception {
this.server = server;
this.objectName = objectName;
- dependencyService = new DependencyServiceProxy(server);
+ Kernel kernel;
+ try {
+ String kernelName = (String) server.getAttribute(Kernel.KERNEL,
"KernelName");
+ kernel = Kernel.getKernel(kernelName);
+ } catch (Exception e) {
+ throw new IllegalStateException("No kernel is registered in this
MBeanServer");
+ }
+ dependencyManager = kernel.getDependencyManager();
return objectName;
}
@@ -159,7 +168,7 @@
synchronized (this) {
server = null;
objectName = null;
- dependencyService = null;
+ dependencyManager = null;
}
}
@@ -175,8 +184,8 @@
return objectName;
}
- public DependencyServiceMBean getDependencyService() {
- return dependencyService;
+ public DependencyManager getDependencyManager() {
+ return dependencyManager;
}
public final boolean isStateManageable() {
@@ -294,7 +303,7 @@
start();
// startRecursive all of objects that depend on me
- Set dependents = dependencyService.getChildren(objectName);
+ Set dependents = dependencyManager.getChildren(objectName);
for (Iterator iterator = dependents.iterator(); iterator.hasNext();)
{
ObjectName dependent = (ObjectName) iterator.next();
try {
@@ -335,7 +344,7 @@
// Don't try to stop dependents from within a synchronized block...
this should reduce deadlocks
// stop all of my dependent objects
- Set dependents = dependencyService.getChildren(objectName);
+ Set dependents = dependencyManager.getChildren(objectName);
for (Iterator iterator = dependents.iterator(); iterator.hasNext();)
{
ObjectName child = (ObjectName) iterator.next();
try {
@@ -396,7 +405,7 @@
}
// check if an mbean is blocking us from starting
- blocker = dependencyService.checkBlocker(objectName);
+ blocker = dependencyManager.checkBlocker(objectName);
if (blocker != null) {
try {
// register for state change with the blocker
@@ -419,7 +428,7 @@
}
// check if all of the mbeans we depend on are running
- Set parents = dependencyService.getParents(objectName);
+ Set parents = dependencyManager.getParents(objectName);
for (Iterator i = parents.iterator(); i.hasNext();) {
ObjectName parent = (ObjectName) i.next();
if (!server.isRegistered(parent)) {
@@ -511,7 +520,7 @@
}
try {
// check if all of the mbeans depending on us are stopped
- Set children = dependencyService.getChildren(objectName);
+ Set children = dependencyManager.getChildren(objectName);
for (Iterator i = children.iterator(); i.hasNext();) {
ObjectName child = (ObjectName) i.next();
if (server.isRegistered(child)) {
1.13 +7 -7
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/SingleProxy.java
Index: SingleProxy.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/SingleProxy.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- SingleProxy.java 2 Jun 2004 06:49:23 -0000 1.12
+++ SingleProxy.java 5 Jun 2004 20:33:40 -0000 1.13
@@ -104,7 +104,7 @@
if (targets.size() == 1) {
// will be more then one target... remove the dependency
ObjectName currentTarget = (ObjectName)
targets.iterator().next();
-
gmbean.getDependencyService().removeDependency(gmbean.getObjectNameObject(),
currentTarget);
+
gmbean.getDependencyManager().removeDependency(gmbean.getObjectNameObject(),
currentTarget);
}
targets.add(target);
@@ -114,7 +114,7 @@
gmbean.fail();
} else if (targets.size() == 1) {
// there is now just one target... add a dependency
-
gmbean.getDependencyService().addDependency(gmbean.getObjectNameObject(),
target);
+
gmbean.getDependencyManager().addDependency(gmbean.getObjectNameObject(),
target);
if (waitingForMe) {
attemptFullStart();
}
@@ -132,14 +132,14 @@
} else if (targets.size() == 1) {
// we only have one target remaining... add a dependency
ObjectName remainingTarget = (ObjectName)
targets.iterator().next();
-
gmbean.getDependencyService().addDependency(gmbean.getObjectNameObject(),
remainingTarget);
+
gmbean.getDependencyManager().addDependency(gmbean.getObjectNameObject(),
remainingTarget);
if (waitingForMe) {
attemptFullStart();
}
} else if (targets.isEmpty()) {
// that was our last target... remove the dependency
-
gmbean.getDependencyService().removeDependency(gmbean.getObjectNameObject(),
target);
+
gmbean.getDependencyManager().removeDependency(gmbean.getObjectNameObject(),
target);
}
}
@@ -169,13 +169,13 @@
throw new WaitingException("More then one targets are running
for " + name + " reference");
}
waitingForMe = false;
-
gmbean.getDependencyService().addStartHolds(gmbean.getObjectNameObject(),
patterns);
+
gmbean.getDependencyManager().addStartHolds(gmbean.getObjectNameObject(),
patterns);
methodInterceptor.connect(gmbean.getServer(), (ObjectName)
targets.iterator().next());
}
public synchronized void stop() {
waitingForMe = false;
methodInterceptor.disconnect();
-
gmbean.getDependencyService().removeStartHolds(gmbean.getObjectNameObject(),
patterns);
+
gmbean.getDependencyManager().removeStartHolds(gmbean.getObjectNameObject(),
patterns);
}
}
1.24 +3 -8
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java
Index: Configuration.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- Configuration.java 5 Jun 2004 07:53:22 -0000 1.23
+++ Configuration.java 5 Jun 2004 20:33:40 -0000 1.24
@@ -185,7 +185,7 @@
}
throw e;
}
- mbServer.invoke(Kernel.DEPENDENCY_SERVICE, "addDependency",
new Object[]{name, objectName}, new String[]{ObjectName.class.getName(),
ObjectName.class.getName()});
+ kernel.getDependencyManager().addDependency(name,
objectName);
}
} finally {
Thread.currentThread().setContextClassLoader(oldCl);
@@ -201,12 +201,7 @@
MBeanServer mbServer = kernel.getMBeanServer();
for (Iterator i = gbeans.keySet().iterator(); i.hasNext();) {
ObjectName name = (ObjectName) i.next();
- try {
- mbServer.invoke(Kernel.DEPENDENCY_SERVICE,
"removeDependency", new Object[]{name, objectName}, new
String[]{ObjectName.class.getName(), ObjectName.class.getName()});
- } catch (Exception e) {
- // ignore
- log.warn("Could not remove dependency for child " + name, e);
- }
+ kernel.getDependencyManager().removeDependency(name, objectName);
try {
log.trace("Unregistering GBean " + name);
mbServer.unregisterMBean(name);
1.8 +1 -1
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationManagerImpl.java
Index: ConfigurationManagerImpl.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationManagerImpl.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
1.37 +14 -17
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java
Index: Kernel.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- Kernel.java 5 Jun 2004 19:30:43 -0000 1.36
+++ Kernel.java 5 Jun 2004 20:33:40 -0000 1.37
@@ -42,7 +42,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.geronimo.gbean.jmx.DependencyService;
import org.apache.geronimo.gbean.jmx.GBeanMBean;
import org.apache.geronimo.kernel.config.ConfigurationManager;
import org.apache.geronimo.kernel.config.ConfigurationManagerImpl;
@@ -59,7 +58,7 @@
* with an MBeanServer that is used to register the Configurations themselves
* and the MBeans they define.
* <p/>
- * Dependencies between MBeans are handled by a dedicated DependencyService
+ * Dependencies between MBeans are handled by a dedicated DependencyManager
* that is responsible for tracking those dependencies and ensuring that the
* dependent objects follow the appropriate lifecycle and receive appropriate
* notifications.
@@ -78,12 +77,6 @@
*/
public static final ObjectName KERNEL =
JMXUtil.getObjectName("geronimo.boot:role=Kernel");
- /**
- * The JMX name of the DependencyService.
- */
- public static final ObjectName DEPENDENCY_SERVICE =
JMXUtil.getObjectName("geronimo.boot:role=DependencyService");
-
-
private static final Map kernels = new HashMap();
private static final ReferenceQueue queue = new ReferenceQueue();
private final String kernelName;
@@ -94,6 +87,8 @@
private MBeanServer mbServer;
private LinkedList shutdownHooks = new LinkedList();
+ private DependencyManager dependencyManager;
+
private ConfigurationManager configurationManager;
private GBeanMBean configurationManagerGBean;
@@ -183,6 +178,10 @@
}
}
+ public DependencyManager getDependencyManager() {
+ return dependencyManager;
+ }
+
public ConfigurationManager getConfigurationManager() {
return configurationManager;
}
@@ -331,8 +330,8 @@
}
/**
- * Boot this Kernel, triggering the instantiation of the MBeanServer and
- * the registration of the DependencyService and ConfigurationStore
+ * Boot this Kernel, triggering the instantiation of the MBeanServer and
DependencyManager,
+ * and the registration ConfigurationStore
*
* @throws java.lang.Exception if the boot fails
*/
@@ -352,7 +351,7 @@
mbServer = MBeanServerFactory.createMBeanServer(domainName);
mbServer.registerMBean(this, KERNEL);
- mbServer.registerMBean(new DependencyService(), DEPENDENCY_SERVICE);
+ dependencyManager = new DependencyManager(mbServer);
configurationManagerGBean = new
GBeanMBean(ConfigurationManagerImpl.GBEAN_INFO);
configurationManagerGBean.setReferencePatterns("Stores",
Collections.singleton(CONFIGURATION_STORE_PATTERN));
@@ -396,11 +395,9 @@
} catch (Exception e) {
// ignore
}
- try {
- mbServer.unregisterMBean(DEPENDENCY_SERVICE);
- } catch (Exception e) {
- // ignore
- }
+
+ dependencyManager.close();
+ dependencyManager = null;
MBeanServerFactory.releaseMBeanServer(mbServer);
mbServer = null;
1.1
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/DependencyManager.java
Index: DependencyManager.java
===================================================================
/**
*
* Copyright 2003-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.kernel;
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.JMException;
import javax.management.MBeanServer;
import javax.management.MBeanServerNotification;
import javax.management.Notification;
import javax.management.NotificationFilterSupport;
import javax.management.NotificationListener;
import javax.management.ObjectName;
import org.apache.geronimo.kernel.jmx.JMXUtil;
/**
* 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 $Revision: 1.1 $ $Date: 2004/06/05 20:33:40 $
* @jmx:mbean
*/
public class DependencyManager implements NotificationListener {
/**
* The mbean server we are registered with.
*/
private MBeanServer mbeanServer;
/**
* 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();
/**
* A map from a component's ObjectName to the list of ObjectPatterns that
the component is blocking
* from starting.
*/
private final Map startHoldsMap = new HashMap();
public DependencyManager(MBeanServer mbeanServer) throws Exception {
assert mbeanServer != null;
this.mbeanServer = mbeanServer;
NotificationFilterSupport mbeanServerFilter = new
NotificationFilterSupport();
mbeanServerFilter.enableType(MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
mbeanServer.addNotificationListener(JMXUtil.DELEGATE_NAME, this,
mbeanServerFilter, null);
}
public synchronized void close() {
try {
mbeanServer.removeNotificationListener(JMXUtil.DELEGATE_NAME,
this);
} catch (JMException ignored) {
// no big deal... just good citizen clean up code
}
mbeanServer = null;
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
* @jmx:managed-operation
*/
public synchronized void addDependency(ObjectName child, ObjectName
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
* @jmx:managed-operation
*/
public synchronized void removeDependency(ObjectName child, ObjectName
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
* @jmx:managed-operation
*/
public synchronized void removeAllDependencies(ObjectName 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
* @jmx:managed-operation
*/
public synchronized void addDependencies(ObjectName 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
* @jmx:managed-operation
*/
public synchronized Set getParents(ObjectName child) {
Set parents = (Set) childToParentMap.get(child);
if (parents == null) {
return Collections.EMPTY_SET;
}
return 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
* @jmx:managed-operation
*/
public synchronized Set getChildren(ObjectName parent) {
Set children = (Set) parentToChildMap.get(parent);
if (children == null) {
return Collections.EMPTY_SET;
}
return children;
}
/**
* Adds a hold on a collection of object name patterns. If the name of 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
* @jmx:managed-operation
*/
public synchronized void addStartHolds(ObjectName objectName, Collection
holds) {
Collection currentHolds = (Collection) startHoldsMap.get(objectName);
if (currentHolds == null) {
currentHolds = 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
* @jmx:managed-operation
*/
public synchronized void removeStartHolds(ObjectName objectName,
Collection holds) {
Collection currentHolds = (Collection) startHoldsMap.get(objectName);
if (currentHolds != null) {
currentHolds.removeAll(holds);
}
}
/**
* Removes all of the holds owned by a component.
*
* @param objectName the object name of the component that will no longer
have any holds
* @jmx:managed-operation
*/
public synchronized void removeAllStartHolds(ObjectName objectName) {
startHoldsMap.remove(objectName);
}
/**
* Gets the object name of the mbean blocking the start specified mbean.
*
* @param objectName the mbean to check for blockers
* @return the mbean blocking the specified mbean, or null if there are
no blockers
* @jmx:managed-operation
*/
public synchronized ObjectName checkBlocker(ObjectName objectName) {
// check if objectName name is on one of the hold lists
for (Iterator iterator = startHoldsMap.keySet().iterator();
iterator.hasNext();) {
ObjectName blocker = (ObjectName) iterator.next();
List holds = (List) startHoldsMap.get(blocker);
for (Iterator holdsIterator = holds.iterator();
holdsIterator.hasNext();) {
ObjectName pattern = (ObjectName) holdsIterator.next();
if (pattern.apply(objectName)) {
return blocker;
}
}
}
return null;
}
public void handleNotification(Notification n, Object handback) {
String type = n.getType();
if (MBeanServerNotification.UNREGISTRATION_NOTIFICATION.equals(type))
{
MBeanServerNotification notification = (MBeanServerNotification)
n;
ObjectName source = notification.getMBeanName();
synchronized (this) {
removeAllDependencies(source);
removeAllStartHolds(source);
}
}
}
}