servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r966045 - in /servicemix/smx4/nmr/trunk: jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ jbi/deployer/src/main/resources/OSGI-INF/blueprint/ jbi/deployer/src/test/java/org/apache/servicemix/jbi/deployer/artifacts/ jbi/os...
Date Tue, 20 Jul 2010 22:44:32 GMT
Author: gnodet
Date: Tue Jul 20 22:44:31 2010
New Revision: 966045

URL: http://svn.apache.org/viewvc?rev=966045&view=rev
Log:
SMX4NMR-216: Shutdown issues with the NMR/JBI management layer

Modified:
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AdminCommandsImpl.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AdminService.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ComponentInstaller.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/InstallationContextImpl.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyInstaller.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/SharedLibraryInstaller.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/resources/OSGI-INF/blueprint/servicemix-jbi-deployer.xml
    servicemix/smx4/nmr/trunk/jbi/deployer/src/test/java/org/apache/servicemix/jbi/deployer/artifacts/ServiceAssemblyImplTest.java
    servicemix/smx4/nmr/trunk/jbi/osgi/src/main/resources/OSGI-INF/blueprint/servicemix-jbi.xml
    servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/Environment.java
    servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/AbstractComponentContext.java
    servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentRegistryImpl.java
    servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/EnvironmentImpl.java
    servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/MBeanServerWrapper.java
    servicemix/smx4/nmr/trunk/nmr/management/src/main/java/org/apache/servicemix/nmr/management/ManagedEndpoint.java
    servicemix/smx4/nmr/trunk/nmr/management/src/main/java/org/apache/servicemix/nmr/management/ManagementAgent.java
    servicemix/smx4/nmr/trunk/nmr/management/src/main/java/org/apache/servicemix/nmr/management/ManagementEndpointRegistry.java
    servicemix/smx4/nmr/trunk/nmr/management/src/main/resources/OSGI-INF/blueprint/servicemix-nmr-management.xml
    servicemix/smx4/nmr/trunk/nmr/management/src/test/java/org/apache/servicemix/nmr/management/ManagementStrategyTest.java

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AdminCommandsImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AdminCommandsImpl.java?rev=966045&r1=966044&r2=966045&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AdminCommandsImpl.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AdminCommandsImpl.java Tue Jul 20 22:44:31 2010
@@ -22,9 +22,7 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Properties;
 import java.util.Set;
-
 import javax.jbi.management.LifeCycleMBean;
-import javax.management.ObjectName;
 
 import org.apache.servicemix.jbi.deployer.AdminCommandsService;
 import org.apache.servicemix.jbi.deployer.Component;
@@ -443,28 +441,13 @@ public class AdminCommandsImpl implement
         return buffer.toString();
     }
 
