geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r395753 - in /geronimo/branches/1.1/modules: kernel/src/java/org/apache/geronimo/kernel/ kernel/src/java/org/apache/geronimo/kernel/basic/ system/src/java/org/apache/geronimo/system/jmx/
Date Fri, 21 Apr 2006 01:45:59 GMT
Author: dain
Date: Thu Apr 20 18:45:55 2006
New Revision: 395753

URL: http://svn.apache.org/viewcvs?rev=395753&view=rev
Log:
Cleaned up ObjectName handling in the jmx bridges.

Modified:
    geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java
    geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/KernelGBean.java
    geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/basic/BasicKernel.java
    geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/jmx/KernelDelegate.java
    geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/jmx/KernelMBeanServer.java
    geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/jmx/MBeanGBeanBridge.java
    geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/jmx/MBeanServerKernelBridge.java

Modified: geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java?rev=395753&r1=395752&r2=395753&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java (original)
+++ geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java Thu
Apr 20 18:45:55 2006
@@ -346,10 +346,6 @@
     /**
      * @deprecated Use AbstractName version instead
      */
-    boolean isLoaded(ObjectName name);
-    /**
-     * @deprecated Use AbstractName version instead
-     */
     Object getGBean(ObjectName name) throws GBeanNotFoundException, InternalKernelException,
