geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r109658 - in geronimo/trunk/modules/kernel/src: java/org/apache/geronimo/gbean/jmx java/org/apache/geronimo/gbean/runtime java/org/apache/geronimo/kernel test/org/apache/geronimo/gbean/runtime
Date Fri, 03 Dec 2004 09:16:03 GMT
Author: dain
Date: Fri Dec  3 01:16:02 2004
New Revision: 109658

URL: http://svn.apache.org/viewcvs?view=rev&rev=109658
Log:
Notifications now go directly though the LifecycleMonitor
JMX notifications are still fired, but GBeans don't listen for JMX notifcations amymore

Added:
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/LifecycleBroadcaster.java
Modified:
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBean.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/JMXLifecycleBroadcaster.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstanceState.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java
   geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/LifecycleMonitor.java
   geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/gbean/runtime/GBeanAttributeTest.java

Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBean.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBean.java?view=diff&rev=109658&p1=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBean.java&r1=109657&p2=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBean.java&r2=109658
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBean.java	(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBean.java	Fri
Dec  3 01:16:02 2004
@@ -205,7 +205,7 @@
             }
 
             gbeanData.setName(objectName);
-            lifecycleBroadcaster = new JMXLifecycleBroadcaster();
+            lifecycleBroadcaster = new JMXLifecycleBroadcaster(objectName, kernel.getLifecycleMonitor().createLifecycleBroadcaster(objectName));
             gbeanInstance = new GBeanInstance(kernel, gbeanData, lifecycleBroadcaster, classLoader);
             mbeanInfo = GBeanJMXUtil.toMBeanInfo(gbeanInstance.getGBeanInfo());
         }

Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/JMXLifecycleBroadcaster.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/JMXLifecycleBroadcaster.java?view=diff&rev=109658&p1=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/JMXLifecycleBroadcaster.java&r1=109657&p2=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/JMXLifecycleBroadcaster.java&r2=109658
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/JMXLifecycleBroadcaster.java
(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/JMXLifecycleBroadcaster.java
Fri Dec  3 01:16:02 2004
@@ -16,48 +16,62 @@
  */
 package org.apache.geronimo.gbean.jmx;
 
-import javax.management.ObjectName;
-import javax.management.NotificationBroadcasterSupport;
+import javax.management.ListenerNotFoundException;
 import javax.management.Notification;
-import javax.management.NotificationListener;
+import javax.management.NotificationBroadcasterSupport;
 import javax.management.NotificationFilter;
-import javax.management.ListenerNotFoundException;
+import javax.management.NotificationListener;
+import javax.management.ObjectName;
 
-import org.apache.geronimo.kernel.LifecycleListener;
+import org.apache.geronimo.gbean.runtime.LifecycleBroadcaster;
 import org.apache.geronimo.kernel.management.NotificationType;
 
 /**
  * @version $Rev$ $Date$
  */
-public class JMXLifecycleBroadcaster implements LifecycleListener {
+public class JMXLifecycleBroadcaster implements LifecycleBroadcaster {
     private final NotificationBroadcasterSupport notificationBroadcaster = new NotificationBroadcasterSupport();
+    private final ObjectName objectName;
+    private final LifecycleBroadcaster lifecycleBroadcaster;
     private long sequence;
 
-    public void loaded(ObjectName objectName) {
+    public JMXLifecycleBroadcaster(ObjectName objectName, LifecycleBroadcaster lifecycleBroadcaster)
{
+        this.objectName = objectName;
+        this.lifecycleBroadcaster = lifecycleBroadcaster;
+    }
+
+    public void fireLoadedEvent() {
+        lifecycleBroadcaster.fireLoadedEvent();
         notificationBroadcaster.sendNotification(new Notification(NotificationType.OBJECT_CREATED,
objectName, nextSequence()));
     }
 
-    public void starting(ObjectName objectName) {
+    public void fireStartingEvent() {
+        lifecycleBroadcaster.fireStartingEvent();
         notificationBroadcaster.sendNotification(new Notification(NotificationType.STATE_STARTING,
objectName, nextSequence()));
     }
 
-    public void running(ObjectName objectName) {
+    public void fireRunningEvent() {
+        lifecycleBroadcaster.fireRunningEvent();
         notificationBroadcaster.sendNotification(new Notification(NotificationType.STATE_RUNNING,
objectName, nextSequence()));
     }
 
-    public void stopping(ObjectName objectName) {
+    public void fireStoppingEvent() {
+        lifecycleBroadcaster.fireStoppingEvent();
         notificationBroadcaster.sendNotification(new Notification(NotificationType.STATE_STOPPING,
objectName, nextSequence()));
     }
 
-    public void stopped(ObjectName objectName) {
+    public void fireStoppedEvent() {
+        lifecycleBroadcaster.fireStoppedEvent();
         notificationBroadcaster.sendNotification(new Notification(NotificationType.STATE_STOPPED,
objectName, nextSequence()));
     }
 
-    public void failed(ObjectName objectName) {
+    public void fireFailedEvent() {
+        lifecycleBroadcaster.fireFailedEvent();
         notificationBroadcaster.sendNotification(new Notification(NotificationType.STATE_FAILED,
objectName, nextSequence()));
     }
 
-    public void unloaded(ObjectName objectName) {
+    public void fireUnloadedEvent() {
+        lifecycleBroadcaster.fireUnloadedEvent();
         notificationBroadcaster.sendNotification(new Notification(NotificationType.OBJECT_DELETED,
objectName, nextSequence()));
     }
 

Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java?view=diff&rev=109658&p1=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java&r1=109657&p2=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java&r2=109658
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java
(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java
Fri Dec  3 01:16:02 2004
@@ -43,7 +43,6 @@
 import org.apache.geronimo.gbean.InvalidConfigurationException;
 import org.apache.geronimo.gbean.WaitingException;
 import org.apache.geronimo.kernel.Kernel;
-import org.apache.geronimo.kernel.LifecycleListener;
 import org.apache.geronimo.kernel.NoSuchAttributeException;
 import org.apache.geronimo.kernel.NoSuchOperationException;
 import org.apache.geronimo.kernel.management.EventProvider;
@@ -99,7 +98,7 @@
     /**
      * The single listener to which we broadcast lifecycle change events.
      */
-    private final LifecycleListener lifecycleBroadcaster;
+    private final LifecycleBroadcaster lifecycleBroadcaster;
 
     /**
      * The lifecycle controller given to the instance
@@ -190,7 +189,7 @@
      * @throws org.apache.geronimo.gbean.InvalidConfigurationException if the gbeanInfo is
inconsistent with the actual java classes, such as
      * mismatched attribute types or the intial data can not be set
      */
-    public GBeanInstance(Kernel kernel, GBeanData gbeanData, LifecycleListener lifecycleBroadcaster,
ClassLoader classLoader) throws InvalidConfigurationException {
+    public GBeanInstance(Kernel kernel, GBeanData gbeanData, LifecycleBroadcaster lifecycleBroadcaster,
ClassLoader classLoader) throws InvalidConfigurationException {
         this.kernel = kernel;
         this.objectName = gbeanData.getName();
         this.lifecycleBroadcaster = lifecycleBroadcaster;
@@ -297,7 +296,7 @@
         for (int i = 0; i < references.length; i++) {
             references[i].online(this.kernel);
         }
-        lifecycleBroadcaster.loaded(objectName);
+        lifecycleBroadcaster.fireLoadedEvent();
     }
 
     public void destroy() {
@@ -308,7 +307,7 @@
             destroyed = true;
         }
 
-        lifecycleBroadcaster.unloaded(objectName);
+        lifecycleBroadcaster.fireUnloadedEvent();
 
         // just to be sure, stop all the references again
         for (int i = 0; i < references.length; i++) {

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/org/apache/geronimo/gbean/runtime/GBeanInstanceState.java?view=diff&rev=109658&p1=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstanceState.java&r1=109657&p2=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstanceState.java&r2=109658
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstanceState.java
(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstanceState.java
Fri Dec  3 01:16:02 2004
@@ -62,7 +62,7 @@
     /**
      * The broadcaster of lifecycle events
      */
-    private final LifecycleListener lifecycleBroadcaster;
+    private final LifecycleBroadcaster lifecycleBroadcaster;
 
     /**
      * The listener for the of the object blocking the start of this gbean.
@@ -74,7 +74,7 @@
     // objects check if each other are in one state or another (i.e., classic A calls B while
B calls A)
     private volatile State state = State.STOPPED;
 
-    GBeanInstanceState(Kernel kernel, ObjectName objectName, GBeanLifecycle gbeanLifecycle,
LifecycleListener lifecycleBroadcaster) {
+    GBeanInstanceState(Kernel kernel, ObjectName objectName, GBeanLifecycle gbeanLifecycle,
LifecycleBroadcaster lifecycleBroadcaster) {
         this.kernel = kernel;
         this.dependencyManager = kernel.getDependencyManager();
         this.objectName = objectName;
@@ -110,7 +110,7 @@
 
         // only fire a notification if we are not already starting
         if (state != State.STARTING) {
-            lifecycleBroadcaster.starting(objectName);
+            lifecycleBroadcaster.fireStartingEvent();
         }
 
         attemptFullStart();
@@ -188,7 +188,7 @@
 
         // only fire a notification if we are not already stopping
         if (state != State.STOPPING) {
-            lifecycleBroadcaster.stopping(objectName);
+            lifecycleBroadcaster.fireStoppingEvent();
         }
 
         // Don't try to stop dependents from within a synchronized block... this should reduce
deadlocks
@@ -231,7 +231,7 @@
             doSafeFail();
             setStateInstance(State.FAILED);
         }
-        lifecycleBroadcaster.failed(objectName);
+        lifecycleBroadcaster.fireFailedEvent();
     }
 
     /**
@@ -523,23 +523,23 @@
         assert !Thread.holdsLock(this): "This method cannot be called while holding a synchronized
lock on this";
         switch (state.toInt()) {
             case State.STOPPED_INDEX:
-                lifecycleBroadcaster.stopped(objectName);
+                lifecycleBroadcaster.fireStoppedEvent();
                 break;
 
             case State.STARTING_INDEX:
-                lifecycleBroadcaster.starting(objectName);
+                lifecycleBroadcaster.fireStartingEvent();
                 break;
 
             case State.RUNNING_INDEX:
-                lifecycleBroadcaster.running(objectName);
+                lifecycleBroadcaster.fireRunningEvent();
                 break;
 
             case State.STOPPING_INDEX:
-                lifecycleBroadcaster.stopping(objectName);
+                lifecycleBroadcaster.fireStoppingEvent();
                 break;
 
             case State.FAILED_INDEX:
-                lifecycleBroadcaster.failed(objectName);
+                lifecycleBroadcaster.fireFailedEvent();
                 break;
         }
     }

Added: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/LifecycleBroadcaster.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/LifecycleBroadcaster.java?view=auto&rev=109658
==============================================================================
--- (empty file)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/LifecycleBroadcaster.java
Fri Dec  3 01:16:02 2004
@@ -0,0 +1,32 @@
+/**
+ *
+ * Copyright 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.gbean.runtime;
+
+
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface LifecycleBroadcaster {
+    public void fireLoadedEvent();
+    public void fireStartingEvent();
+    public void fireRunningEvent();
+    public void fireStoppingEvent();
+    public void fireStoppedEvent();
+    public void fireFailedEvent();
+    public void fireUnloadedEvent();
+}

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/org/apache/geronimo/kernel/Kernel.java?view=diff&rev=109658&p1=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java&r1=109657&p2=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java&r2=109658
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java	(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java	Fri Dec
 3 01:16:02 2004
@@ -24,13 +24,14 @@
 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 java.util.Iterator;
-import java.util.HashSet;
 import javax.management.Attribute;
+import javax.management.AttributeNotFoundException;
 import javax.management.InstanceAlreadyExistsException;
 import javax.management.InstanceNotFoundException;
 import javax.management.JMException;
@@ -38,17 +39,15 @@
 import javax.management.MBeanServer;
 import javax.management.MBeanServerFactory;
 import javax.management.MalformedObjectNameException;
-import javax.management.NotificationBroadcasterSupport;
 import javax.management.ObjectName;
-import javax.management.AttributeNotFoundException;
 
 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.runtime.GBeanInstance;
 import org.apache.geronimo.gbean.jmx.GBeanMBean;
 import org.apache.geronimo.gbean.jmx.JMXLifecycleBroadcaster;
+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;
@@ -78,7 +77,7 @@
  *
  * @version $Rev$ $Date$
  */
-public class Kernel extends NotificationBroadcasterSupport implements KernelMBean {
+public class Kernel implements KernelMBean {
 
     /**
      * The JMX name used by a Kernel to register itself when it boots.
@@ -559,7 +558,7 @@
 
         mbServer = MBeanServerFactory.createMBeanServer(domainName);
         mbServer.registerMBean(this, KERNEL);
-        lifecycleMonitor = new LifecycleMonitor(mbServer);
+        lifecycleMonitor = new LifecycleMonitor(this);
         dependencyManager = new DependencyManager(lifecycleMonitor);
         proxyManager = new ProxyManager(this);
 
@@ -568,7 +567,7 @@
         configurationData.setReferencePatterns("Stores", Collections.singleton(CONFIGURATION_STORE_PATTERN));
 
         // create the connfiguration manager instance
-        JMXLifecycleBroadcaster lifecycleBroadcaster = new JMXLifecycleBroadcaster();
+        JMXLifecycleBroadcaster lifecycleBroadcaster = new JMXLifecycleBroadcaster(CONFIGURATION_MANAGER_NAME,
lifecycleMonitor.createLifecycleBroadcaster(CONFIGURATION_MANAGER_NAME));
         configurationManagerInstance = new GBeanInstance(this, configurationData, lifecycleBroadcaster,
getClass().getClassLoader());
         configurationManagerInstance.start();
         configurationManager = (ConfigurationManager) configurationManagerInstance.getTarget();

Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/LifecycleMonitor.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/LifecycleMonitor.java?view=diff&rev=109658&p1=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/LifecycleMonitor.java&r1=109657&p2=geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/LifecycleMonitor.java&r2=109658
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/LifecycleMonitor.java
(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/LifecycleMonitor.java
Fri Dec  3 01:16:02 2004
@@ -17,34 +17,25 @@
 
 package org.apache.geronimo.kernel;
 
+import java.util.Collections;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
-import java.util.Set;
 import java.util.Map;
-import java.util.Collections;
-import java.util.HashMap;
-import javax.management.InstanceNotFoundException;
-import javax.management.MBeanServer;
-import javax.management.MBeanServerNotification;
-import javax.management.Notification;
-import javax.management.NotificationFilterSupport;
-import javax.management.NotificationListener;
+import java.util.Set;
 import javax.management.ObjectName;
-import javax.management.NotificationBroadcaster;
-import javax.management.NotificationFilter;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.geronimo.kernel.jmx.JMXUtil;
-import org.apache.geronimo.kernel.management.NotificationType;
+import org.apache.geronimo.gbean.runtime.LifecycleBroadcaster;
 
 /**
  * @version $Rev: 71492 $ $Date: 2004-11-14 21:31:50 -0800 (Sun, 14 Nov 2004) $
  */
-public class LifecycleMonitor implements NotificationListener {
+public class LifecycleMonitor {
     private static final Log log = LogFactory.getLog(LifecycleMonitor.class);
 
-    private final MBeanServer server;
+    private final Kernel kernel;
 
     // todo we should only hold weak references to the listeners
     private final Map boundListeners = new HashMap();
@@ -53,58 +44,17 @@
     /**
      * @deprecated don't use this yet... it may change or go away
      */
-    public LifecycleMonitor(MBeanServer server) {
-        this.server = server;
-
-        // listen for all mbean registration events
-        try {
-            NotificationFilterSupport mbeanServerFilter = new NotificationFilterSupport();
-            mbeanServerFilter.enableType(MBeanServerNotification.REGISTRATION_NOTIFICATION);
-            mbeanServerFilter.enableType(MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
-            server.addNotificationListener(JMXUtil.DELEGATE_NAME, this, mbeanServerFilter,
null);
-        } catch (Exception e) {
-            // this will never happen... all of the above is well formed
-            throw new AssertionError(e);
-        }
+    public LifecycleMonitor(Kernel kernel) {
+        this.kernel = kernel;
 
         // register for state change notifications with all mbeans that match the target
patterns
-        Set names = server.queryNames(null, null);
+        Set names = this.kernel.listGBeans((ObjectName)null);
         for (Iterator objectNameIterator = names.iterator(); objectNameIterator.hasNext();)
{
             addSource((ObjectName) objectNameIterator.next());
         }
-
-        for (Iterator iterator = boundListeners.keySet().iterator(); iterator.hasNext();)
{
-            ObjectName source = (ObjectName) iterator.next();
-            try {
-                if (server.isInstanceOf(source, NotificationBroadcaster.class.getName()))
{
-                    server.addNotificationListener(source, this, STATE_CHANGE_FILTER, null);
-                }
-            } catch (InstanceNotFoundException e) {
-                // the instance died before we could get going... not a big deal
-                break;
-            } catch (Throwable e) {
-                log.warn("Could not add state change listener to: " + source + " on behalf
of objectName", e);
-            }
-        }
     }
 
     public synchronized void destroy() {
-        try {
-            server.removeNotificationListener(JMXUtil.DELEGATE_NAME, this);
-        } catch (Exception ignore) {
-            // don't care... we tried
-        }
-
-        // unregister for all notifications
-        for (Iterator iterator = boundListeners.keySet().iterator(); iterator.hasNext();)
{
-            ObjectName target = (ObjectName) iterator.next();
-            try {
-                server.removeNotificationListener(target, this, STATE_CHANGE_FILTER, null);
-            } catch (Exception ignore) {
-                // don't care... we tried
-            }
-        }
-
         boundListeners.clear();
         listenerPatterns.clear();
     }
@@ -257,61 +207,48 @@
         }
     }
 
-    public void handleNotification(Notification notification, Object o) {
-        String type = notification.getType();
+    /**
+     * @deprecated is this for internal use by the GBeanInstance and will be remove later
+     */
+    public LifecycleBroadcaster createLifecycleBroadcaster(ObjectName objectName) {
+        return new RawLifecycleBroadcaster(objectName);
+    }
 
-        if (MBeanServerNotification.REGISTRATION_NOTIFICATION.equals(type)) {
-            ObjectName source = ((MBeanServerNotification) notification).getMBeanName();
-            if (!boundListeners.containsKey(source)) {
-                // register for state change notifications
-                try {
-                    server.addNotificationListener(source, this, STATE_CHANGE_FILTER, null);
-                } catch (InstanceNotFoundException e) {
-                    // the instance died before we could get going... not a big deal
-                    return;
-                }
+    private class RawLifecycleBroadcaster implements LifecycleBroadcaster {
+        private final ObjectName objectName;
 
-                addSource(source);
-                fireLoadedEvent(source);
-            }
-        } else if (MBeanServerNotification.UNREGISTRATION_NOTIFICATION.equals(type)) {
-            ObjectName source = ((MBeanServerNotification) notification).getMBeanName();
-            fireUnloadedEvent(source);
-            removeSource(source);
-        } else {
-            final ObjectName source = (ObjectName) notification.getSource();
-            if (NotificationType.STATE_STARTING.equals(type)) {
-                fireStartingEvent(source);
-            } else if (NotificationType.STATE_RUNNING.equals(type)) {
-                fireRunningEvent(source);
-            } else if (NotificationType.STATE_STOPPING.equals(type)) {
-                fireStoppingEvent(source);
-            } else if (NotificationType.STATE_STOPPED.equals(type)) {
-                fireStoppedEvent(source);
-            } else if (NotificationType.STATE_FAILED.equals(type)) {
-                fireFailedEvent(source);
-            }
+        public RawLifecycleBroadcaster(ObjectName objectName) {
+            this.objectName = objectName;
         }
-    }
 
-    /**
-     * A notification filter which only lets all J2EE state change notifications pass.
-     * Specifically this is STATE_STARTING, STATE_RUNNING, STATE_STOPPING, STATE_STOPPED
-     * and STATE_FAILED.
-     */
-    private static final NotificationFilter STATE_CHANGE_FILTER = new J2EEStateChangeFilter();
+        public void fireLoadedEvent() {
+            addSource(objectName);
+            LifecycleMonitor.this.fireLoadedEvent(objectName);
+        }
+
+        public void fireStartingEvent() {
+            LifecycleMonitor.this.fireStartingEvent(objectName);
+        }
+
+        public void fireRunningEvent() {
+            LifecycleMonitor.this.fireRunningEvent(objectName);
+        }
+
+        public void fireStoppingEvent() {
+            LifecycleMonitor.this.fireStoppingEvent(objectName);
+        }
+
+        public void fireStoppedEvent() {
+            LifecycleMonitor.this.fireStoppedEvent(objectName);
+        }
 
-    private static final class J2EEStateChangeFilter implements NotificationFilter {
-        private J2EEStateChangeFilter() {
+        public void fireFailedEvent() {
+            LifecycleMonitor.this.fireFailedEvent(objectName);
         }
 
-        public boolean isNotificationEnabled(Notification notification) {
-            String type = notification.getType();
-            return NotificationType.STATE_STARTING.equals(type) ||
-                    NotificationType.STATE_RUNNING.equals(type) ||
-                    NotificationType.STATE_STOPPING.equals(type) ||
-                    NotificationType.STATE_STOPPED.equals(type) ||
-                    NotificationType.STATE_FAILED.equals(type);
+        public void fireUnloadedEvent() {
+            LifecycleMonitor.this.fireUnloadedEvent(objectName);
+            removeSource(objectName);
         }
     }
 }

Modified: geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/gbean/runtime/GBeanAttributeTest.java
Url: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/gbean/runtime/GBeanAttributeTest.java?view=diff&rev=109658&p1=geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/gbean/runtime/GBeanAttributeTest.java&r1=109657&p2=geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/gbean/runtime/GBeanAttributeTest.java&r2=109658
==============================================================================
--- geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/gbean/runtime/GBeanAttributeTest.java
(original)
+++ geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/gbean/runtime/GBeanAttributeTest.java
Fri Dec  3 01:16:02 2004
@@ -23,7 +23,6 @@
 import org.apache.geronimo.gbean.GBeanData;
 import org.apache.geronimo.gbean.InvalidConfigurationException;
 import org.apache.geronimo.kernel.Kernel;
-import org.apache.geronimo.kernel.LifecycleAdapter;
 import org.apache.geronimo.kernel.MockDynamicGBean;
 import org.apache.geronimo.kernel.MockGBean;
 
@@ -351,11 +350,11 @@
 
         gbeanInstance = new GBeanInstance(kernel,
                 new GBeanData(new ObjectName("test:MockGBean=normal"), MockGBean.getGBeanInfo()),
-                new LifecycleAdapter(),
+                new MyLifecycleBroadcaster(),
                 MockGBean.class.getClassLoader());
         dynamicGBeanInstance = new GBeanInstance(kernel,
                 new GBeanData(new ObjectName("test:MockGBean=dynamic"), MockDynamicGBean.getGBeanInfo()),
-                new LifecycleAdapter(),
+                new MyLifecycleBroadcaster(),
                 MockGBean.class.getClassLoader());
         getInvoker = new MethodInvoker() {
 
@@ -376,5 +375,28 @@
     protected void tearDown() throws Exception {
         kernel.shutdown();
         gbeanInstance = null;
+    }
+
+    private static class MyLifecycleBroadcaster implements LifecycleBroadcaster {
+        public void fireLoadedEvent() {
+        }
+
+        public void fireStartingEvent() {
+        }
+
+        public void fireRunningEvent() {
+        }
+
+        public void fireStoppingEvent() {
+        }
+
+        public void fireStoppedEvent() {
+        }
+
+        public void fireFailedEvent() {
+        }
+
+        public void fireUnloadedEvent() {
+        }
     }
 }

Mime
View raw message