+
     public void init() throws Exception {
-    	try {
-    		deployer.getManagementStrategy().manageObject(this);
-    	} catch (Exception e) {
-    		//means somehow the previous AdminCommandsService not dereference successfully, 
-    		//this could be caused by a race between the AdminCommandsImpl destroy-method 
-    		//being called and Blueprint itself being shutdown.
-    		//so we try to dereference it again at this point
-        	ObjectName objectName = deployer.getManagementStrategy().getManagedObjectName(this, null, ObjectName.class);
-        	deployer.getManagementStrategy().unmanageNamedObject(objectName);
-        	deployer.getManagementStrategy().manageObject(this);
-    	}
+        deployer.getEnvironment().manageObject(this);
     }
 
     public void destroy() throws Exception {
-        try {
-        	deployer.getManagementStrategy().unmanageObject(this);
-        } catch (Exception e) {
-        	// ignore ServiceUnavailableException thrown by Blueprint
-            // Service on dereference of ManagementStrategy proxy if its
-            // already in the process of itself shutting down
-        }
+        deployer.getEnvironment().unmanageObject(this);
     }
 
     public void setInstallationService(InstallationService installationService) {

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AdminService.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AdminService.java?rev=966045&r1=966044&r2=966045&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AdminService.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AdminService.java Tue Jul 20 22:44:31 2010
@@ -51,7 +51,7 @@ public class AdminService implements Adm
         for (Component component : deployer.getComponents().values()) {
             if (Deployer.TYPE_BINDING_COMPONENT.equals(component.getMainType())) {
                 try {
-                    names.add(deployer.getManagementStrategy().getManagedObjectName(component, null, ObjectName.class));
+                    names.add(deployer.getEnvironment().getManagedObjectName(component));
                 } catch (Exception e) {
                 }
             }
@@ -63,7 +63,7 @@ public class AdminService implements Adm
         Component component = deployer.getComponent(name);
         if (component != null) {
             try {
-                return deployer.getManagementStrategy().getManagedObjectName(component, null, ObjectName.class);
+                return deployer.getEnvironment().getManagedObjectName(component);
             } catch (Exception e) {
             }
         }
@@ -75,7 +75,7 @@ public class AdminService implements Adm
         for (Component component : deployer.getComponents().values()) {
             if (Deployer.TYPE_SERVICE_ENGINE.equals(component.getMainType())) {
                 try {
-                    names.add(deployer.getManagementStrategy().getManagedObjectName(component, null, ObjectName.class));
+                    names.add(deployer.getEnvironment().getManagedObjectName(component));
                 } catch (Exception e) {
                 }
             }

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ComponentInstaller.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ComponentInstaller.java?rev=966045&r1=966044&r2=966045&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ComponentInstaller.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ComponentInstaller.java Tue Jul 20 22:44:31 2010
@@ -61,9 +61,7 @@ public class ComponentInstaller extends 
         this.installRoot = new File(System.getProperty("karaf.base"), "data/jbi/" + getName() + "/install");
         this.installRoot.mkdirs();
         this.installationContext = new InstallationContextImpl(descriptor.getComponent(), 
-                                                               deployer.getEnvironment(),
-                                                               deployer.getManagementStrategy(),
-                                                               deployer.getMbeanServer());
+                                                               deployer.getEnvironment());
         this.installationContext.setInstallRoot(installRoot);
     }
 
@@ -78,7 +76,7 @@ public class ComponentInstaller extends 
 
     public void register() throws JMException {
         try {
-            deployer.getManagementStrategy().manageObject(this);
+            deployer.getEnvironment().manageObject(this);
         } catch (Exception ex) {
             throw new JMException(ex.getMessage());
         }
@@ -86,7 +84,7 @@ public class ComponentInstaller extends 
 
     public void unregister() throws JMException {
         try {
-            deployer.getManagementStrategy().unmanageObject(this);
+            deployer.getEnvironment().unmanageObject(this);
         } catch (Exception ex) {
             throw new JMException(ex.getMessage());
         }
@@ -256,7 +254,7 @@ public class ComponentInstaller extends 
     public ObjectName getObjectName() {
         if (objectName == null) {
             try {
-                objectName = deployer.getManagementStrategy().getManagedObjectName(this, null, ObjectName.class);
+                objectName = deployer.getEnvironment().getManagedObjectName(this);
             } catch (Exception e) {
                 // ignore
             }
@@ -319,7 +317,7 @@ public class ComponentInstaller extends 
                 // in case the bootstrap has not done it
                 try {
                     if (extensionMBeanName != null) {
-                        deployer.getManagementStrategy().unmanageObject(extensionMBeanName);
+                        deployer.getEnvironment().unmanageNamedObject(extensionMBeanName);
                     }
                 } catch (Exception e) {
                     // ignore
@@ -424,7 +422,7 @@ public class ComponentInstaller extends 
             }
         }
         Component component = deployer.registerComponent(getBundle(), componentDesc, innerComponent, aLibs);
-        return deployer.getManagementStrategy().getManagedObjectName(component, null, ObjectName.class);
+        return deployer.getEnvironment().getManagedObjectName(component);
     }
 
     public void configure(Properties props) throws Exception {
@@ -433,7 +431,7 @@ public class ComponentInstaller extends 
             if (on == null) {
                 LOGGER.warn("Could not find installation configuration MBean. Installation properties will be ignored.");
             } else {
-                MBeanServer mbs = deployer.getMbeanServer();
+                MBeanServer mbs = deployer.getEnvironment().getMBeanServer();
                 for (Object o : props.keySet()) {
                     String key = (String) o;
                     String val = props.getProperty(key);

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java?rev=966045&r1=966044&r2=966045&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java Tue Jul 20 22:44:31 2010
@@ -113,14 +113,10 @@ public class Deployer implements Synchro
     
     private int shutdownTimeout;
 
-    // Helper beans
-    private ManagementStrategy managementStrategy;
     private Environment environment;
 
     private ListenerRegistry listenerRegistry;
     
-    private MBeanServer mbeanServer;
-
     private Storage storage;
 
     public Deployer() throws JBIException {
@@ -156,22 +152,6 @@ public class Deployer implements Synchro
         return endpointListener;
     }
 
-    public ManagementStrategy getManagementStrategy() {
-        return managementStrategy;
-    }
-
-    public void setManagementStrategy(ManagementStrategy managementStrategy) {
-        this.managementStrategy = managementStrategy;
-    }
-    
-    public MBeanServer getMbeanServer() {
-        return mbeanServer;
-    }
-
-    public void setMbeanServer(MBeanServer mbeanServer) {
-        this.mbeanServer = mbeanServer;
-    }
-
     public void setEnvironment(Environment environment) {
         this.environment = environment;
     }
@@ -414,8 +394,8 @@ public class Deployer implements Synchro
         props.put(NAME, sharedLibraryDesc.getIdentification().getName());
         LOGGER.debug("Registering JBI Shared Library");
         registerService(bundle, SharedLibrary.class.getName(), sl, props);
-        if (!getManagementStrategy().isManaged(sl, null)) {
-        	getManagementStrategy().manageObject(sl);
+        if (!getEnvironment().isManaged(sl)) {
+        	getEnvironment().manageObject(sl);
         }
         // Check pending bundles
         checkPendingInstallers();
@@ -442,8 +422,8 @@ public class Deployer implements Synchro
         if (!wrappedComponents.containsKey(name)) {
             registerService(bundle, javax.jbi.component.Component.class.getName(), innerComponent, props);
         }
-        if (!getManagementStrategy().isManaged(component, null)) {
-        	getManagementStrategy().manageObject(component);
+        if (!getEnvironment().isManaged(component)) {
+        	getEnvironment().manageObject(component);
         }
         return component;
     }
@@ -463,9 +443,9 @@ public class Deployer implements Synchro
         // register the service assembly in the OSGi registry
         LOGGER.debug("Registering JBI service assembly");
         registerService(bundle, ServiceAssembly.class.getName(), sa, props);
-        if (!getManagementStrategy().isManaged(sa, null)) {
+        if (!getEnvironment().isManaged(sa)) {
         	//check if this SA is managed, this is the case that restart SA bundle
-        	getManagementStrategy().manageObject(sa);
+        	getEnvironment().manageObject(sa);
         }
         return sa;
     }
@@ -508,7 +488,7 @@ public class Deployer implements Synchro
             }
             components.remove(component.getName());
             try {
-				getManagementStrategy().unmanageObject(component);
+				getEnvironment().unmanageObject(component);
 			} catch (Exception e) {
 				LOGGER.error("Error unmanage component: " + component.getName(), e);
 			}
@@ -521,7 +501,7 @@ public class Deployer implements Synchro
             pendingAssemblies.remove(assembly);
             unregisterServices(assembly.getBundle());
             try {
-				getManagementStrategy().unmanageObject(assembly);
+				getEnvironment().unmanageObject(assembly);
 			} catch (Exception e) {
 				LOGGER.error("Error unmanage service assembly: " + assembly.getName(), e);
 			}
@@ -536,7 +516,7 @@ public class Deployer implements Synchro
             // TODO: shutdown all components
             sharedLibraries.remove(library.getName());
             try {
-				getManagementStrategy().unmanageObject(library);
+				getEnvironment().unmanageObject(library);
 			} catch (Exception e) {
 				LOGGER.error("Error unmanage sharedlibrary: " + library.getName(), e);
 			}
@@ -635,7 +615,7 @@ public class Deployer implements Synchro
         // propagate lifecycle event to management strategy
         // 
         try {
-            getManagementStrategy().notify(event);
+            getEnvironment().notify(event);
         } catch (Exception e) {
             // ignore
         }

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/InstallationContextImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/InstallationContextImpl.java?rev=966045&r1=966044&r2=966045&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/InstallationContextImpl.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/InstallationContextImpl.java Tue Jul 20 22:44:31 2010
@@ -55,21 +55,15 @@ import org.apache.servicemix.nmr.managem
 public class InstallationContextImpl implements InstallationContext, ComponentContext, MBeanNames {
 
     private ComponentDesc descriptor;
-    private ManagementStrategy managementStrategy;
-    private MBeanServer mbeanServer;
     private Environment environment;
     private File installRoot;
     private List<String> classPathElements = Collections.emptyList();
     private boolean install = true;
 
     public InstallationContextImpl(ComponentDesc descriptor,
-                                   Environment environment,
-                                   ManagementStrategy managementStrategy,
-                                   MBeanServer mbeanServer) {
+                                   Environment environment) {
         this.descriptor = descriptor;
         this.environment = environment;
-        this.managementStrategy = managementStrategy;
-        this.mbeanServer = mbeanServer;
         if (descriptor.getComponentClassPath() != null
                 && descriptor.getComponentClassPath().getPathElements() != null
                 && descriptor.getComponentClassPath().getPathElements().length > 0) {
@@ -296,44 +290,40 @@ public class InstallationContextImpl imp
 
     public ObjectName createCustomComponentMBeanName(String customName) {
         ObjectName name = null;
-        if (managementStrategy != null) {
-            Nameable nameable = new Nameable() {
-                public String getName() {
-                    return descriptor.getIdentification().getName();
-                }                    
-                public String getParent() {
-                    return null;
-                }
-                public String getMainType() {
-                    return null;
-                }
-                public String getSubType() {
-                    return null;
-                }
-                public String getVersion() {
-                    return null;
-                }
-                public Class getPrimaryInterface() {
-                    return null;
-                }
-            };
-            try {
-                name = managementStrategy.getManagedObjectName(nameable, customName, ObjectName.class);
-            } catch (Exception e){
-                // ignore
+        Nameable nameable = new Nameable() {
+            public String getName() {
+                return descriptor.getIdentification().getName();
+            }
+            public String getParent() {
+                return null;
             }
+            public String getMainType() {
+                return null;
+            }
+            public String getSubType() {
+                return null;
+            }
+            public String getVersion() {
+                return null;
+            }
+            public Class getPrimaryInterface() {
+                return null;
+            }
+        };
+        try {
+            name = environment.getManagedObjectName(nameable, customName);
+        } catch (Exception e){
+            // ignore
         }
         return name;
     }
 
     public String getJmxDomainName() {
         String name = null;
-        if (managementStrategy != null) {
-            try {
-                name = managementStrategy.getManagedObjectName(null, null, String.class);
-            } catch (Exception e) {
-                // ignore
-            }
+        try {
+            name = environment.getJmxDomainName();
+        } catch (Exception e) {
+            // ignore
         }
         return name;
     }
@@ -385,7 +375,7 @@ public class InstallationContextImpl imp
     }
 
     public MBeanServer getMBeanServer() {
-        return mbeanServer;
+        return environment.getMBeanServer();
     }
 
     public InitialContext getNamingContext() {

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyInstaller.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyInstaller.java?rev=966045&r1=966044&r2=966045&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyInstaller.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyInstaller.java Tue Jul 20 22:44:31 2010
@@ -95,7 +95,7 @@ public class ServiceAssemblyInstaller ex
             }
             postInstall();
             ServiceAssembly sa = deployer.registerServiceAssembly(bundle, descriptor.getServiceAssembly(), sus);
-            return deployer.getManagementStrategy().getManagedObjectName(sa, null, ObjectName.class);
+            return deployer.getEnvironment().getManagedObjectName(sa);
         } catch (Exception e) {
             LOGGER.error(e.getMessage());
             throw new JBIException(e);

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/SharedLibraryInstaller.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/SharedLibraryInstaller.java?rev=966045&r1=966044&r2=966045&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/SharedLibraryInstaller.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/SharedLibraryInstaller.java Tue Jul 20 22:44:31 2010
@@ -50,7 +50,7 @@ public class SharedLibraryInstaller exte
     public ObjectName install() throws JBIException {
         try {
             SharedLibrary sl = deployer.registerSharedLibrary(bundle, descriptor.getSharedLibrary(), createClassLoader());
-            return deployer.getManagementStrategy().getManagedObjectName(sl, null, ObjectName.class);
+            return deployer.getEnvironment().getManagedObjectName(sl);
         } catch (Exception e) {
             LOGGER.error(e.getMessage());
             throw new JBIException(e);

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/resources/OSGI-INF/blueprint/servicemix-jbi-deployer.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/resources/OSGI-INF/blueprint/servicemix-jbi-deployer.xml?rev=966045&r1=966044&r2=966045&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/resources/OSGI-INF/blueprint/servicemix-jbi-deployer.xml (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/resources/OSGI-INF/blueprint/servicemix-jbi-deployer.xml Tue Jul 20 22:44:31 2010
@@ -22,12 +22,10 @@
            xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0">
 
     <!-- JBI Deployer -->
-    <bean id="deployer" class="org.apache.servicemix.jbi.deployer.impl.Deployer" init-method="init" destroy-method="destroy">
+    <bean id="deployer" class="org.apache.servicemix.jbi.deployer.impl.Deployer" init-method="init" destroy-method="destroy" depends-on="managementStrategy">
         <property name="autoStart" value="true" />
         <property name="endpointListener" ref="endpointListener" />
         <property name="environment" ref="environment" />
-        <property name="managementStrategy" ref="managementStrategy" />
-        <property name="mbeanServer" ref="mbeanServer" />
         <property name="shutdownTimeout" value="${shutdownTimeout}" />
         <property name="bundleContext" ref="blueprintBundleContext"/>
     </bean>
@@ -77,32 +75,32 @@
     <!-- Expose AdminCommandsService in OSGi -->
     <service ref="adminCommandsService" interface="org.apache.servicemix.jbi.deployer.AdminCommandsService" />
 
-    <!-- Retrieve ManagementStrategy from OSGi service registry -->
-    <reference id="managementStrategy" interface="org.fusesource.commons.management.ManagementStrategy" />
-
     <!-- Environment -->
     <bean id="environment" class="org.apache.servicemix.jbi.runtime.impl.EnvironmentImpl">
-        <property name="transactionManagers" ref="transactionManagers" />
-        <property name="mbeanServer" ref="mbeanServer" />
-        <property name="namingContext" ref="namingContext" />
+        <property name="bundleContext" ref="blueprintBundleContext"/>
+        <property name="namingContext" ref="namingContext"/>
     </bean>
 
+    <!-- Retrieve ManagementStrategy from OSGi service registry -->
+    <reference id="managementStrategy" interface="org.fusesource.commons.management.ManagementStrategy">
+        <reference-listener ref="environment" bind-method="bindManagementStrategy" unbind-method="unbindManagementStrategy"/>
+    </reference>
+
+    <!-- Retrieve ManagementStrategy from OSGi service registry -->
+    <reference id="mbeanServer" interface="javax.management.MBeanServer">
+        <reference-listener ref="environment" bind-method="bindMBeanServer" unbind-method="unbindMBeanServer"/>
+    </reference>
+
     <!-- Reference to the Transaction Manager -->
-    <reference-list id="transactionManagers"
-                    interface="javax.transaction.TransactionManager"
-                    availability="optional"
-                    ext:proxy-method="greedy"/>
+    <reference id="transactionManager" interface="javax.transaction.TransactionManager" availability="optional">
+        <reference-listener ref="environment" bind-method="bindTransactionManager" unbind-method="unbindTransactionManager"/>
+    </reference>
 
     <!-- The InitialContext -->
     <bean id="namingContext" class="javax.naming.InitialContext">
         <argument><null/></argument>
     </bean>
 
-    <!-- MBeanServer -->
-    <reference id="mbeanServer"
-               interface="javax.management.MBeanServer"
-               availability="mandatory" />
-
     <cm:property-placeholder persistent-id="org.apache.servicemix.jbi">
         <cm:default-properties>
             <cm:property name="shutdownTimeout" value="0"/>

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/test/java/org/apache/servicemix/jbi/deployer/artifacts/ServiceAssemblyImplTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/test/java/org/apache/servicemix/jbi/deployer/artifacts/ServiceAssemblyImplTest.java?rev=966045&r1=966044&r2=966045&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/test/java/org/apache/servicemix/jbi/deployer/artifacts/ServiceAssemblyImplTest.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/test/java/org/apache/servicemix/jbi/deployer/artifacts/ServiceAssemblyImplTest.java Tue Jul 20 22:44:31 2010
@@ -35,7 +35,6 @@ import static org.easymock.EasyMock.crea
 import static org.easymock.EasyMock.expect;
 import static org.easymock.EasyMock.replay;
 import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.prefs.Preferences;
 
 /**
  * Test cases for {@link ServiceAssemblyImpl}

Modified: servicemix/smx4/nmr/trunk/jbi/osgi/src/main/resources/OSGI-INF/blueprint/servicemix-jbi.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/osgi/src/main/resources/OSGI-INF/blueprint/servicemix-jbi.xml?rev=966045&r1=966044&r2=966045&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/osgi/src/main/resources/OSGI-INF/blueprint/servicemix-jbi.xml (original)
+++ servicemix/smx4/nmr/trunk/jbi/osgi/src/main/resources/OSGI-INF/blueprint/servicemix-jbi.xml Tue Jul 20 22:44:31 2010
@@ -28,21 +28,16 @@
     </type-converters>
 
     <!-- JBI Component Registry -->
-    <bean id="componentRegistry" class="org.apache.servicemix.jbi.runtime.impl.ComponentRegistryImpl">
+    <bean id="componentRegistry" class="org.apache.servicemix.jbi.runtime.impl.ComponentRegistryImpl" depends-on="managementStrategy">
         <property name="nmr" ref="nmrWrapper" />
         <property name="documentRepository" ref="documentRepository" />
-        <property name="managementStrategy" ref="managementStrategy" />
         <property name="environment" ref="environment" />
     </bean>
 
-    <!-- Retrieve ManagementStrategy from OSGi service registry -->
-    <reference id="managementStrategy" interface="org.fusesource.commons.management.ManagementStrategy" />
-
     <!-- Environment -->
     <bean id="environment" class="org.apache.servicemix.jbi.runtime.impl.EnvironmentImpl">
-        <property name="transactionManagers" ref="transactionManagers" />
-        <property name="mbeanServers" ref="mbeanServers" />
-        <property name="namingContext" ref="namingContext" />
+        <property name="bundleContext" ref="blueprintBundleContext"/>
+        <property name="namingContext" ref="namingContext"/>
     </bean>
 
     <bean id="nmrWrapper" class="org.apache.servicemix.jbi.osgi.NMRWrapper" init-method="init">
@@ -66,16 +61,21 @@
     <reference id="documentRepository"
                     interface="org.apache.servicemix.document.DocumentRepository" />
 
+    <!-- Retrieve ManagementStrategy from OSGi service registry -->
+    <reference id="managementStrategy" interface="org.fusesource.commons.management.ManagementStrategy">
+        <reference-listener ref="environment" bind-method="bindManagementStrategy" unbind-method="unbindManagementStrategy"/>
+    </reference>
+
+    <!-- Retrieve ManagementStrategy from OSGi service registry -->
+    <reference id="mbeanServer" interface="javax.management.MBeanServer">
+        <reference-listener ref="environment" bind-method="bindMBeanServer" unbind-method="unbindMBeanServer"/>
+    </reference>
+
     <!-- Reference to the Transaction Manager -->
-    <reference-list id="transactionManagers"
-                    interface="javax.transaction.TransactionManager"
-                    availability="optional"
-                    ext:proxy-method="greedy"/>
-
-    <!-- Reference to the JMX server -->
-    <reference-list id="mbeanServers"
-                    interface="javax.management.MBeanServer"
-                    availability="optional"/>
+    <reference id="transactionManager" interface="javax.transaction.TransactionManager" availability="optional">
+        <reference-listener ref="environment" bind-method="bindTransactionManager" unbind-method="unbindTransactionManager"/>
+    </reference>
+
 
     <!-- The InitialContext -->
     <bean id="namingContext" class="javax.naming.InitialContext">

Modified: servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/Environment.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/Environment.java?rev=966045&r1=966044&r2=966045&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/Environment.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/Environment.java Tue Jul 20 22:44:31 2010
@@ -16,7 +16,9 @@
  */
 package org.apache.servicemix.jbi.runtime;
 
+import java.util.EventObject;
 import javax.management.MBeanServer;
+import javax.management.ObjectName;
 import javax.naming.InitialContext;
 
 /**
@@ -29,4 +31,19 @@ public interface Environment {
 
     InitialContext getNamingContext();
 
+    void manageObject(Object managedObject) throws Exception;
+
+    void unmanageObject(Object managedObject) throws Exception;
+
+    void unmanageNamedObject(ObjectName name) throws Exception;
+
+    ObjectName getManagedObjectName(Object object) throws Exception;
+
+    ObjectName getManagedObjectName(Object object, String customName) throws Exception;
+
+    String getJmxDomainName() throws Exception;
+
+    boolean isManaged(Object managedObject);
+
+    void notify(EventObject event) throws Exception;
 }

Modified: servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/AbstractComponentContext.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/AbstractComponentContext.java?rev=966045&r1=966044&r2=966045&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/AbstractComponentContext.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/AbstractComponentContext.java Tue Jul 20 22:44:31 2010
@@ -16,43 +16,41 @@
  */
 package org.apache.servicemix.jbi.runtime.impl;
 
-import java.util.Map;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
-import java.util.ArrayList;
+import java.util.Map;
 import java.util.MissingResourceException;
 import java.util.logging.Logger;
-import java.io.InputStream;
-import java.io.IOException;
-import java.net.URL;
-
-import javax.jbi.component.ComponentContext;
-import javax.jbi.servicedesc.ServiceEndpoint;
 import javax.jbi.JBIException;
+import javax.jbi.component.ComponentContext;
 import javax.jbi.management.MBeanNames;
 import javax.jbi.messaging.DeliveryChannel;
 import javax.jbi.messaging.MessagingException;
-import javax.xml.namespace.QName;
+import javax.jbi.servicedesc.ServiceEndpoint;
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
 import javax.naming.InitialContext;
+import javax.xml.namespace.QName;
 
-import org.w3c.dom.Document;
-import org.w3c.dom.DocumentFragment;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.Node;
-
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.jbi.runtime.ComponentWrapper;
+import org.apache.servicemix.jbi.runtime.impl.utils.DOMUtil;
+import org.apache.servicemix.jbi.runtime.impl.utils.URIResolver;
+import org.apache.servicemix.jbi.runtime.impl.utils.WSAddressingConstants;
 import org.apache.servicemix.nmr.api.Endpoint;
 import org.apache.servicemix.nmr.api.NMR;
 import org.apache.servicemix.nmr.api.internal.InternalEndpoint;
-import org.apache.servicemix.jbi.runtime.impl.utils.DOMUtil;
-import org.apache.servicemix.jbi.runtime.impl.utils.WSAddressingConstants;
-import org.apache.servicemix.jbi.runtime.impl.utils.URIResolver;
-import org.apache.servicemix.jbi.runtime.ComponentWrapper;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.servicemix.nmr.management.Nameable;
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
 
 public abstract class AbstractComponentContext implements ComponentContext, MBeanNames {
 
@@ -64,24 +62,8 @@ public abstract class AbstractComponentC
     protected DeliveryChannel dc;
     protected ComponentRegistryImpl componentRegistry;
 
-    protected MBeanServer mbeanServer;
-    protected InitialContext initialContext;
-    protected Object transactionManager;
-
     public AbstractComponentContext(ComponentRegistryImpl componentRegistry) {
         this.componentRegistry = componentRegistry;
-        if (componentRegistry.getEnvironment() != null) {
-            MBeanServer mbs = componentRegistry.getEnvironment().getMBeanServer();
-            if (componentRegistry.getManagementStrategy() != null) {
-                this.mbeanServer = new MBeanServerWrapper(mbs, componentRegistry.getManagementStrategy());
-            } else {
-                this.mbeanServer = mbs;
-            }
-
-            this.mbeanServer = componentRegistry.getEnvironment().getMBeanServer();
-            this.initialContext = componentRegistry.getEnvironment().getNamingContext();
-            this.transactionManager = componentRegistry.getEnvironment().getTransactionManager();
-        }
     }
 
     public NMR getNmr() {
@@ -245,59 +227,53 @@ public abstract class AbstractComponentC
     }
 
     public MBeanServer getMBeanServer() {
-        return mbeanServer;
+        return componentRegistry.getEnvironment().getMBeanServer();
     }
 
     public InitialContext getNamingContext() {
-        return initialContext;
+        return componentRegistry.getEnvironment().getNamingContext();
     }
 
     public Object getTransactionManager() {
-        return transactionManager;
+        return componentRegistry.getEnvironment().getTransactionManager();
     }
 
     public ObjectName createCustomComponentMBeanName(String customName) {
         ObjectName name = null;
-        if (componentRegistry.getManagementStrategy() != null) {
-            try {
-                Nameable nameable = new Nameable() {
-                    public String getName() {
-                        return getComponentName();
-                    }                    
-                    public String getParent() {
-                        return null;
-                    }
-                    public String getMainType() {
-                        return null;
-                    }
-                    public String getSubType() {
-                        return null;
-                    }
-                    public String getVersion() {
-                        return null;
-                    }
-                    public Class getPrimaryInterface() {
-                        return null;
-                    }
-                };
-                name = componentRegistry.getManagementStrategy().getManagedObjectName(nameable, 
-                                                                                      customName, 
-                                                                                      ObjectName.class);
-            } catch (Exception e) {
-                // ignore
-            }
+        try {
+            Nameable nameable = new Nameable() {
+                public String getName() {
+                    return getComponentName();
+                }
+                public String getParent() {
+                    return null;
+                }
+                public String getMainType() {
+                    return null;
+                }
+                public String getSubType() {
+                    return null;
+                }
+                public String getVersion() {
+                    return null;
+                }
+                public Class getPrimaryInterface() {
+                    return null;
+                }
+            };
+            name = componentRegistry.getEnvironment().getManagedObjectName(nameable, customName);
+        } catch (Exception e) {
+            // ignore
         }
         return name;
     }
 
     public String getJmxDomainName() {
         String name = null;
-        if (this.componentRegistry.getManagementStrategy() != null) {
-            try {
-                name = componentRegistry.getManagementStrategy().getManagedObjectName(null, null, String.class);
-            } catch (Exception e) {
-                // ignore
-            }
+        try {
+            name = componentRegistry.getEnvironment().getJmxDomainName();
+        } catch (Exception e) {
+            // ignore
         }
         return name;
     }

Modified: servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentRegistryImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentRegistryImpl.java?rev=966045&r1=966044&r2=966045&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentRegistryImpl.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentRegistryImpl.java Tue Jul 20 22:44:31 2010
@@ -43,7 +43,6 @@ public class ComponentRegistryImpl exten
     private DocumentRepository documentRepository;
     private Map<String, ComponentContextImpl> contexts;
     private Environment environment;
-    private ManagementStrategy managementStrategy;
 
     public ComponentRegistryImpl() {
         contexts = new ConcurrentHashMap<String, ComponentContextImpl>();
@@ -65,14 +64,6 @@ public class ComponentRegistryImpl exten
         this.environment = environment;
     }
 
-    public ManagementStrategy getManagementStrategy() {
-        return managementStrategy;
-    }
-
-    public void setManagementStrategy(ManagementStrategy managementStrategy) {
-        this.managementStrategy = managementStrategy;
-    }
-    
     public DocumentRepository getDocumentRepository() {
         return documentRepository;
     }

Modified: servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/EnvironmentImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/EnvironmentImpl.java?rev=966045&r1=966044&r2=966045&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/EnvironmentImpl.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/EnvironmentImpl.java Tue Jul 20 22:44:31 2010
@@ -16,88 +16,208 @@
  */
 package org.apache.servicemix.jbi.runtime.impl;
 
-import java.util.List;
-
-import javax.naming.InitialContext;
+import java.util.EventObject;
+import java.util.HashSet;
+import java.util.Set;
 import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.naming.InitialContext;
 
 import org.apache.servicemix.jbi.runtime.Environment;
+import org.fusesource.commons.management.ManagementStrategy;
+import org.fusesource.commons.management.Statistic;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
 
 /**
  */
 public class EnvironmentImpl implements Environment {
 
+    private BundleContext bundleContext;
     private Object transactionManager;
-    private List transactionManagers;
     private InitialContext namingContext;
-    private List<InitialContext> namingContexts;
-    private MBeanServer mbeanServer;
-    private List<MBeanServer> mbeanServers;
 
-    public MBeanServer getMBeanServer() {
-        if (mbeanServer != null) {
-            return mbeanServer;
-        }
-        if (mbeanServers != null && !mbeanServers.isEmpty()) {
-            return mbeanServers.get(0);
-        }
-        return null;
-    }
+    private ManagementStrategyWrapper managementStrategy = new ManagementStrategyWrapper();
+    private ManagementStrategy currentMs;
+    private ServiceReference currentMsRef;
+    private MBeanServerWrapper mbeanServer = new MBeanServerWrapper(null, managementStrategy);
 
-    public void setMbeanServer(MBeanServer mbeanServer) {
-        this.mbeanServer = mbeanServer;
+    public void setBundleContext(BundleContext bundleContext) {
+        this.bundleContext = bundleContext;
     }
 
-    public List<MBeanServer> getMbeanServers() {
-        return mbeanServers;
+    public ManagementStrategy getManagementStrategy() {
+        return managementStrategy;
     }
 
-    public void setMbeanServers(List<MBeanServer> mbeanServers) {
-        this.mbeanServers = mbeanServers;
+    public void bindManagementStrategy(ManagementStrategy ms) {
+        managementStrategy.setDelegate(ms);
     }
 
-
-    public Object getTransactionManager() {
-        if (transactionManager != null) {
-            return transactionManager;
+    public void bindManagementStrategy(ServiceReference reference) {
+        ManagementStrategy ms = (ManagementStrategy) bundleContext.getService(reference);
+        managementStrategy.updateRef(currentMs, ms);
+        if (currentMsRef != null) {
+            bundleContext.ungetService(currentMsRef);
         }
-        if (transactionManagers != null && !transactionManagers.isEmpty()) {
-            return transactionManagers.get(0);
+        currentMs = ms;
+        currentMsRef = reference;
+    }
+
+    public void unbindManagementStrategy(ServiceReference ref) {
+        managementStrategy.updateRef(currentMs, null);
+        if (currentMsRef != null) {
+            bundleContext.ungetService(currentMsRef);
         }
-        return null;
+        currentMs = null;
+        currentMsRef = null;
+    }
+
+    public MBeanServer getMBeanServer() {
+        return mbeanServer;
+    }
+
+    public void bindMBeanServer(MBeanServer mbs) {
+        mbeanServer.setDelegate(mbs);
+    }
+
+    public void unbindMBeanServer(MBeanServer mbs) {
     }
 
-    public void setTransactionManager(Object transactionManager) {
-        this.transactionManager = transactionManager;
+    public Object getTransactionManager() {
+        return transactionManager;
     }
 
-    public List getTransactionManagers() {
-        return transactionManagers;
+    public void bindTransactionManager(ServiceReference reference) {
+        transactionManager = bundleContext.getService(reference);
+        bundleContext.ungetService(reference); // do not keep the reference count, as it's done by blueprint
     }
 
-    public void setTransactionManagers(List transactionManagers) {
-        this.transactionManagers = transactionManagers;
+    public void unbindTransactionManager(ServiceReference reference) {
+        transactionManager = null;
     }
 
     public InitialContext getNamingContext() {
-        if (namingContext != null) {
-            return namingContext;
-        }
-        if (namingContexts != null && !namingContexts.isEmpty()) {
-            return namingContexts.get(0);
-        }
-        return null;
+        return namingContext;
     }
 
     public void setNamingContext(InitialContext namingContext) {
         this.namingContext = namingContext;
     }
 
-    public List<InitialContext> getNamingContexts() {
-        return namingContexts;
+    public ObjectName getManagedObjectName(Object object) throws Exception {
+        return getManagementStrategy().getManagedObjectName(object, null, ObjectName.class);
+    }
+
+    public ObjectName getManagedObjectName(Object object, String customName) throws Exception {
+        return getManagementStrategy().getManagedObjectName(object, customName, ObjectName.class);
     }
 
-    public void setNamingContexts(List<InitialContext> namingContexts) {
-        this.namingContexts = namingContexts;
+    public String getJmxDomainName() throws Exception {
+        return getManagementStrategy().getManagedObjectName(null, null, String.class);
+    }
+
+    public void manageObject(Object managedObject) throws Exception {
+        getManagementStrategy().manageObject(managedObject);
+    }
+
+    public void unmanageObject(Object managedObject) throws Exception {
+        getManagementStrategy().unmanageObject(managedObject);
+    }
+
+    public void unmanageNamedObject(ObjectName name) throws Exception {
+        getManagementStrategy().unmanageNamedObject(name);
+    }
+
+    public boolean isManaged(Object managedObject) {
+        return getManagementStrategy().isManaged(managedObject, null);
+    }
+
+    public void notify(EventObject event) throws Exception {
+        getManagementStrategy().notify(event);
+    }
+
+
+    public static class ManagementStrategyWrapper implements ManagementStrategy {
+
+        private ManagementStrategy delegate;
+        private boolean isValid;
+        private Set<Object> managedObjects = new HashSet<Object>();
+
+        public synchronized ManagementStrategy getDelegate() {
+            return delegate;
+        }
+
+        public synchronized void setDelegate(ManagementStrategy delegate) {
+            this.delegate = delegate;
+        }
+
+        public synchronized void updateRef(ManagementStrategy oldMs, ManagementStrategy newMs) {
+            if (oldMs != newMs) {
+                if (oldMs != null) {
+                    for (Object managedObject : managedObjects) {
+                        try {
+                            oldMs.unmanageObject(managedObject);
+                        } catch (Exception e) {
+                            // Ignore
+                        }
+                    }
+                }
+                if (newMs != null) {
+                    for (Object managedObject : managedObjects) {
+                        try {
+                            newMs.manageObject(managedObject);
+                        } catch (Exception e) {
+                            // Ignore
+                        }
+                    }
+                }
+            }
+            isValid = newMs != null;
+        }
+
+        public synchronized void manageObject(Object managedObject) throws Exception {
+            if (isValid) {
+                delegate.manageObject(managedObject);
+            }
+            managedObjects.add(managedObject);
+        }
+
+        public synchronized void manageNamedObject(Object managedObject, Object preferedName) throws Exception {
+            delegate.manageNamedObject(managedObject, preferedName);
+        }
+
+        public synchronized <T> T getManagedObjectName(Object managableObject, String customName, Class<T> nameType) throws Exception {
+            return delegate.getManagedObjectName(managableObject, customName, nameType);
+        }
+
+        public synchronized void unmanageObject(Object managedObject) throws Exception {
+            if (isValid) {
+                delegate.unmanageObject(managedObject);
+            }
+            managedObjects.remove(managedObject);
+        }
+
+        public synchronized void unmanageNamedObject(Object name) throws Exception {
+            delegate.unmanageNamedObject(name);
+        }
+
+        public synchronized boolean isManaged(Object managableObject, Object name) {
+            if (isValid) {
+                return delegate.isManaged(managableObject, name);
+            } else if (managableObject != null) {
+                return managedObjects.contains(managableObject);
+            } else {
+                return false;
+            }
+        }
+
+        public synchronized void notify(EventObject event) throws Exception {
+            delegate.notify(event);
+        }
+
+        public synchronized Statistic createStatistic(String name, Object owner, Statistic.UpdateMode updateMode) {
+            return delegate.createStatistic(name, owner, updateMode);
+        }
     }
 }

Modified: servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/MBeanServerWrapper.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/MBeanServerWrapper.java?rev=966045&r1=966044&r2=966045&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/MBeanServerWrapper.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/MBeanServerWrapper.java Tue Jul 20 22:44:31 2010
@@ -48,12 +48,16 @@ public class MBeanServerWrapper implemen
 
     private MBeanServer delegate;
     private ManagementStrategy strategy;
-    
+
     MBeanServerWrapper(MBeanServer delegate, ManagementStrategy strategy) {
-        this.delegate = delegate;
         this.strategy = strategy;
+        this.delegate = delegate;
     }
-    
+
+    public void setDelegate(MBeanServer delegate) {
+        this.delegate = delegate;
+    }
+
     public void addNotificationListener(ObjectName name,
             NotificationListener listener, NotificationFilter filter,
             Object handback) throws InstanceNotFoundException {

Modified: servicemix/smx4/nmr/trunk/nmr/management/src/main/java/org/apache/servicemix/nmr/management/ManagedEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/management/src/main/java/org/apache/servicemix/nmr/management/ManagedEndpoint.java?rev=966045&r1=966044&r2=966045&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/management/src/main/java/org/apache/servicemix/nmr/management/ManagedEndpoint.java (original)
+++ servicemix/smx4/nmr/trunk/nmr/management/src/main/java/org/apache/servicemix/nmr/management/ManagedEndpoint.java Tue Jul 20 22:44:31 2010
@@ -34,7 +34,6 @@ import org.fusesource.commons.management
 public class ManagedEndpoint extends StandardMBean implements ManagedEndpointMBean {
 
     protected final InternalEndpoint endpoint;
-    protected final Map<String,?> properties;
     protected final Statistic inboundExchanges;
     protected final Statistic outboundExchanges;
     protected final Statistic inboundExchangeRate;
@@ -42,11 +41,9 @@ public class ManagedEndpoint extends Sta
     protected final ManagementStrategy managementStrategy;
 
     public ManagedEndpoint(InternalEndpoint endpoint, 
-                           Map<String,?> properties, 
                            ManagementStrategy managementStrategy) throws NotCompliantMBeanException {
         super(ManagedEndpointMBean.class);
         this.endpoint = endpoint;
-        this.properties = new HashMap<String,Object>(properties);
         this.managementStrategy = managementStrategy;
         this.inboundExchanges = managementStrategy.createStatistic("inboundExchanges", 
                                                                    this, 
@@ -82,7 +79,7 @@ public class ManagedEndpoint extends Sta
      * @return the name of the endpoint
      */
     public String getName() {
-        return (String) properties.get(Endpoint.NAME);
+        return (String) getProperties().get(Endpoint.NAME);
     }
 
     /**
@@ -91,7 +88,7 @@ public class ManagedEndpoint extends Sta
      * @return the properties of the endpoint
      */
     public Map<String, ?> getProperties() {
-        return properties;
+        return endpoint.getMetaData();
     }
 
     /**

Modified: servicemix/smx4/nmr/trunk/nmr/management/src/main/java/org/apache/servicemix/nmr/management/ManagementAgent.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/management/src/main/java/org/apache/servicemix/nmr/management/ManagementAgent.java?rev=966045&r1=966044&r2=966045&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/management/src/main/java/org/apache/servicemix/nmr/management/ManagementAgent.java (original)
+++ servicemix/smx4/nmr/trunk/nmr/management/src/main/java/org/apache/servicemix/nmr/management/ManagementAgent.java Tue Jul 20 22:44:31 2010
@@ -18,8 +18,9 @@ package org.apache.servicemix.nmr.manage
 
 import java.lang.reflect.UndeclaredThrowableException;
 import java.util.EventObject;
-import java.util.HashSet;
-import java.util.Set;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import javax.management.InstanceAlreadyExistsException;
 import javax.management.JMException;
 import javax.management.MBeanServer;
@@ -37,6 +38,7 @@ import org.fusesource.commons.management
 import org.fusesource.commons.management.Statistic;
 import org.fusesource.commons.management.Statistic.UpdateMode;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.blueprint.container.ServiceUnavailableException;
 
@@ -48,7 +50,7 @@ public class ManagementAgent implements 
 
     private boolean enabled;
     private MBeanServer mbeanServer;
-    private Set<ObjectName> mbeans = new HashSet<ObjectName>();
+    private Map<ObjectName, Object> mbeans = new HashMap<ObjectName, Object>();
     private NamingStrategy namingStrategy;
     private BundleContext bundleContext;
     private ServiceRegistration serviceRegistration;
@@ -59,7 +61,7 @@ public class ManagementAgent implements 
     /**
      * @see org.fusesource.commons.management.ManagementStrategy#manageObject(java.lang.Object)
      */
-    public void manageObject(Object managedObject) throws Exception {
+    public synchronized void manageObject(Object managedObject) throws Exception {
         ObjectName objectName = getManagedObjectName(managedObject, null, ObjectName.class);
         manageNamedObject(managedObject, objectName);
     }
@@ -67,7 +69,7 @@ public class ManagementAgent implements 
     /**
      * @see org.fusesource.commons.management.ManagementStrategy#getManagedObjectName(java.lang.Object,java.lang.String,java.lang.Class)
      */
-    public <T> T getManagedObjectName(Object managableObject, 
+    public synchronized <T> T getManagedObjectName(Object managableObject,
                                       String customName, 
                                       Class<T> nameType) throws Exception {
         return String.class.equals(nameType) && managableObject == null && customName == null
@@ -80,11 +82,11 @@ public class ManagementAgent implements 
     /**
      * @see org.fusesource.commons.management.ManagementStrategy#manageNamedObject(java.lang.Object,java.lang.Object)
      */
-    public void manageNamedObject(Object managedObject, Object preferredName) throws Exception {
+    public synchronized void manageNamedObject(Object managedObject, Object preferredName) throws Exception {
         managedObject = getTypeSpecificManagedObject(managedObject);
         if (preferredName instanceof ObjectName && managedObject != null) {
             try {
-                register(managedObject, (ObjectName)preferredName);
+                register(managedObject, (ObjectName) preferredName);
             } catch (Exception ex) {
                 throw (JMException) new JMException(ex.getMessage()).initCause(ex);
             }
@@ -94,7 +96,7 @@ public class ManagementAgent implements 
     /**
      * @see org.fusesource.commons.management.ManagementStrategy#unmanageObject(java.lang.Object)
      */
-    public void unmanageObject(Object managedObject) throws Exception {
+    public synchronized void unmanageObject(Object managedObject) throws Exception {
         ObjectName objectName = getManagedObjectName(managedObject, null, ObjectName.class);
         unmanageNamedObject(objectName);
     }
@@ -102,16 +104,16 @@ public class ManagementAgent implements 
     /**
      * @see org.fusesource.commons.management.ManagementStrategy#unmanageNamedObject(java.lang.Object)
      */
-    public void unmanageNamedObject(Object name) throws Exception {
+    public synchronized void unmanageNamedObject(Object name) throws Exception {
         if (name instanceof ObjectName) {
-            unregister((ObjectName)name);
+            unregister((ObjectName) name);
         }
     }
     
     /**
      * @see org.fusesource.commons.management.ManagementStrategy#isManaged(java.lang.Object,java.lang.Object)
      */
-    public boolean isManaged(Object managableObject, Object name) {
+    public synchronized boolean isManaged(Object managableObject, Object name) {
         try {
             return managableObject != null 
                    ? getMbeanServer().isRegistered(
@@ -168,7 +170,28 @@ public class ManagementAgent implements 
     public void setMbeanServer(MBeanServer mbeanServer) {
         this.mbeanServer = mbeanServer;
     }
-    
+
+    public synchronized void bindMBeanServer(ServiceReference reference) throws Exception {
+        if (isEnabled()) {
+            MBeanServer mbeanServer = (MBeanServer) bundleContext.getService(reference);
+            bundleContext.ungetService(reference); // do not keep the reference count, as it's done by blueprint
+            if (mbeanServer != this.mbeanServer) {
+                unregisterObjects();
+                this.mbeanServer = mbeanServer;
+                registerObjects();
+            }
+            registerService();
+        }
+    }
+
+    public synchronized void unbindMBeanServer(ServiceReference reference) {
+        if (isEnabled()) {
+            unregisterObjects();
+            this.mbeanServer = null;
+            unregisterService();
+        }
+    }
+
     public NamingStrategy getNamingStrategy() {
         return namingStrategy;
     }
@@ -177,66 +200,81 @@ public class ManagementAgent implements 
         this.namingStrategy = namingStrategy;
     }
     
-    public void init() throws Exception {
-        if (isEnabled()) {
-            registerService();
-        }        
-    }
-           
-
-    public void destroy() throws Exception {
-        // Using the array to hold the busMBeans to avoid the
-        // CurrentModificationException
-        try {
-            Object[] mBeans = mbeans.toArray();
-            int caught = 0;
-            for (Object name : mBeans) {
-                mbeans.remove((ObjectName)name);
-                try {
-                    unregister((ObjectName)name);
-                } catch (JMException jmex) {
-                    LOG.info("Exception unregistering MBean", jmex);
-                    caught++;
-                } catch (ServiceUnavailableException sue) {
-                    // due to timing / shutdown ordering issue that we may
-                    // ignore as not unregistering from an already shutdown 
-                    // blueprint container is quite harmless
-                }
-            }
-            if (caught > 0) {
-                LOG.warn("A number of " + caught
-                        + " exceptions caught while unregistering MBeans during stop operation.  "
-                        + "See INFO log for details.");
+    protected void registerObjects() {
+        ObjectName[] mBeans = mbeans.keySet().toArray(new ObjectName[mbeans.size()]);
+        int caught = 0;
+        for (ObjectName name : mBeans) {
+            try {
+                register(mbeans.get(name), name);
+            } catch (JMException jmex) {
+                LOG.info("Exception unregistering MBean", jmex);
+                caught++;
+            } catch (ServiceUnavailableException sue) {
+                // due to timing / shutdown ordering issue that we may
+                // ignore as not unregistering from an already shutdown
+                // blueprint container is quite harmless
             }
-        } finally {
-            unregisterService();
+        }
+        if (caught > 0) {
+            LOG.warn("A number of " + caught
+                    + " exceptions caught while unregistering MBeans during stop operation.  "
+                    + "See INFO log for details.");
         }
     }
 
-    public void register(Object obj, ObjectName name) throws JMException {
+    protected void register(Object obj, ObjectName name) throws JMException {
         register(obj, name, !(obj instanceof ManagedEndpoint));
     }
 
-    public void register(Object obj, ObjectName name, boolean forceRegistration) throws JMException {
-        try {
-            registerMBeanWithServer(obj, name, forceRegistration);
-        } catch (UndeclaredThrowableException ute) {
-            if (ute.getCause() instanceof RuntimeException) {
-                LOG.warn("MBean registration failed: ", ute.getCause());
-                throw (RuntimeException)ute.getCause();
-            } else {
-                LOG.warn("MBean registration failed: ", ute.getCause());
-                throw new JMException(ute.getCause().getMessage());
+    protected void register(Object obj, ObjectName name, boolean forceRegistration) throws JMException {
+        if (mbeanServer == null) {
+            mbeans.put(name, obj);
+        } else {
+            try {
+                registerMBeanWithServer(obj, name, forceRegistration);
+            } catch (UndeclaredThrowableException ute) {
+                if (ute.getCause() instanceof RuntimeException) {
+                    LOG.warn("MBean registration failed: ", ute.getCause());
+                    throw (RuntimeException)ute.getCause();
+                } else {
+                    LOG.warn("MBean registration failed: ", ute.getCause());
+                    throw new JMException(ute.getCause().getMessage());
+                }
+            }
+        }
+    }
+
+    protected void unregisterObjects() {
+        ObjectName[] mBeans = mbeans.keySet().toArray(new ObjectName[mbeans.size()]);
+        int caught = 0;
+        for (ObjectName name : mBeans) {
+            try {
+                unregister(name);
+            } catch (JMException jmex) {
+                LOG.info("Exception unregistering MBean", jmex);
+                caught++;
+            } catch (ServiceUnavailableException sue) {
+                // due to timing / shutdown ordering issue that we may
+                // ignore as not unregistering from an already shutdown
+                // blueprint container is quite harmless
             }
         }
+        if (caught > 0) {
+            LOG.warn("A number of " + caught
+                    + " exceptions caught while unregistering MBeans during stop operation.  "
+                    + "See INFO log for details.");
+        }
     }
 
-    public void unregister(ObjectName name) throws JMException {
-        mbeanServer.unregisterMBean(name);
+    protected void unregister(ObjectName name) throws JMException {
+        mbeans.remove(name);
+        if (mbeanServer != null) {
+            mbeanServer.unregisterMBean(name);
+        }
     }
 
-    private void registerMBeanWithServer(Object obj, ObjectName name, boolean forceRegistration) throws JMException {
-        ObjectInstance instance = null;
+    protected void registerMBeanWithServer(Object obj, ObjectName name, boolean forceRegistration) throws JMException {
+        ObjectInstance instance;
         try {
             instance = mbeanServer.registerMBean(obj, name);
         } catch (InstanceAlreadyExistsException e) {
@@ -249,7 +287,7 @@ public class ManagementAgent implements 
         }
 
         if (instance != null) {
-            mbeans.add(name);
+            mbeans.put(name, obj);
         }
     }
     
@@ -264,7 +302,7 @@ public class ManagementAgent implements 
         }
     }
     
-    private ObjectName getTypeSpecificObjectName(Object mo, String customName) throws MalformedObjectNameException {
+    protected ObjectName getTypeSpecificObjectName(Object mo, String customName) throws MalformedObjectNameException {
         return mo instanceof ManagedEndpoint
                ? namingStrategy.getObjectName((ManagedEndpoint)mo)
                : mo instanceof Nameable
@@ -275,7 +313,7 @@ public class ManagementAgent implements 
     }
 
     
-    private Object getTypeSpecificManagedObject(Object object) throws NotCompliantMBeanException {
+    protected Object getTypeSpecificManagedObject(Object object) throws NotCompliantMBeanException {
         return object instanceof ManagedEndpoint
                ? object
                : object instanceof Nameable

Modified: servicemix/smx4/nmr/trunk/nmr/management/src/main/java/org/apache/servicemix/nmr/management/ManagementEndpointRegistry.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/management/src/main/java/org/apache/servicemix/nmr/management/ManagementEndpointRegistry.java?rev=966045&r1=966044&r2=966045&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/management/src/main/java/org/apache/servicemix/nmr/management/ManagementEndpointRegistry.java (original)
+++ servicemix/smx4/nmr/trunk/nmr/management/src/main/java/org/apache/servicemix/nmr/management/ManagementEndpointRegistry.java Tue Jul 20 22:44:31 2010
@@ -28,6 +28,9 @@ import org.apache.servicemix.nmr.api.eve
 import org.apache.servicemix.nmr.api.internal.InternalEndpoint;
 import org.apache.servicemix.nmr.api.internal.InternalExchange;
 import org.fusesource.commons.management.ManagementStrategy;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.util.tracker.ServiceTracker;
 
 /**
  */
@@ -35,45 +38,126 @@ public class ManagementEndpointRegistry 
 
     private static final transient Log LOG = LogFactory.getLog(ManagementEndpointRegistry.class);
 
+    private BundleContext bundleContext;
     private ManagementStrategy managementStrategy;
-    private Map<String, ManagedEndpoint> endpoints;
+    private final Map<String, InternalEndpoint> internalEndpoints;
+    private final Map<String, ManagedEndpoint> endpoints;
+    private ServiceTracker managementStrategyTracker;
+    private ServiceTracker endpointTracker;
 
     public ManagementEndpointRegistry() {
         endpoints = new ConcurrentHashMap<String, ManagedEndpoint>();
+        internalEndpoints = new ConcurrentHashMap<String, InternalEndpoint>();
     }
 
-    public ManagementStrategy getManagementAgent() {
-        return managementStrategy;
+    public void setBundleContext(BundleContext bundleContext) {
+        this.bundleContext = bundleContext;
     }
 
-    public void setManagementStrategy(ManagementStrategy managementStrategy) {
-        this.managementStrategy = managementStrategy;
+    public void init() {
+        if (bundleContext == null) {
+            throw new IllegalArgumentException("bundleContext must be set");
+        }
+        managementStrategyTracker = new ServiceTracker(bundleContext, ManagementStrategy.class.getName(), null) {
+            @Override
+            public Object addingService(ServiceReference reference) {
+                ManagementStrategy newMs = (ManagementStrategy) super.addingService(reference);
+                if (getService() == null) {
+                    bindManagementStrategy(newMs);
+                }
+                return newMs;
+            }
+
+            @Override
+            public void removedService(ServiceReference reference, Object service) {
+                ManagementStrategy newMs = (ManagementStrategy) getService();
+                bindManagementStrategy(newMs);
+                super.removedService(reference, service);
+            }
+        };
+        managementStrategyTracker.open();
+        endpointTracker = new ServiceTracker(bundleContext, InternalEndpoint.class.getName(), null) {
+            @Override
+            public Object addingService(ServiceReference reference) {
+                InternalEndpoint endpoint = (InternalEndpoint) super.addingService(reference);
+                register(endpoint);
+                return endpoint;
+            }
+
+            @Override
+            public void removedService(ServiceReference reference, Object service) {
+                InternalEndpoint endpoint = (InternalEndpoint) service;
+                unregister(endpoint);
+                super.removedService(reference, service);
+            }
+        };
+        endpointTracker.open();
     }
 
-    public void register(InternalEndpoint endpoint, Map<String, ?> properties) {
-        try {
-            LOG.info("Registering endpoint: " + endpoint + " with properties " + properties);
-            ManagedEndpoint ep = new ManagedEndpoint(endpoint, properties, managementStrategy);
-            endpoints.put(endpoint.getId(), ep);
-            managementStrategy.manageObject(ep);
-        } catch (Exception e) {
-            LOG.warn("Unable to register managed endpoint: " + e, e);
+    public void destroy() {
+        unregisterAll();
+        managementStrategyTracker.close();
+        endpointTracker.close();
+    }
+
+    public void bindManagementStrategy(ManagementStrategy ms) {
+        LOG.debug("Using new management strategy: " + ms);
+        unregisterAll();
+        managementStrategy = ms;
+        registerAll();
+    }
+
+    protected void registerAll() {
+        if (managementStrategy != null) {
+            for (String id : internalEndpoints.keySet()) {
+                registerEndpoint(internalEndpoints.get(id));
+            }
         }
     }
 
-    public void unregister(InternalEndpoint endpoint, Map<String, ?> properties) {
-        if (endpoint ==  null) {
-            return;
+    protected void unregisterAll() {
+        if (managementStrategy != null) {
+            for (String id : internalEndpoints.keySet()) {
+                unregisterEndpoint(internalEndpoints.get(id));
+            }
         }
-        try {
-            LOG.info("Unregistering endpoint: " + endpoint + " with properties " + properties);
-            ManagedEndpoint ep = endpoints.remove(endpoint.getId());
-            managementStrategy.unmanageObject(ep);
-        } catch (Exception e) {
-            LOG.warn("Unable to unregister managed endpoint: " + e, e);
+    }
+
+    protected void registerEndpoint(InternalEndpoint iep) {
+        if (managementStrategy != null) {
+            try {
+                LOG.info("Registering endpoint: " + iep + " with properties " + iep.getMetaData());
+                ManagedEndpoint ep = new ManagedEndpoint(iep, managementStrategy);
+                endpoints.put(iep.getId(), ep);
+                managementStrategy.manageObject(ep);
+            } catch (Exception e) {
+                LOG.warn("Unable to register managed endpoint: " + e, e);
+            }
+        }
+    }
+
+    private void unregisterEndpoint(InternalEndpoint iep) {
+        if (managementStrategy != null) {
+            try {
+                LOG.info("Unregistering endpoint: " + iep + " with properties " + iep.getMetaData());
+                ManagedEndpoint ep = endpoints.remove(iep.getId());
+                managementStrategy.unmanageObject(ep);
+            } catch (Exception e) {
+                LOG.warn("Unable to unregister managed endpoint: " + e, e);
+            }
         }
     }
 
+    public void register(InternalEndpoint endpoint) {
+        internalEndpoints.put(endpoint.getId(), endpoint);
+        registerEndpoint(endpoint);
+    }
+
+    public void unregister(InternalEndpoint endpoint) {
+        internalEndpoints.remove(endpoint.getId());
+        unregisterEndpoint(endpoint);
+    }
+
     public void exchangeSent(Exchange exchange) {
         try {
             if (LOG.isTraceEnabled()) {
@@ -138,9 +222,4 @@ public class ManagementEndpointRegistry 
         }
     }
 
-    public void afterPropertiesSet() throws Exception {
-        if (managementStrategy == null) {
-            throw new IllegalArgumentException("managementStrategy must not be null");
-        }
-    }
 }

Modified: servicemix/smx4/nmr/trunk/nmr/management/src/main/resources/OSGI-INF/blueprint/servicemix-nmr-management.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/management/src/main/resources/OSGI-INF/blueprint/servicemix-nmr-management.xml?rev=966045&r1=966044&r2=966045&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/management/src/main/resources/OSGI-INF/blueprint/servicemix-nmr-management.xml (original)
+++ servicemix/smx4/nmr/trunk/nmr/management/src/main/resources/OSGI-INF/blueprint/servicemix-nmr-management.xml Tue Jul 20 22:44:31 2010
@@ -24,7 +24,9 @@
     <!-- MBeanServer -->
     <reference id="mbeanServer"
                interface="javax.management.MBeanServer"
-               availability="mandatory"/>
+               availability="mandatory">
+        <reference-listener ref="managementStrategy" bind-method="bindMBeanServer" unbind-method="unbindMBeanServer"/>
+    </reference>
  
 
     <bean id="namingStrategy" class="org.apache.servicemix.nmr.management.DefaultNamingStrategy">
@@ -34,36 +36,36 @@
     <!-- ManagementStrategy -->
     <bean id="managementStrategy"
           class="org.apache.servicemix.nmr.management.ManagementAgent"
-          init-method="init"
-          destroy-method="destroy">
+          depends-on="mbeanServer">
         <property name="bundleContext" ref="blueprintBundleContext"/>
         <property name="enabled" value="${enabled}"/>
         <property name="namingStrategy" ref="namingStrategy" />
-        <property name="mbeanServer" ref="mbeanServer" />
     </bean>
 
     <!-- Service registration for the management strategy is done in
          ManagementAgent.init() so that is can be made optional depending
          on the value returned by isEnabled().  This means that we must
          get a separate reference to the management strategy so it can 
-         be injected into the management endpoint registry. --> 
+         be injected into the management endpoint registry.
     <reference id="managementStrategyRef"
                interface="org.fusesource.commons.management.ManagementStrategy" 
-               availability="optional"/>
+               availability="optional">
+        <reference-listener ref="endpointRegistry" bind-method="bindManagementStrategy" unbind-method="unbindManagementStrategy"/>
+    </reference>        --> 
 
-    <!-- Endpoint registry -->   
+    <!-- Endpoint registry -->
     <bean id="endpointRegistry" 
           class="org.apache.servicemix.nmr.management.ManagementEndpointRegistry"
-          init-method="afterPropertiesSet">
-        <property name="managementStrategy" ref="managementStrategyRef"/>
+          init-method="init" destroy-method="destroy">
+        <property name="bundleContext" ref="blueprintBundleContext"/>
     </bean>
        
-    <!-- List of endpoints -->
+    <!-- List of endpoints
     <reference-list id="endpoints"
                     interface="org.apache.servicemix.nmr.api.internal.InternalEndpoint"
                     availability="optional">
         <reference-listener ref="endpointRegistry" bind-method="register" unbind-method="unregister" />
-    </reference-list>
+    </reference-list>      -->
 
     <!-- Exchange listener -->
     <service ref="endpointRegistry">

Modified: servicemix/smx4/nmr/trunk/nmr/management/src/test/java/org/apache/servicemix/nmr/management/ManagementStrategyTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/management/src/test/java/org/apache/servicemix/nmr/management/ManagementStrategyTest.java?rev=966045&r1=966044&r2=966045&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/management/src/test/java/org/apache/servicemix/nmr/management/ManagementStrategyTest.java (original)
+++ servicemix/smx4/nmr/trunk/nmr/management/src/test/java/org/apache/servicemix/nmr/management/ManagementStrategyTest.java Tue Jul 20 22:44:31 2010
@@ -42,6 +42,7 @@ import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
 
 public class ManagementStrategyTest extends Assert { //TestCase {
@@ -298,7 +299,7 @@ public class ManagementStrategyTest exte
         InternalEndpoint internal = control.createMock(InternalEndpoint.class);
         HashMap<String, Object> props = new HashMap<String, Object>();
         ManagedEndpoint endpoint = 
-            new ManagedEndpoint(internal, props, strategy);
+            new ManagedEndpoint(internal, strategy);
         expect(internal.getId()).andReturn("endpoint_foo");
         expect(mbeanServer.registerMBean(isA(ManagedEndpoint.class), eq(name))).andReturn(instance);
         control.replay();
@@ -328,30 +329,33 @@ public class ManagementStrategyTest exte
     
     @Test
     public void testEnableDisable() throws Exception {
-
         ServiceRegistration sr = createMock(ServiceRegistration.class);
         sr.unregister();
         BundleContext ctx = createMock(BundleContext.class);
         expect(ctx.registerService("org.fusesource.commons.management.ManagementStrategy",
                                    strategy, null)).andReturn(sr);
-        replay(ctx, sr);
+        ServiceReference ref = createMock(ServiceReference.class);
+        MBeanServer mbs = createMock(MBeanServer.class);
+        expect(ctx.getService(ref)).andReturn(mbs);
+        expect(ctx.ungetService(ref)).andReturn(false);
+        replay(ctx, sr, ref, mbs);
 
         strategy.setEnabled(true);
         assertTrue(strategy.isEnabled());
         strategy.setBundleContext(ctx);
         assertSame(ctx, strategy.getBundleContext());
-        strategy.init();
-        strategy.destroy();
-        verify(ctx, sr);
+        strategy.bindMBeanServer(ref);
+        strategy.unbindMBeanServer(ref);
+        verify(ctx, sr, ref, mbs);
 
         reset(ctx, sr);
         replay(ctx, sr);
         strategy = setUpStrategy();
         strategy.setEnabled(false);
         assertFalse(strategy.isEnabled());
-        strategy.init();
-        strategy.destroy();
-        verify(ctx, sr);
+        strategy.bindMBeanServer(ref);
+        strategy.unbindMBeanServer(ref);
+        verify(ctx, sr, ref, mbs);
 
     }
 



Mime
View raw message