IllegalStateException;
     /**
      * @deprecated Use AbstractName version instead

Modified: geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/KernelGBean.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/KernelGBean.java?rev=395753&r1=395752&r2=395753&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/KernelGBean.java
(original)
+++ geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/KernelGBean.java
Thu Apr 20 18:45:55 2006
@@ -62,10 +62,6 @@
         kernel.loadGBean(gbeanData, classLoader);
     }
 
-    public boolean isLoaded(ObjectName name) {
-        return kernel.isLoaded(name);
-    }
-
     public boolean isLoaded(AbstractName name) {
         return kernel.isLoaded(name);
     }

Modified: geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/basic/BasicKernel.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/basic/BasicKernel.java?rev=395753&r1=395752&r2=395753&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/basic/BasicKernel.java
(original)
+++ geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/basic/BasicKernel.java
Thu Apr 20 18:45:55 2006
@@ -257,10 +257,6 @@
         return gbeanInstance.invoke(methodName, args, types);
     }
 
-    public boolean isLoaded(ObjectName name) {
-        return registry.isRegistered(name);
-    }
-
     public boolean isLoaded(AbstractName name) {
         return registry.isRegistered(name);
     }

Modified: geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/jmx/KernelDelegate.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/jmx/KernelDelegate.java?rev=395753&r1=395752&r2=395753&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/jmx/KernelDelegate.java
(original)
+++ geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/jmx/KernelDelegate.java
Thu Apr 20 18:45:55 2006
@@ -605,16 +605,6 @@
         return invokeKernel("invoke", new Object[]{shortName, type, methodName, args, types},
new String[]{String.class.getName(), Class.class.getName(), String.class.getName(), Object[].class.getName(),
String[].class.getName()});
     }
 
-    public boolean isLoaded(ObjectName name) {
-        try {
-            return ((Boolean) invokeKernel("isLoaded", new Object[]{name}, new String[]{ObjectName.class.getName()})).booleanValue();
-        } catch (RuntimeException e) {
-            throw e;
-        } catch (Exception e) {
-            throw new InternalKernelException(e);
-        }
-    }
-
     public boolean isLoaded(AbstractName name) {
         try {
             return ((Boolean) invokeKernel("isLoaded", new Object[]{name}, new String[]{AbstractName.class.getName()})).booleanValue();

Modified: geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/jmx/KernelMBeanServer.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/jmx/KernelMBeanServer.java?rev=395753&r1=395752&r2=395753&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/jmx/KernelMBeanServer.java
(original)
+++ geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/jmx/KernelMBeanServer.java
Thu Apr 20 18:45:55 2006
@@ -20,6 +20,9 @@
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
+import java.util.HashMap;
+import java.util.Collections;
+import java.util.LinkedHashSet;
 import javax.management.Attribute;
 import javax.management.AttributeList;
 import javax.management.AttributeNotFoundException;
@@ -38,30 +41,85 @@
 import javax.management.OperationsException;
 import javax.management.QueryExp;
 import javax.management.ReflectionException;
+import javax.management.MalformedObjectNameException;
 import javax.management.loading.ClassLoaderRepository;
 
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.AbstractNameQuery;
+import org.apache.geronimo.gbean.AbstractName;
 import org.apache.geronimo.kernel.GBeanNotFoundException;
 import org.apache.geronimo.kernel.InternalKernelException;
 import org.apache.geronimo.kernel.NoSuchAttributeException;
 import org.apache.geronimo.kernel.NoSuchOperationException;
 import org.apache.geronimo.kernel.Kernel;
- 
+import org.apache.geronimo.kernel.lifecycle.LifecycleAdapter;
+
 /**
  * A fake MBeanServer that delegates to a Kernel.
  * @version $Rev$ $Date$
  */
 public class KernelMBeanServer implements MBeanServer {
+    private static final AbstractNameQuery ALL = new AbstractNameQuery(null, Collections.EMPTY_MAP,
Collections.EMPTY_SET);
+
+    private final HashMap objetNameToAbstractName = new HashMap();
     private final Kernel kernel;
 
     public KernelMBeanServer(Kernel kernel) {
         this.kernel = kernel;
     }
 
+    public void doStart() {
+        kernel.getLifecycleMonitor().addLifecycleListener(new GBeanRegistrationListener(),
ALL);
+
+        Set allNames = kernel.listGBeans(ALL);
+        for (Iterator iterator = allNames.iterator(); iterator.hasNext();) {
+            AbstractName abstractName = (AbstractName) iterator.next();
+            register(abstractName);
+        }
+    }
+
+    public synchronized AbstractName getAbstractNameFor(ObjectName objectName) {
+        return (AbstractName) objetNameToAbstractName.get(objectName);
+    }
+
+    private synchronized void register(AbstractName abstractName) {
+        objetNameToAbstractName.put(abstractName.getObjectName(), abstractName);
+    }
+
+    private synchronized void unregister(AbstractName abstractName) {
+        objetNameToAbstractName.remove(abstractName.getObjectName());
+    }
+
+    public void doFail() {
+        doStop();
+    }
+
+    public synchronized void doStop() {
+        objetNameToAbstractName.clear();
+    }
+
+    private class GBeanRegistrationListener extends LifecycleAdapter {
+        public void loaded(AbstractName abstractName) {
+            register(abstractName);
+        }
+
+        public void unloaded(AbstractName abstractName) {
+            unregister(abstractName);
+        }
+    }
+
+    public AbstractName toAbstractName(ObjectName objectName) throws InstanceNotFoundException{
+        AbstractName abstractName = getAbstractNameFor(objectName);
+        if (abstractName == null) {
+            throw new InstanceNotFoundException(objectName.getCanonicalName());
+        }
+        return abstractName;
+    }
+
     public Object getAttribute(ObjectName name, String attribute) throws MBeanException,
AttributeNotFoundException, InstanceNotFoundException, ReflectionException {
+        AbstractName abstractName = toAbstractName(name);
         try {
-            return kernel.getAttribute(name, attribute);
+            return kernel.getAttribute(abstractName, attribute);
         } catch (NoSuchAttributeException e) {
             throw new AttributeNotFoundException(attribute);
         } catch (GBeanNotFoundException e) {
@@ -74,11 +132,12 @@
     }
 
     public AttributeList getAttributes(ObjectName name, String[] attributes) throws InstanceNotFoundException,
ReflectionException {
+        AbstractName abstractName = toAbstractName(name);
         AttributeList attributeList = new AttributeList(attributes.length);
         for (int i = 0; i < attributes.length; i++) {
             String attribute = attributes[i];
             try {
-                Object value = kernel.getAttribute(name, attribute);
+                Object value = kernel.getAttribute(abstractName, attribute);
                 attributeList.add(i, new Attribute(attribute, value));
             } catch (NoSuchAttributeException e) {
                 // ignored - caller will simply find no value
@@ -102,9 +161,10 @@
     }
 
     public MBeanInfo getMBeanInfo(ObjectName name) throws InstanceNotFoundException, ReflectionException
{
+        AbstractName abstractName = toAbstractName(name);
         GBeanInfo gbeanInfo;
         try {
-            gbeanInfo = kernel.getGBeanInfo(name);
+            gbeanInfo = kernel.getGBeanInfo(abstractName);
         } catch (GBeanNotFoundException e) {
             throw new InstanceNotFoundException(name.toString());
         } catch (InternalKernelException e) {
@@ -114,8 +174,9 @@
     }
 
     public Object invoke(ObjectName name, String operationName, Object[] params, String[]
signature) throws InstanceNotFoundException, MBeanException, ReflectionException {
+        AbstractName abstractName = toAbstractName(name);
         try {
-            return kernel.invoke(name, operationName, params, signature);
+            return kernel.invoke(abstractName, operationName, params, signature);
         } catch (NoSuchOperationException e) {
             throw new ReflectionException(new NoSuchMethodException(e.getMessage()));
         } catch (GBeanNotFoundException e) {
@@ -131,30 +192,50 @@
     }
 
     public boolean isRegistered(ObjectName name) {
-        return kernel.isLoaded(name);
+        AbstractName abstractName = getAbstractNameFor(name);
+        if (abstractName == null) {
+            return false;
+        }
+        return kernel.isLoaded(abstractName);
     }
 
     public Set queryNames(ObjectName pattern, QueryExp query) {
-        Set names = kernel.listGBeans(pattern);
-        if (query == null) {
-            return names;
+        // normalize the name
+        if (pattern != null && pattern.getDomain().length() == 0) {
+            try {
+                pattern = new ObjectName(kernel.getKernelName(), pattern.getKeyPropertyList());
+            } catch (MalformedObjectNameException e) {
+                throw new AssertionError(e);
+            }
         }
 
-        Set filteredNames = new HashSet(names.size());
-        for (Iterator iterator = names.iterator(); iterator.hasNext();) {
-            // this must be done for each objectName applied
-            query.setMBeanServer(this);
+        Set names;
+        synchronized (this) {
+            names = new LinkedHashSet(objetNameToAbstractName.keySet());
+        }
 
+        // fairly dumb implementation that iterates the list of all registered GBeans
+        Set result = new HashSet(names.size());
+        for (Iterator iterator = names.iterator(); iterator.hasNext();) {
             ObjectName name = (ObjectName) iterator.next();
-            try {
-                if (query.apply(name)) {
-                    filteredNames.add(name);
+            if (pattern == null || pattern.apply(name)) {
+                if (query != null) {
+                    query.setMBeanServer(this);
+
+                    try {
+                        if (query.apply(name)) {
+                            result.add(name);
+                        }
+                    } catch (Exception e) {
+                        // reject any name that threw an exception
+                    }
+                } else {
+                    result.add(name);
                 }
-            } catch (Exception e) {
-                // reject any name that threw an exception
             }
         }
-        return filteredNames;
+
+        return result;
     }
 
     public Set queryMBeans(ObjectName pattern, QueryExp query) {
@@ -172,10 +253,11 @@
     }
 
     public void setAttribute(ObjectName name, Attribute attribute) throws InstanceNotFoundException,
AttributeNotFoundException, MBeanException {
+        AbstractName abstractName = toAbstractName(name);
         String attributeName = attribute.getName();
         Object attributeValue = attribute.getValue();
         try {
-            kernel.setAttribute(name, attributeName, attributeValue);
+            kernel.setAttribute(abstractName, attributeName, attributeValue);
         } catch (NoSuchAttributeException e) {
             throw new AttributeNotFoundException(attributeName);
         } catch (GBeanNotFoundException e) {
@@ -188,13 +270,14 @@
     }
 
     public AttributeList setAttributes(ObjectName name, AttributeList attributes) throws
InstanceNotFoundException, ReflectionException {
+        AbstractName abstractName = toAbstractName(name);
         AttributeList set = new AttributeList(attributes.size());
         for (Iterator iterator = attributes.iterator(); iterator.hasNext();) {
             Attribute attribute = (Attribute) iterator.next();
             String attributeName = attribute.getName();
             Object attributeValue = attribute.getValue();
             try {
-                kernel.setAttribute(name, attributeName, attributeValue);
+                kernel.setAttribute(abstractName, attributeName, attributeValue);
                 set.add(attribute);
             } catch (NoSuchAttributeException e) {
                 // ignored - caller will see value was not set because this attribute will
not be in the attribute list
@@ -211,7 +294,7 @@
 
     public String[] getDomains() {
         Set domains = new HashSet();
-        Set names = kernel.listGBeans((ObjectName)null);
+        Set names = kernel.listGBeans((AbstractNameQuery)null);
         for (Iterator iterator = names.iterator(); iterator.hasNext();) {
             ObjectName objectName = (ObjectName) iterator.next();
             domains.add(objectName.getDomain());
@@ -220,8 +303,9 @@
     }
 
     public ObjectInstance getObjectInstance(ObjectName objectName) throws InstanceNotFoundException
{
+        AbstractName abstractName = toAbstractName(objectName);
         try {
-            GBeanInfo gbeanInfo = kernel.getGBeanInfo(objectName);
+            GBeanInfo gbeanInfo = kernel.getGBeanInfo(abstractName);
             return new ObjectInstance(objectName, gbeanInfo.getClassName());
         } catch (GBeanNotFoundException e) {
             throw new InstanceNotFoundException(objectName.getCanonicalName());
@@ -229,8 +313,9 @@
     }
 
     public ClassLoader getClassLoaderFor(ObjectName objectName) throws InstanceNotFoundException
{
+        AbstractName abstractName = toAbstractName(objectName);
         try {
-            return kernel.getClassLoaderFor(objectName);
+            return kernel.getClassLoaderFor(abstractName);
         } catch (GBeanNotFoundException e) {
             throw new InstanceNotFoundException(objectName.getCanonicalName());
         }

Modified: geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/jmx/MBeanGBeanBridge.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/jmx/MBeanGBeanBridge.java?rev=395753&r1=395752&r2=395753&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/jmx/MBeanGBeanBridge.java
(original)
+++ geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/jmx/MBeanGBeanBridge.java
Thu Apr 20 18:45:55 2006
@@ -48,7 +48,7 @@
 import org.apache.geronimo.kernel.management.NotificationType;
 
 /**
- * @version $Rev$ $Date$
+ * @version $Rev: 383682 $ $Date$
  */
 public final class MBeanGBeanBridge implements MBeanRegistration, DynamicMBean, NotificationEmitter
{
     private static final Log log = LogFactory.getLog(MBeanGBeanBridge.class);
@@ -61,7 +61,8 @@
     /**
      * The unique name of this service.
      */
-    private final AbstractName objectName;
+    private final AbstractName abstractName;
+    private final ObjectName objectName;
     private final AbstractNameQuery pattern;
 
     /**
@@ -75,16 +76,17 @@
     private final NotificationBroadcasterSupport notificationBroadcaster = new NotificationBroadcasterSupport();
     private final LifecycleBridge lifecycleBridge;
 
-    public MBeanGBeanBridge(Kernel kernel, AbstractName abstractName, MBeanInfo mbeanInfo)
{
+    public MBeanGBeanBridge(Kernel kernel, AbstractName abstractName, ObjectName objectName,
MBeanInfo mbeanInfo) {
         this.kernel = kernel;
-        this.objectName = abstractName;
+        this.abstractName = abstractName;
         this.pattern = new AbstractNameQuery(abstractName);
         this.mbeanInfo = mbeanInfo;
-        lifecycleBridge = new LifecycleBridge(abstractName, notificationBroadcaster);
+        this.objectName = objectName;
+        lifecycleBridge = new LifecycleBridge(abstractName, objectName, notificationBroadcaster);
     }
 
     public ObjectName getObjectName() {
-        return objectName.getObjectName();
+        return objectName;
     }
 
     public ObjectName preRegister(MBeanServer mBeanServer, ObjectName objectName) throws
Exception {
@@ -95,13 +97,13 @@
         if (Boolean.TRUE.equals(registrationDone)) {
             // fire the loaded event from the gbeanMBean.. it was already fired from the
GBeanInstance when it was created
             kernel.getLifecycleMonitor().addLifecycleListener(lifecycleBridge, pattern);
-            lifecycleBridge.loaded(objectName);
+            lifecycleBridge.loaded(abstractName);
         }
     }
 
     public void preDeregister() {
         kernel.getLifecycleMonitor().removeLifecycleListener(lifecycleBridge);
-        lifecycleBridge.unloaded(objectName);
+        lifecycleBridge.unloaded(abstractName);
     }
 
     public void postDeregister() {
@@ -113,7 +115,7 @@
 
     public Object getAttribute(String attributeName) throws ReflectionException, AttributeNotFoundException
{
         try {
-            return kernel.getAttribute(objectName, attributeName);
+            return kernel.getAttribute(abstractName, attributeName);
         } catch (NoSuchAttributeException e) {
             throw new AttributeNotFoundException(attributeName);
         } catch (Exception e) {
@@ -125,7 +127,7 @@
         String attributeName = attribute.getName();
         Object attributeValue = attribute.getValue();
         try {
-            kernel.setAttribute(objectName, attributeName, attributeValue);
+            kernel.setAttribute(abstractName, attributeName, attributeValue);
         } catch (NoSuchAttributeException e) {
             throw new AttributeNotFoundException(attributeName);
         } catch (Exception e) {
@@ -163,7 +165,7 @@
 
     public Object invoke(String operationName, Object[] arguments, String[] types) throws
ReflectionException {
         try {
-            return kernel.invoke(objectName, operationName, arguments, types);
+            return kernel.invoke(abstractName, operationName, arguments, types);
         } catch (NoSuchOperationException e) {
             throw new ReflectionException(new NoSuchMethodException(new GOperationSignature(operationName,
types).toString()));
         } catch (Exception e) {
@@ -190,7 +192,7 @@
     }
 
     public String toString() {
-        return objectName.toString();
+        return abstractName.toString();
     }
 
     private static class LifecycleBridge implements LifecycleListener {
@@ -200,59 +202,65 @@
         private long sequence;
 
         /**
-         * Name of the MBeanGBean
+         * AbstractName of this MBean
+         */
+        private final AbstractName mbeanAbstractName;
+
+        /**
+         * ObjectName of this MBean
          */
-        private final AbstractName mbeanGBeanName;
+        private final ObjectName objectName;
 
         /**
          * The notification broadcaster to use
          */
         private final NotificationBroadcasterSupport notificationBroadcaster;
 
-        public LifecycleBridge(AbstractName mbeanGBeanName, NotificationBroadcasterSupport
notificationBroadcaster) {
-            this.mbeanGBeanName = mbeanGBeanName;
+        public LifecycleBridge(AbstractName mbeanAbstractName, ObjectName objectName, NotificationBroadcasterSupport
notificationBroadcaster) {
+            this.mbeanAbstractName = mbeanAbstractName;
+            this.objectName = objectName;
             this.notificationBroadcaster = notificationBroadcaster;
         }
 
         public void loaded(AbstractName abstractName) {
-            if (mbeanGBeanName.equals(abstractName)) {
-                notificationBroadcaster.sendNotification(new Notification(NotificationType.OBJECT_CREATED,
abstractName.getObjectName(), nextSequence()));
+            if (mbeanAbstractName.equals(abstractName)) {
+                notificationBroadcaster.sendNotification(new Notification(NotificationType.OBJECT_CREATED,
objectName, nextSequence()));
             }
         }
 
         public void starting(AbstractName abstractName) {
-            if (mbeanGBeanName.equals(abstractName)) {
-                notificationBroadcaster.sendNotification(new Notification(NotificationType.STATE_STARTING,
abstractName.getObjectName(), nextSequence()));
+            if (mbeanAbstractName.equals(abstractName)) {
+                notificationBroadcaster.sendNotification(new Notification(NotificationType.STATE_STARTING,
objectName, nextSequence()));
             }
         }
 
         public void running(AbstractName abstractName) {
-            if (mbeanGBeanName.equals(abstractName)) {
-                notificationBroadcaster.sendNotification(new Notification(NotificationType.STATE_RUNNING,
abstractName.getObjectName(), nextSequence()));
+            if (mbeanAbstractName.equals(abstractName)) {
+                notificationBroadcaster.sendNotification(new Notification(NotificationType.STATE_RUNNING,
objectName, nextSequence()));
             }
         }
 
         public void stopping(AbstractName abstractName) {
-            if (mbeanGBeanName.equals(abstractName)) {
-                notificationBroadcaster.sendNotification(new Notification(NotificationType.STATE_STOPPING,
abstractName.getObjectName(), nextSequence()));
+            if (mbeanAbstractName.equals(abstractName)) {
+                notificationBroadcaster.sendNotification(new Notification(NotificationType.STATE_STOPPING,
objectName, nextSequence()));
             }
         }
 
         public void stopped(AbstractName abstractName) {
-            if (mbeanGBeanName.equals(abstractName)) {
-                notificationBroadcaster.sendNotification(new Notification(NotificationType.STATE_STOPPED,
abstractName.getObjectName(), nextSequence()));
+            if (mbeanAbstractName.equals(abstractName)) {
+                notificationBroadcaster.sendNotification(new Notification(NotificationType.STATE_STOPPED,
objectName, nextSequence()));
             }
         }
 
         public void failed(AbstractName abstractName) {
-            if (mbeanGBeanName.equals(abstractName)) {
-                notificationBroadcaster.sendNotification(new Notification(NotificationType.STATE_FAILED,
abstractName.getObjectName(), nextSequence()));
+            if (mbeanAbstractName.equals(abstractName)) {
+                notificationBroadcaster.sendNotification(new Notification(NotificationType.STATE_FAILED,
objectName, nextSequence()));
             }
         }
 
         public void unloaded(AbstractName abstractName) {
-            if (mbeanGBeanName.equals(abstractName)) {
-                notificationBroadcaster.sendNotification(new Notification(NotificationType.OBJECT_DELETED,
abstractName.getObjectName(), nextSequence()));
+            if (mbeanAbstractName.equals(abstractName)) {
+                notificationBroadcaster.sendNotification(new Notification(NotificationType.OBJECT_DELETED,
objectName, nextSequence()));
             }
         }
 

Modified: geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/jmx/MBeanServerKernelBridge.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/jmx/MBeanServerKernelBridge.java?rev=395753&r1=395752&r2=395753&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/jmx/MBeanServerKernelBridge.java
(original)
+++ geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/jmx/MBeanServerKernelBridge.java
Thu Apr 20 18:45:55 2006
@@ -45,10 +45,11 @@
  */
 public class MBeanServerKernelBridge implements GBeanLifecycle {
     private static final Log log = LogFactory.getLog(MBeanServerKernelBridge.class);
+    private static final AbstractNameQuery ALL = new AbstractNameQuery(null, Collections.EMPTY_MAP,
Collections.EMPTY_SET);
+
     private final HashMap registry = new HashMap();
     private final Kernel kernel;
     private final MBeanServer mbeanServer;
-    private static final AbstractNameQuery ALL = new AbstractNameQuery(null, Collections.EMPTY_MAP,
Collections.EMPTY_SET);
 
     // todo remove this as soon as Geronimo supports factory beans    
     public MBeanServerKernelBridge(Kernel kernel, MBeanServerReference mbeanServerReference)
{
@@ -63,38 +64,10 @@
     public void doStart() {
         kernel.getLifecycleMonitor().addLifecycleListener(new GBeanRegistrationListener(),
ALL);
 
-        HashMap beans = new HashMap();
-        synchronized (this) {
-            Set allNames = kernel.listGBeans(ALL);
-            for (Iterator iterator = allNames.iterator(); iterator.hasNext();) {
-                AbstractName abstractName = (AbstractName) iterator.next();
-                if (registry.containsKey(abstractName.getObjectName())) {
-                    // instance already registered
-                    continue;
-                }
-                MBeanInfo mbeanInfo;
-                try {
-                    mbeanInfo = JMXUtil.toMBeanInfo(kernel.getGBeanInfo(abstractName));
-                } catch (GBeanNotFoundException e) {
-                    // ignore - gbean already unregistered
-                    continue;
-                }
-                MBeanGBeanBridge mbeanGBeanBridge = new MBeanGBeanBridge(kernel, abstractName,
mbeanInfo);
-                registry.put(abstractName.getObjectName(), mbeanGBeanBridge);
-                beans.put(abstractName.getObjectName(), mbeanGBeanBridge);
-            }
-        }
-        for (Iterator iterator = beans.entrySet().iterator(); iterator.hasNext();) {
-            Map.Entry entry = (Map.Entry) iterator.next();
-            ObjectName objectName = (ObjectName) entry.getKey();
-            MBeanGBeanBridge bridge = (MBeanGBeanBridge) entry.getValue();
-            try {
-                mbeanServer.registerMBean(bridge, objectName);
-            } catch (InstanceAlreadyExistsException e) {
-                // ignore - gbean already has an mbean shadow object
-            } catch (Exception e) {
-                log.warn("Unable to register MBean shadow object for GBean", unwrapJMException(e));
-            }
+        Set allNames = kernel.listGBeans(ALL);
+        for (Iterator iterator = allNames.iterator(); iterator.hasNext();) {
+            AbstractName abstractName = (AbstractName) iterator.next();
+            register(abstractName);
         }
     }
 
@@ -123,14 +96,14 @@
         try {
             MBeanGBeanBridge mbeanGBeanBridge;
             synchronized (this) {
-                if (registry.containsKey(abstractName.getObjectName())) {
+                if (registry.containsKey(abstractName)) {
                     return;
                 }
                 MBeanInfo mbeanInfo = JMXUtil.toMBeanInfo(kernel.getGBeanInfo(abstractName));
-                mbeanGBeanBridge = new MBeanGBeanBridge(kernel, abstractName, mbeanInfo);
-                registry.put(abstractName.getObjectName(), mbeanGBeanBridge);
+                mbeanGBeanBridge = new MBeanGBeanBridge(kernel, abstractName, abstractName.getObjectName(),
mbeanInfo);
+                registry.put(abstractName, mbeanGBeanBridge);
             }
-            mbeanServer.registerMBean(mbeanGBeanBridge, abstractName.getObjectName());
+            mbeanServer.registerMBean(mbeanGBeanBridge, mbeanGBeanBridge.getObjectName());
         } catch (GBeanNotFoundException e) {
             // ignore - gbean already unregistered
         } catch (InstanceAlreadyExistsException e) {
@@ -141,19 +114,20 @@
     }
 
     private void unregister(AbstractName abstractName) {
+        MBeanGBeanBridge mbeanGBeanBridge;
         synchronized (this) {
-            if (registry.remove(abstractName.getObjectName()) == null) {
-                return;
-            }
+            mbeanGBeanBridge = (MBeanGBeanBridge) registry.remove(abstractName);
         }
 
-        try {
-            mbeanServer.unregisterMBean(abstractName.getObjectName());
-        } catch (InstanceNotFoundException e) {
-            // ignore - something else may have unregistered us
-            // if there truely is no GBean then we will catch it below whwn we call the superclass
-        } catch (Exception e) {
-            log.warn("Unable to unregister MBean shadow object for GBean", unwrapJMException(e));
+        if (mbeanGBeanBridge != null) {
+            try {
+                mbeanServer.unregisterMBean(mbeanGBeanBridge.getObjectName());
+            } catch (InstanceNotFoundException e) {
+                // ignore - something else may have unregistered us
+                // if there truely is no GBean then we will catch it below whwn we call the
superclass
+            } catch (Exception e) {
+                log.warn("Unable to unregister MBean shadow object for GBean", unwrapJMException(e));
+            }
         }
     }
 



Mime
View raw message