You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by cc...@apache.org on 2009/08/25 06:16:01 UTC

svn commit: r807471 [1/2] - in /servicemix/smx4/nmr/trunk: ./ jbi/deployer/ jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/ jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/ jbi/deployer/src/main/java/org/apache/se...

Author: ccustine
Date: Tue Aug 25 04:15:57 2009
New Revision: 807471

URL: http://svn.apache.org/viewvc?rev=807471&view=rev
Log:
SMX4NMR-140 Refactor management infrastructure to eliminate duplication and allow for easier pluggability

Added:
    servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/MBeanServerWrapper.java
    servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/NmrStartedEvent.java
    servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/NmrStoppedEvent.java
    servicemix/smx4/nmr/trunk/nmr/management/src/main/java/org/apache/servicemix/nmr/management/ExchangeFailedEvent.java
    servicemix/smx4/nmr/trunk/nmr/management/src/main/java/org/apache/servicemix/nmr/management/Nameable.java
    servicemix/smx4/nmr/trunk/nmr/management/src/test/java/org/apache/servicemix/nmr/management/ManagementStrategyTest.java
Removed:
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/NamingStrategy.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/DefaultNamingStrategy.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ManagementAgent.java
    servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ManagementContext.java
Modified:
    servicemix/smx4/nmr/trunk/jbi/deployer/pom.xml
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/ComponentImpl.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/ServiceAssemblyImpl.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/SharedLibraryImpl.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/events/LifeCycleEvent.java
    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/java/org/apache/servicemix/jbi/deployer/task/JbiTask.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/resources/META-INF/spring/servicemix-jbi-deployer.xml
    servicemix/smx4/nmr/trunk/jbi/itests/pom.xml
    servicemix/smx4/nmr/trunk/jbi/itests/src/test/java/org/apache/servicemix/jbi/itests/IntegrationTest.java
    servicemix/smx4/nmr/trunk/jbi/itests/src/test/java/org/apache/servicemix/jbi/itests/ManagementTest.java
    servicemix/smx4/nmr/trunk/jbi/osgi/pom.xml
    servicemix/smx4/nmr/trunk/jbi/osgi/src/main/java/org/apache/servicemix/jbi/osgi/NMRWrapper.java
    servicemix/smx4/nmr/trunk/jbi/osgi/src/main/resources/META-INF/spring/servicemix-jbi.xml
    servicemix/smx4/nmr/trunk/jbi/runtime/pom.xml
    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/nmr/api/src/main/java/org/apache/servicemix/nmr/api/NMR.java
    servicemix/smx4/nmr/trunk/nmr/core/pom.xml
    servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/ServiceMix.java
    servicemix/smx4/nmr/trunk/nmr/management/pom.xml
    servicemix/smx4/nmr/trunk/nmr/management/src/main/java/org/apache/servicemix/nmr/management/DefaultNamingStrategy.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/java/org/apache/servicemix/nmr/management/NamingStrategy.java
    servicemix/smx4/nmr/trunk/nmr/management/src/main/java/org/apache/servicemix/nmr/management/stats/CountStatistic.java
    servicemix/smx4/nmr/trunk/nmr/management/src/main/java/org/apache/servicemix/nmr/management/stats/Statistic.java
    servicemix/smx4/nmr/trunk/nmr/management/src/main/java/org/apache/servicemix/nmr/management/stats/TimeStatistic.java
    servicemix/smx4/nmr/trunk/nmr/management/src/main/resources/META-INF/spring/servicemix-nmr-management.xml
    servicemix/smx4/nmr/trunk/nmr/management/src/test/java/org/apache/servicemix/nmr/management/stats/CountStatisticTest.java
    servicemix/smx4/nmr/trunk/nmr/management/src/test/java/org/apache/servicemix/nmr/management/stats/TimeStatisticTest.java
    servicemix/smx4/nmr/trunk/nmr/osgi/pom.xml
    servicemix/smx4/nmr/trunk/nmr/osgi/src/main/resources/META-INF/spring/servicemix-nmr.xml
    servicemix/smx4/nmr/trunk/pom.xml

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/pom.xml?rev=807471&r1=807470&r2=807471&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/pom.xml (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/pom.xml Tue Aug 25 04:15:57 2009
@@ -76,6 +76,15 @@
             <artifactId>easymock</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.servicemix.nmr</groupId>
+            <artifactId>org.apache.servicemix.nmr.management</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.fusesource.commonman</groupId>
+            <artifactId>commons-management</artifactId>
+            <version>${commons.management.version}</version>
+        </dependency>
     </dependencies>
 
     <build>
@@ -89,6 +98,7 @@
                         <Import-Package>
                             javax.transaction,
                             org.apache.geronimo.transaction.manager;resolution:=optional,
+                            org.apache.servicemix.jbi.runtime.impl,
                             *
                         </Import-Package>
                         <Export-Package>org.apache.servicemix.jbi.deployer*</Export-Package>

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/ComponentImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/ComponentImpl.java?rev=807471&r1=807470&r2=807471&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/ComponentImpl.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/ComponentImpl.java Tue Aug 25 04:15:57 2009
@@ -38,12 +38,13 @@
 import org.apache.servicemix.jbi.deployer.descriptor.ComponentDesc;
 import org.apache.servicemix.jbi.deployer.descriptor.DescriptorFactory;
 import org.apache.servicemix.jbi.runtime.ComponentWrapper;
+import org.apache.servicemix.nmr.management.Nameable;
 import org.osgi.framework.Bundle;
 import org.osgi.service.prefs.Preferences;
 
 /**
  */
-public class ComponentImpl extends AbstractLifecycleJbiArtifact implements Component, ComponentWrapper {
+public class ComponentImpl extends AbstractLifecycleJbiArtifact implements Component, ComponentWrapper, Nameable {
 
     private Bundle bundle;
     private ComponentDesc componentDesc;
@@ -302,4 +303,25 @@
         }
     }
 
+    public String toString() {
+        return getName();
+    }
+
+    public String getParent() {
+        return null;
+    }
+    
+    // REVISIT Type should be "Component"
+    
+    public String getSubType() {
+        return "LifeCycle";
+    }
+    
+    public String getVersion() {
+        return null;
+    }
+
+    public Class getPrimaryInterface() {
+        return Component.class;
+    }
 }

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/ServiceAssemblyImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/ServiceAssemblyImpl.java?rev=807471&r1=807470&r2=807471&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/ServiceAssemblyImpl.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/ServiceAssemblyImpl.java Tue Aug 25 04:15:57 2009
@@ -29,6 +29,7 @@
 import javax.jbi.JBIException;
 import javax.jbi.management.LifeCycleMBean;
 
+import org.apache.servicemix.jbi.deployer.Component;
 import org.apache.servicemix.jbi.deployer.ServiceAssembly;
 import org.apache.servicemix.jbi.deployer.ServiceUnit;
 import org.apache.servicemix.jbi.deployer.descriptor.Connection;
@@ -37,6 +38,7 @@
 import org.apache.servicemix.jbi.deployer.events.LifeCycleEvent;
 import org.apache.servicemix.nmr.api.Wire;
 import org.apache.servicemix.nmr.core.util.MapToDictionary;
+import org.apache.servicemix.nmr.management.Nameable;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.prefs.Preferences;
@@ -44,7 +46,7 @@
 /**
  * ServiceAssembly object
  */
-public class ServiceAssemblyImpl extends AbstractLifecycleJbiArtifact implements ServiceAssembly {
+public class ServiceAssemblyImpl extends AbstractLifecycleJbiArtifact implements ServiceAssembly, Nameable {
 
     private enum Action {
         Init,
@@ -349,4 +351,28 @@
         thread.start();
         return semaphore;
     }
+    
+    public String toString() {
+        return getName();
+    }
+
+    public String getParent() {
+        return null;
+    }
+
+    public String getType() {
+        return "ServiceAssembly";
+    }
+    
+    public String getSubType() {
+        return null;
+    }
+    
+    public String getVersion() {
+        return null;
+    }
+
+    public Class getPrimaryInterface() {
+        return ServiceAssembly.class;
+    }
 }

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/SharedLibraryImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/SharedLibraryImpl.java?rev=807471&r1=807470&r2=807471&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/SharedLibraryImpl.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/artifacts/SharedLibraryImpl.java Tue Aug 25 04:15:57 2009
@@ -26,12 +26,14 @@
 import org.apache.servicemix.jbi.deployer.SharedLibrary;
 import org.apache.servicemix.jbi.deployer.descriptor.DescriptorFactory;
 import org.apache.servicemix.jbi.deployer.descriptor.SharedLibraryDesc;
+import org.apache.servicemix.jbi.deployer.impl.AdminService;
+import org.apache.servicemix.nmr.management.Nameable;
 import org.osgi.framework.Bundle;
 
 /**
  * SharedLibrary object
  */
-public class SharedLibraryImpl implements SharedLibrary {
+public class SharedLibraryImpl implements SharedLibrary, Nameable {
 
     protected final Log LOGGER = LogFactory.getLog(getClass());
 
@@ -86,4 +88,19 @@
         components.remove(component);
     }
 
+    public String getParent() {
+        return null;
+    }
+    
+    public String getType() {
+        return "SharedLibrary";
+    }
+
+    public String getSubType() {
+        return null;
+    }
+
+    public Class getPrimaryInterface() {
+        return SharedLibrary.class;
+    }
 }

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/events/LifeCycleEvent.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/events/LifeCycleEvent.java?rev=807471&r1=807470&r2=807471&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/events/LifeCycleEvent.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/events/LifeCycleEvent.java Tue Aug 25 04:15:57 2009
@@ -53,4 +53,14 @@
     public boolean isForced() {
         return forced;
     }
+
+    public String toString() {
+        String clz = getSource().getClass().getSimpleName();
+        return (clz.endsWith("Impl") 
+                ? clz.substring(0, clz.length() - "Impl".length())
+                : clz) + " " +
+               getSource() + " " +
+               type + " " +
+               (isForced() ? "(forced)" : "");
+    }
 }

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=807471&r1=807470&r2=807471&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 Aug 25 04:15:57 2009
@@ -24,7 +24,6 @@
 import java.util.Set;
 
 import javax.jbi.management.LifeCycleMBean;
-import javax.management.StandardMBean;
 
 import org.apache.servicemix.jbi.deployer.AdminCommandsService;
 import org.apache.servicemix.jbi.deployer.Component;
@@ -32,11 +31,12 @@
 import org.apache.servicemix.jbi.deployer.ServiceUnit;
 import org.apache.servicemix.jbi.deployer.SharedLibrary;
 import org.apache.servicemix.jbi.deployer.utils.ManagementSupport;
+import org.apache.servicemix.nmr.management.Nameable;
 import org.springframework.beans.factory.DisposableBean;
 import org.springframework.beans.factory.InitializingBean;
 import org.springframework.util.StringUtils;
 
-public class AdminCommandsImpl implements AdminCommandsService, InitializingBean, DisposableBean {
+public class AdminCommandsImpl implements AdminCommandsService, InitializingBean, DisposableBean, Nameable {
 
     private Deployer deployer;
     private InstallationService installationService;
@@ -71,7 +71,7 @@
     public String uninstallComponent(final String name) throws Exception {
         try {
             if (installationService.unloadInstaller(name, true)) {
-            	return ManagementSupport.createSuccessMessage("uninstallComponent", name);
+                return ManagementSupport.createSuccessMessage("uninstallComponent", name);
             }
             throw ManagementSupport.failure("uninstallComponent", name);
         } catch (Exception e) {
@@ -445,12 +445,11 @@
     }
 
     public void afterPropertiesSet() throws Exception {
-        deployer.getManagementAgent().register(new StandardMBean(this, AdminCommandsService.class),
-                                               deployer.getNamingStrategy().getObjectName(this));
+        deployer.getManagementStrategy().manageObject(this);
     }
 
     public void destroy() throws Exception {
-        deployer.getManagementAgent().unregister(deployer.getNamingStrategy().getObjectName(this));
+        deployer.getManagementStrategy().unmanageObject(this);
     }
 
     public void setInstallationService(InstallationService installationService) {
@@ -477,4 +476,27 @@
         this.deployer = deployer;
     }
 
+    public String getParent() {
+        return AdminService.DEFAULT_NAME;
+    }
+
+    public String getName() {
+        return "AdminCommandsService";
+    }
+    
+    public String getType() {
+        return "SystemService";
+    }
+
+    public String getSubType() {
+        return null;
+    }
+
+    public Class getPrimaryInterface() {
+        return AdminCommandsService.class;
+    }
+
+    public String getVersion() {
+        return null;
+    }
 }

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=807471&r1=807470&r2=807471&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 Aug 25 04:15:57 2009
@@ -20,7 +20,6 @@
 import java.util.Set;
 
 import javax.jbi.management.AdminServiceMBean;
-import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 
 import org.apache.servicemix.jbi.deployer.Component;
@@ -38,7 +37,6 @@
     public static final int DEFAULT_CONNECTOR_PORT = 1099;
 
     private Deployer deployer;
-    private DefaultNamingStrategy namingStrategy;
 
     public Deployer getDeployer() {
         return deployer;
@@ -48,21 +46,13 @@
         this.deployer = deployer;
     }
 
-    public void setNamingStrategy(DefaultNamingStrategy namingStrategy) {
-        this.namingStrategy = namingStrategy;
-    }
-
-    public DefaultNamingStrategy getNamingStrategy() {
-        return namingStrategy;
-    }
-
     public ObjectName[] getBindingComponents() {
         Set<ObjectName> names = new HashSet<ObjectName>();
         for (Component component : deployer.getComponents().values()) {
             if (Deployer.TYPE_BINDING_COMPONENT.equals(component.getType())) {
                 try {
-                    names.add(namingStrategy.getObjectName(component));
-                } catch (MalformedObjectNameException e) {
+                    names.add(deployer.getManagementStrategy().getManagedObjectName(component, null, ObjectName.class));
+                } catch (Exception e) {
                 }
             }
         }
@@ -73,8 +63,8 @@
         Component component = deployer.getComponent(name);
         if (component != null) {
             try {
-                return namingStrategy.getObjectName(component);
-            } catch (MalformedObjectNameException e) {
+                return deployer.getManagementStrategy().getManagedObjectName(component, null, ObjectName.class);
+            } catch (Exception e) {
             }
         }
         return null;
@@ -85,8 +75,8 @@
         for (Component component : deployer.getComponents().values()) {
             if (Deployer.TYPE_SERVICE_ENGINE.equals(component.getType())) {
                 try {
-                    names.add(namingStrategy.getObjectName(component));
-                } catch (MalformedObjectNameException e) {
+                    names.add(deployer.getManagementStrategy().getManagedObjectName(component, null, ObjectName.class));
+                } 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=807471&r1=807470&r2=807471&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 Aug 25 04:15:57 2009
@@ -32,7 +32,6 @@
 import javax.management.JMException;
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
-import javax.management.StandardMBean;
 
 import org.apache.servicemix.jbi.deployer.Component;
 import org.apache.servicemix.jbi.deployer.SharedLibrary;
@@ -43,11 +42,12 @@
 import org.apache.servicemix.jbi.deployer.utils.FileUtil;
 import org.apache.servicemix.jbi.deployer.utils.ManagementSupport;
 import org.apache.xbean.classloader.MultiParentClassLoader;
+import org.apache.servicemix.nmr.management.Nameable;
 import org.osgi.framework.Bundle;
 import org.osgi.service.prefs.BackingStoreException;
 import org.springframework.osgi.util.BundleDelegatingClassLoader;
 
-public class ComponentInstaller extends AbstractInstaller implements InstallerMBean {
+public class ComponentInstaller extends AbstractInstaller implements InstallerMBean, Nameable {
 
     private InstallationContextImpl installationContext;
     private ObjectName objectName;
@@ -61,8 +61,10 @@
         super(deployer, descriptor, jbiArtifact, autoStart);
         this.installRoot = new File(System.getProperty("servicemix.base"), "data/jbi/" + getName() + "/install");
         this.installRoot.mkdirs();
-        this.installationContext = new InstallationContextImpl(descriptor.getComponent(), deployer.getEnvironment(),
-                                                               deployer.getNamingStrategy(), deployer.getManagementAgent());
+        this.installationContext = new InstallationContextImpl(descriptor.getComponent(), 
+                                                               deployer.getEnvironment(),
+                                                               deployer.getManagementStrategy(),
+                                                               deployer.getMbeanServer());
         this.installationContext.setInstallRoot(installRoot);
     }
 
@@ -76,11 +78,19 @@
     }
 
     public void register() throws JMException {
-        deployer.getManagementAgent().register(new StandardMBean(this, InstallerMBean.class), getObjectName());
+        try {
+            deployer.getManagementStrategy().manageObject(this);
+        } catch (Exception ex) {
+            throw new JMException(ex.getMessage());
+        }
     }
 
     public void unregister() throws JMException {
-        deployer.getManagementAgent().unregister(getObjectName());
+        try {
+            deployer.getManagementStrategy().unmanageObject(this);
+        } catch (Exception ex) {
+            throw new JMException(ex.getMessage());
+        }
     }
 
     public String getName() {
@@ -246,7 +256,11 @@
      */
     public ObjectName getObjectName() {
         if (objectName == null) {
-            objectName = deployer.getNamingStrategy().createCustomComponentMBeanName("Installer", getName());
+            try {
+                objectName = deployer.getManagementStrategy().getManagedObjectName(this, null, ObjectName.class);
+            } catch (Exception e) {
+                // ignore
+            }
         }
         return objectName;
     }
@@ -306,9 +320,9 @@
                 // in case the bootstrap has not done it
                 try {
                     if (extensionMBeanName != null) {
-                        deployer.getManagementAgent().unregister(extensionMBeanName);
+                        deployer.getManagementStrategy().unmanageObject(extensionMBeanName);
                     }
-                } catch (JMException e) {
+                } catch (Exception e) {
                     // ignore
                 }
                 if (bootstrap == null) {
@@ -411,7 +425,7 @@
             }
         }
         Component component = deployer.registerComponent(getBundle(), componentDesc, innerComponent, aLibs);
-        return deployer.getNamingStrategy().getObjectName(component);
+        return deployer.getManagementStrategy().getManagedObjectName(component, null, ObjectName.class);
     }
 
     public void configure(Properties props) throws Exception {
@@ -420,7 +434,7 @@
             if (on == null) {
                 LOGGER.warn("Could not find installation configuration MBean. Installation properties will be ignored.");
             } else {
-                MBeanServer mbs = deployer.getManagementAgent().getMbeanServer();
+                MBeanServer mbs = deployer.getMbeanServer();
                 for (Object o : props.keySet()) {
                     String key = (String) o;
                     String val = props.getProperty(key);
@@ -433,4 +447,24 @@
             }
         }
     }
+
+    public String getParent() {
+        return null;
+    }
+    
+    public String getType() {
+        return "service-engine";
+    }
+    
+    public String getSubType() {
+        return "Installer";
+    }
+    
+    public String getVersion() {
+        return null;
+    }
+    
+    public Class getPrimaryInterface() {
+        return InstallerMBean.class;
+    }
 }

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=807471&r1=807470&r2=807471&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 Aug 25 04:15:57 2009
@@ -28,13 +28,12 @@
 import java.util.concurrent.ConcurrentHashMap;
 
 import javax.jbi.JBIException;
-import javax.management.StandardMBean;
+import javax.management.MBeanServer;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.servicemix.jbi.deployer.Component;
 import org.apache.servicemix.jbi.deployer.DeployedAssembly;
-import org.apache.servicemix.jbi.deployer.NamingStrategy;
 import org.apache.servicemix.jbi.deployer.ServiceAssembly;
 import org.apache.servicemix.jbi.deployer.SharedLibrary;
 import org.apache.servicemix.jbi.deployer.ServiceUnit;
@@ -58,6 +57,7 @@
 import org.apache.servicemix.jbi.runtime.Environment;
 import org.apache.servicemix.nmr.api.event.ListenerRegistry;
 import org.apache.servicemix.nmr.core.ListenerRegistryImpl;
+import org.fusesource.commons.management.ManagementStrategy;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
@@ -118,11 +118,12 @@
     private int shutdownTimeout;
 
     // Helper beans
-    private NamingStrategy namingStrategy;
-    private ManagementAgent managementAgent;
+    private ManagementStrategy managementStrategy;
     private Environment environment;
 
     private ListenerRegistry listenerRegistry;
+    
+    private MBeanServer mbeanServer;
 
     public Deployer() throws JBIException {
         // TODO: control that using properties
@@ -165,20 +166,20 @@
         return endpointListener;
     }
 
-    public NamingStrategy getNamingStrategy() {
-        return namingStrategy;
+    public ManagementStrategy getManagementStrategy() {
+        return managementStrategy;
     }
 
-    public void setNamingStrategy(NamingStrategy namingStrategy) {
-        this.namingStrategy = namingStrategy;
+    public void setManagementStrategy(ManagementStrategy managementStrategy) {
+        this.managementStrategy = managementStrategy;
     }
-
-    public ManagementAgent getManagementAgent() {
-        return managementAgent;
+    
+    public MBeanServer getMbeanServer() {
+        return mbeanServer;
     }
 
-    public void setManagementAgent(ManagementAgent managementAgent) {
-        this.managementAgent = managementAgent;
+    public void setMbeanServer(MBeanServer mbeanServer) {
+        this.mbeanServer = mbeanServer;
     }
 
     public void setEnvironment(Environment environment) {
@@ -404,7 +405,7 @@
         return new ServiceUnitImpl(sud, suRootDir, component);
     }
 
-    public SharedLibrary registerSharedLibrary(Bundle bundle, SharedLibraryDesc sharedLibraryDesc, ClassLoader classLoader) throws Exception {
+    public SharedLibraryImpl registerSharedLibrary(Bundle bundle, SharedLibraryDesc sharedLibraryDesc, ClassLoader classLoader) throws Exception {
         // Create shared library
         SharedLibraryImpl sl = new SharedLibraryImpl(bundle, sharedLibraryDesc, classLoader);
         sharedLibraries.put(sl.getName(), sl);
@@ -413,13 +414,13 @@
         props.put(NAME, sharedLibraryDesc.getIdentification().getName());
         LOGGER.debug("Registering JBI Shared Library");
         registerService(bundle, SharedLibrary.class.getName(), sl, props);
-        getManagementAgent().register(new StandardMBean(sl, SharedLibrary.class), getNamingStrategy().getObjectName(sl));
+        getManagementStrategy().manageObject(sl);
         // Check pending bundles
         checkPendingInstallers();
         return sl;
     }
 
-    public Component registerComponent(Bundle bundle, ComponentDesc componentDesc, javax.jbi.component.Component innerComponent, SharedLibrary[] sharedLibraries) throws Exception {
+    public ComponentImpl registerComponent(Bundle bundle, ComponentDesc componentDesc, javax.jbi.component.Component innerComponent, SharedLibrary[] sharedLibraries) throws Exception {
         String name = componentDesc.getIdentification().getName();
         Preferences prefs = preferencesService.getUserPreferences(name);
         ComponentImpl component = new ComponentImpl(bundle, componentDesc, innerComponent, prefs, autoStart, sharedLibraries);
@@ -440,12 +441,11 @@
         if (!wrappedComponents.containsKey(name)) {
             registerService(bundle, javax.jbi.component.Component.class.getName(), innerComponent, props);
         }
-        getManagementAgent().register(new StandardMBean(component, Component.class),
-                                      getNamingStrategy().getObjectName(component));
+        getManagementStrategy().manageObject(component);
         return component;
     }
 
-    public ServiceAssembly registerServiceAssembly(Bundle bundle, ServiceAssemblyDesc serviceAssemblyDesc, List<ServiceUnitImpl> sus) throws Exception {
+    public ServiceAssemblyImpl registerServiceAssembly(Bundle bundle, ServiceAssemblyDesc serviceAssemblyDesc, List<ServiceUnitImpl> sus) throws Exception {
         // Now create the SA and initialize it
         Preferences prefs = preferencesService.getUserPreferences(serviceAssemblyDesc.getIdentification().getName());
         ServiceAssemblyImpl sa = new ServiceAssemblyImpl(bundle, serviceAssemblyDesc, sus, prefs, endpointListener, autoStart);
@@ -459,7 +459,7 @@
         // register the service assembly in the OSGi registry
         LOGGER.debug("Registering JBI service assembly");
         registerService(bundle, ServiceAssembly.class.getName(), sa, props);
-        getManagementAgent().register(new StandardMBean(sa, ServiceAssembly.class), getNamingStrategy().getObjectName(sa));
+        getManagementStrategy().manageObject(sa);
         return sa;
     }
 
@@ -604,6 +604,14 @@
                     break;
             }
         }
+
+        // propagate lifecycle event to management strategy
+        // 
+        try {
+            getManagementStrategy().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=807471&r1=807470&r2=807471&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 Aug 25 04:15:57 2009
@@ -40,11 +40,13 @@
 import org.w3c.dom.Document;
 import org.w3c.dom.DocumentFragment;
 
-import org.apache.servicemix.jbi.deployer.NamingStrategy;
+import org.apache.servicemix.jbi.deployer.ServiceAssembly;
 import org.apache.servicemix.jbi.deployer.descriptor.ComponentDesc;
 import org.apache.servicemix.jbi.deployer.descriptor.InstallationDescriptorExtension;
 import org.apache.servicemix.jbi.deployer.descriptor.SharedLibraryList;
 import org.apache.servicemix.jbi.runtime.Environment;
+import org.fusesource.commons.management.ManagementStrategy;
+import org.apache.servicemix.nmr.management.Nameable;
 
 
 /**
@@ -54,8 +56,8 @@
 public class InstallationContextImpl implements InstallationContext, ComponentContext, MBeanNames {
 
     private ComponentDesc descriptor;
-    private NamingStrategy namingStrategy;
-    private ManagementAgent managementAgent;
+    private ManagementStrategy managementStrategy;
+    private MBeanServer mbeanServer;
     private Environment environment;
     private File installRoot;
     private List<String> classPathElements = Collections.emptyList();
@@ -63,12 +65,12 @@
 
     public InstallationContextImpl(ComponentDesc descriptor,
                                    Environment environment,
-                                   NamingStrategy namingStrategy,
-                                   ManagementAgent managementAgent) {
+                                   ManagementStrategy managementStrategy,
+                                   MBeanServer mbeanServer) {
         this.descriptor = descriptor;
         this.environment = environment;
-        this.namingStrategy = namingStrategy;
-        this.managementAgent = managementAgent;
+        this.managementStrategy = managementStrategy;
+        this.mbeanServer = mbeanServer;
         if (descriptor.getComponentClassPath() != null
                 && descriptor.getComponentClassPath().getPathElements() != null
                 && descriptor.getComponentClassPath().getPathElements().length > 0) {
@@ -291,17 +293,47 @@
     }
 
     public ObjectName createCustomComponentMBeanName(String customName) {
-        if (namingStrategy != null) {
-            return namingStrategy.createCustomComponentMBeanName(customName, descriptor.getIdentification().getName());
+        ObjectName name = null;
+        if (managementStrategy != null) {
+            Nameable nameable = new Nameable() {
+                public String getName() {
+                    return descriptor.getIdentification().getName();
+                }                    
+                public String getParent() {
+                    return null;
+                }
+                public String getType() {
+                    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
+            }
         }
-        return null;
+        return name;
     }
 
     public String getJmxDomainName() {
-        if (namingStrategy != null) {
-            return namingStrategy.getJmxDomainName();
+        String name = null;
+        if (managementStrategy != null) {
+            try {
+                name = managementStrategy.getManagedObjectName(null, null, String.class);
+            } catch (Exception e) {
+                // ignore
+            }
         }
-        return null;
+        return name;
     }
 
     /**
@@ -351,7 +383,7 @@
     }
 
     public MBeanServer getMBeanServer() {
-        return managementAgent.getMbeanServer();
+        return mbeanServer;
     }
 
     public InitialContext getNamingContext() {
@@ -361,5 +393,4 @@
     public Object getTransactionManager() {
         return environment.getTransactionManager();
     }
-
 }

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=807471&r1=807470&r2=807471&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 Aug 25 04:15:57 2009
@@ -95,7 +95,7 @@
             }
             postInstall();
             ServiceAssembly sa = deployer.registerServiceAssembly(bundle, descriptor.getServiceAssembly(), sus);
-            return deployer.getNamingStrategy().getObjectName(sa);
+            return deployer.getManagementStrategy().getManagedObjectName(sa, null, ObjectName.class);
         } 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=807471&r1=807470&r2=807471&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 Aug 25 04:15:57 2009
@@ -51,7 +51,7 @@
     public ObjectName install() throws JBIException {
         try {
             SharedLibrary sl = deployer.registerSharedLibrary(bundle, descriptor.getSharedLibrary(), createClassLoader());
-            return deployer.getNamingStrategy().getObjectName(sl);
+            return deployer.getManagementStrategy().getManagedObjectName(sl, null, ObjectName.class);
         } 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/task/JbiTask.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/task/JbiTask.java?rev=807471&r1=807470&r2=807471&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/task/JbiTask.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/task/JbiTask.java Tue Aug 25 04:15:57 2009
@@ -21,6 +21,8 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import java.lang.reflect.Method;
+
 import javax.management.MBeanServerInvocationHandler;
 import javax.management.ObjectName;
 import javax.management.remote.JMXConnector;
@@ -29,7 +31,7 @@
 
 import org.apache.servicemix.jbi.deployer.AdminCommandsService;
 import org.apache.servicemix.jbi.deployer.impl.AdminService;
-import org.apache.servicemix.jbi.deployer.impl.DefaultNamingStrategy;
+//import org.apache.servicemix.nmr.management.DefaultNamingStrategy;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.Task;
@@ -53,6 +55,8 @@
 
     private String jndiPath = AdminService.DEFAULT_CONNECTOR_PATH;
 
+    private String namingStrategy = "org.apache.servicemix.nmr.management.DefaultNamingStrategy";
+
     private String username;
 
     private String password;
@@ -113,11 +117,23 @@
      * Get the AdminCommandsService
      *
      * @return the main administration service MBean
-     * @throws IOException
+     * @throws Exception
      */
-    public AdminCommandsService getAdminCommandsService() throws IOException {
-        ObjectName objectName = DefaultNamingStrategy.getSystemObjectName(jmxDomainName, containerName,
-                AdminCommandsService.class);
+    public AdminCommandsService getAdminCommandsService() throws Exception {
+
+        // invoke the static getSystemObjectName() method via reflection
+        // so as to allow an alternative class be configured via the 
+        // namingStrategy attribute on the ant task
+        //
+        Class<?> clazz = Class.forName(namingStrategy);
+        Method method = clazz.getMethod("getSystemObjectName", 
+                                        new Class[]{String.class, 
+                                                    String.class, 
+                                                    Class.class});
+        ObjectName objectName = (ObjectName)
+            method.invoke(null, new Object[]{jmxDomainName, 
+                                             containerName, 
+                                             AdminCommandsService.class});
         return (AdminCommandsService) MBeanServerInvocationHandler.newProxyInstance(
                 jmxConnector.getMBeanServerConnection(), objectName,
                 AdminCommandsService.class, true);
@@ -250,6 +266,20 @@
     }
 
     /**
+     * @return Returns the namingStrategy.
+     */
+    public String getNamingStrategy() {
+        return namingStrategy;
+    }
+
+    /**
+     * @param strategy The namingStrategy to set.
+     */
+    public void setNamingStrategy(String namingStrategy) {
+        this.namingStrategy = namingStrategy;
+    }
+
+    /**
      * execute the task
      *
      * @throws BuildException
@@ -283,4 +313,4 @@
 
     protected abstract void doExecute(AdminCommandsService acs) throws Exception;
 
-}
\ No newline at end of file
+}

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/resources/META-INF/spring/servicemix-jbi-deployer.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/resources/META-INF/spring/servicemix-jbi-deployer.xml?rev=807471&r1=807470&r2=807471&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/resources/META-INF/spring/servicemix-jbi-deployer.xml (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/resources/META-INF/spring/servicemix-jbi-deployer.xml Tue Aug 25 04:15:57 2009
@@ -40,8 +40,8 @@
         <property name="autoStart" value="true" />
         <property name="endpointListener" ref="endpointListener" />
         <property name="environment" ref="environment" />
-        <property name="namingStrategy" ref="namingStrategy" />
-        <property name="managementAgent" ref="managementAgent" />
+        <property name="managementStrategy" ref="managementStrategy" />
+        <property name="mbeanServer" ref="mbeanServer" />
         <property name="preferencesService" ref="preferencesService" />
         <property name="shutdownTimeout" value="${shutdownTimeout}" />
     </bean>
@@ -71,17 +71,9 @@
         </osgi:interfaces>
     </osgi:service>
 
-    <!-- Utilities -->
-    <bean id="namingStrategy" class="org.apache.servicemix.jbi.deployer.impl.DefaultNamingStrategy">
-        <property name="jmxDomainName" value="org.apache.servicemix" />
-    </bean>
-    <bean id="managementAgent" class="org.apache.servicemix.jbi.deployer.impl.ManagementAgent">
-        <property name="mbeanServer" ref="mbeanServer" />
-    </bean>
-
     <!-- Services -->
     <bean id="adminService" class="org.apache.servicemix.jbi.deployer.impl.AdminService">
-        <property name="namingStrategy" ref="namingStrategy" />
+        <property name="deployer" ref="deployer" />
     </bean>
     <bean id="adminCommandsService" class="org.apache.servicemix.jbi.deployer.impl.AdminCommandsImpl">
         <property name="deployer" ref="deployer" />
@@ -96,9 +88,14 @@
     </bean>
 
 
-    <!-- Expose management service in OSGi -->
+    <!-- Expose AdminCommandsService in OSGi -->
     <osgi:service ref="adminCommandsService" interface="org.apache.servicemix.jbi.deployer.AdminCommandsService" />
 
+    <!-- Retrieve ManagementStrategy from OSGi service registry -->
+    <osgi:reference id="managementStrategy"
+                    interface="org.fusesource.commons.management.ManagementStrategy"
+                    cardinality="1..1" />
+
     <!-- Environment -->
     <bean id="environment" class="org.apache.servicemix.jbi.runtime.impl.EnvironmentImpl">
         <property name="transactionManagers" ref="transactionManagers" />

Modified: servicemix/smx4/nmr/trunk/jbi/itests/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/itests/pom.xml?rev=807471&r1=807470&r2=807471&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/itests/pom.xml (original)
+++ servicemix/smx4/nmr/trunk/jbi/itests/pom.xml Tue Aug 25 04:15:57 2009
@@ -76,6 +76,11 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>org.apache.servicemix.nmr</groupId>
+            <artifactId>org.apache.servicemix.nmr.management</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.apache.servicemix.document</groupId>
             <artifactId>org.apache.servicemix.document</artifactId>
             <scope>test</scope>
@@ -110,7 +115,7 @@
             <artifactId>org.apache.felix.prefs</artifactId>
             <scope>test</scope>
         </dependency>
-	    <dependency>
+        <dependency>
             <groupId>org.apache.xbean</groupId>
             <artifactId>xbean-classloader</artifactId>
             <scope>test</scope>
@@ -161,6 +166,20 @@
             <artifactId>org.apache.servicemix.specs.stax-api-1.0</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.fusesource.commonman</groupId>
+            <artifactId>commons-management</artifactId>
+            <version>${commons.management.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.xbean</groupId>
+            <artifactId>xbean-naming</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.servicemix.naming</groupId>
+            <artifactId>org.apache.servicemix.naming</artifactId>
+        </dependency>
     </dependencies>
 
     <build>

Modified: servicemix/smx4/nmr/trunk/jbi/itests/src/test/java/org/apache/servicemix/jbi/itests/IntegrationTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/itests/src/test/java/org/apache/servicemix/jbi/itests/IntegrationTest.java?rev=807471&r1=807470&r2=807471&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/itests/src/test/java/org/apache/servicemix/jbi/itests/IntegrationTest.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/itests/src/test/java/org/apache/servicemix/jbi/itests/IntegrationTest.java Tue Aug 25 04:15:57 2009
@@ -64,6 +64,9 @@
 	 */
 	protected String[] getTestBundlesNames() {
         return new String[] {
+            getBundle("org.fusesource.commonman", "commons-management"),
+            getBundle("org.apache.xbean", "xbean-naming"),
+            getBundle("org.apache.servicemix.naming", "org.apache.servicemix.naming"),
             getBundle("org.apache.servicemix.specs", "org.apache.servicemix.specs.stax-api-1.0"),
             getBundle("org.apache.servicemix.specs", "org.apache.servicemix.specs.jbi-api-1.0"),
             getBundle("org.apache.servicemix.specs", "org.apache.servicemix.specs.activation-api-1.1"),
@@ -78,6 +81,7 @@
             getBundle("org.apache.servicemix.nmr", "org.apache.servicemix.nmr.core"),
             getBundle("org.apache.servicemix.nmr", "org.apache.servicemix.nmr.spring"),
             getBundle("org.apache.servicemix.nmr", "org.apache.servicemix.nmr.osgi"),
+            getBundle("org.apache.servicemix.nmr", "org.apache.servicemix.nmr.management"),
             getBundle("org.apache.servicemix.document", "org.apache.servicemix.document"),
             getBundle("org.apache.servicemix.jbi", "org.apache.servicemix.jbi.runtime"),
             getBundle("org.apache.servicemix.jbi", "org.apache.servicemix.jbi.deployer"),

Modified: servicemix/smx4/nmr/trunk/jbi/itests/src/test/java/org/apache/servicemix/jbi/itests/ManagementTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/itests/src/test/java/org/apache/servicemix/jbi/itests/ManagementTest.java?rev=807471&r1=807470&r2=807471&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/itests/src/test/java/org/apache/servicemix/jbi/itests/ManagementTest.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/itests/src/test/java/org/apache/servicemix/jbi/itests/ManagementTest.java Tue Aug 25 04:15:57 2009
@@ -49,6 +49,9 @@
 	 */
 	protected String[] getTestBundlesNames() {
         return new String[] {
+            getBundle("org.fusesource.commonman", "commons-management"),
+            getBundle("org.apache.xbean", "xbean-naming"),
+            getBundle("org.apache.servicemix.naming", "org.apache.servicemix.naming"),
             getBundle("org.apache.servicemix.specs", "org.apache.servicemix.specs.stax-api-1.0"),
             getBundle("org.apache.servicemix.specs", "org.apache.servicemix.specs.jbi-api-1.0"),
             getBundle("org.apache.servicemix.specs", "org.apache.servicemix.specs.activation-api-1.1"),
@@ -63,6 +66,7 @@
             getBundle("org.apache.servicemix.nmr", "org.apache.servicemix.nmr.core"),
             getBundle("org.apache.servicemix.nmr", "org.apache.servicemix.nmr.spring"),
             getBundle("org.apache.servicemix.nmr", "org.apache.servicemix.nmr.osgi"),
+            getBundle("org.apache.servicemix.nmr", "org.apache.servicemix.nmr.management"),
             getBundle("org.apache.servicemix.document", "org.apache.servicemix.document"),
             getBundle("org.apache.servicemix.jbi", "org.apache.servicemix.jbi.runtime"),
             getBundle("org.apache.servicemix.jbi", "org.apache.servicemix.jbi.deployer"),

Modified: servicemix/smx4/nmr/trunk/jbi/osgi/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/osgi/pom.xml?rev=807471&r1=807470&r2=807471&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/osgi/pom.xml (original)
+++ servicemix/smx4/nmr/trunk/jbi/osgi/pom.xml Tue Aug 25 04:15:57 2009
@@ -52,6 +52,11 @@
             <groupId>org.apache.felix</groupId>
             <artifactId>org.osgi.core</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.fusesource.commonman</groupId>
+            <artifactId>commons-management</artifactId>
+            <version>${commons.management.version}</version>
+        </dependency>
     </dependencies>
 
     <build>
@@ -76,6 +81,7 @@
                             org.apache.servicemix.jbi.osgi,
                             org.osgi.framework;version="[1.3,2.0)",
                             org.osgi.service.url,
+                            org.fusesource.commons.management,
                             *
                         </Import-Package>
                         <Spring-Context>*;publish-context:=false;create-asynchronously:=true</Spring-Context>
@@ -85,4 +91,4 @@
         </plugins>
     </build>
 
-</project>
\ No newline at end of file
+</project>

Modified: servicemix/smx4/nmr/trunk/jbi/osgi/src/main/java/org/apache/servicemix/jbi/osgi/NMRWrapper.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/osgi/src/main/java/org/apache/servicemix/jbi/osgi/NMRWrapper.java?rev=807471&r1=807470&r2=807471&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/osgi/src/main/java/org/apache/servicemix/jbi/osgi/NMRWrapper.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/osgi/src/main/java/org/apache/servicemix/jbi/osgi/NMRWrapper.java Tue Aug 25 04:15:57 2009
@@ -76,5 +76,7 @@
         return nmr.createChannel();
     }
 
-
+    public String getId() {
+        return nmr.getId();
+    }
 }

Modified: servicemix/smx4/nmr/trunk/jbi/osgi/src/main/resources/META-INF/spring/servicemix-jbi.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/osgi/src/main/resources/META-INF/spring/servicemix-jbi.xml?rev=807471&r1=807470&r2=807471&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/osgi/src/main/resources/META-INF/spring/servicemix-jbi.xml (original)
+++ servicemix/smx4/nmr/trunk/jbi/osgi/src/main/resources/META-INF/spring/servicemix-jbi.xml Tue Aug 25 04:15:57 2009
@@ -33,13 +33,7 @@
     <bean id="componentRegistry" class="org.apache.servicemix.jbi.runtime.impl.ComponentRegistryImpl">
         <property name="nmr" ref="nmrWrapper" />
         <property name="documentRepository" ref="documentRepository" />
-        <property name="managementContext" ref="managementContext" />
-        <property name="environment" ref="environment" />
-    </bean>
-
-    <!-- Management context -->
-    <bean id="managementContext" class="org.apache.servicemix.jbi.runtime.impl.ManagementContext">
-        <property name="jmxDomainName" value="org.apache.servicemix" />
+        <property name="managementStrategy" ref="managementStrategy" />
         <property name="environment" ref="environment" />
     </bean>
 
@@ -60,6 +54,11 @@
         <property name="registry" ref="componentRegistry" />
     </bean>
 
+    <!-- Retrieve ManagementStrategy from OSGi service registry -->
+    <osgi:reference id="managementStrategy"
+                    interface="org.fusesource.commons.management.ManagementStrategy"
+                    cardinality="1..1" />
+
     <!-- Reference to the ServiceMix NMR -->
     <osgi:reference id="nmr"
                     interface="org.apache.servicemix.nmr.api.NMR" />

Modified: servicemix/smx4/nmr/trunk/jbi/runtime/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/pom.xml?rev=807471&r1=807470&r2=807471&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/runtime/pom.xml (original)
+++ servicemix/smx4/nmr/trunk/jbi/runtime/pom.xml Tue Aug 25 04:15:57 2009
@@ -86,6 +86,15 @@
             <groupId>org.apache.servicemix.bundles</groupId>
             <artifactId>org.apache.servicemix.bundles.wsdl4j</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.servicemix.nmr</groupId>
+            <artifactId>org.apache.servicemix.nmr.management</artifactId>
+        </dependency>
+        <dependency>
+           <groupId>org.fusesource.commonman</groupId>
+           <artifactId>commons-management</artifactId>
+           <version>${commons.management.version}</version>
+       </dependency>
     </dependencies>
 
     <build>

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=807471&r1=807470&r2=807471&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 Aug 25 04:15:57 2009
@@ -52,6 +52,7 @@
 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;
 
 public abstract class AbstractComponentContext implements ComponentContext, MBeanNames {
 
@@ -70,6 +71,13 @@
     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();
@@ -249,17 +257,49 @@
     }
 
     public ObjectName createCustomComponentMBeanName(String customName) {
-        if (componentRegistry.getManagementContext() != null) {
-            return componentRegistry.getManagementContext().createCustomComponentMBeanName(customName, getComponentName());
+        ObjectName name = null;
+        if (componentRegistry.getManagementStrategy() != null) {
+            try {
+                Nameable nameable = new Nameable() {
+                    public String getName() {
+                        return getComponentName();
+                    }                    
+                    public String getParent() {
+                        return null;
+                    }
+                    public String getType() {
+                        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
+            }
         }
-        return null;
+        return name;
     }
 
     public String getJmxDomainName() {
-        if (this.componentRegistry.getManagementContext() != null) {
-            return componentRegistry.getManagementContext().getJmxDomainName();
+        String name = null;
+        if (this.componentRegistry.getManagementStrategy() != null) {
+            try {
+                name = componentRegistry.getManagementStrategy().getManagedObjectName(null, null, String.class);
+            } catch (Exception e) {
+                // ignore
+            }
         }
-        return null;
+        return name;
     }
 
     public ServiceEndpoint resolveEndpointReference(DocumentFragment epr) {

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=807471&r1=807470&r2=807471&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 Aug 25 04:15:57 2009
@@ -30,6 +30,7 @@
 import org.apache.servicemix.jbi.runtime.ComponentWrapper;
 import org.apache.servicemix.nmr.api.NMR;
 import org.apache.servicemix.nmr.core.ServiceRegistryImpl;
+import org.fusesource.commons.management.ManagementStrategy;
 
 /**
  * Registry of JBI components objects
@@ -42,7 +43,7 @@
     private DocumentRepository documentRepository;
     private Map<String, ComponentContextImpl> contexts;
     private Environment environment;
-    private ManagementContext managementContext;
+    private ManagementStrategy managementStrategy;
 
     public ComponentRegistryImpl() {
         contexts = new ConcurrentHashMap<String, ComponentContextImpl>();
@@ -64,14 +65,14 @@
         this.environment = environment;
     }
 
-    public ManagementContext getManagementContext() {
-        return managementContext;
+    public ManagementStrategy getManagementStrategy() {
+        return managementStrategy;
     }
 
-    public void setManagementContext(ManagementContext managementContext) {
-        this.managementContext = managementContext;
+    public void setManagementStrategy(ManagementStrategy managementStrategy) {
+        this.managementStrategy = managementStrategy;
     }
-
+    
     public DocumentRepository getDocumentRepository() {
         return documentRepository;
     }

Added: 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=807471&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/MBeanServerWrapper.java (added)
+++ servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/MBeanServerWrapper.java Tue Aug 25 04:15:57 2009
@@ -0,0 +1,284 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.servicemix.jbi.runtime.impl;
+
+import java.io.ObjectInputStream;
+import java.util.Set;
+
+import javax.management.Attribute;
+import javax.management.AttributeList;
+import javax.management.AttributeNotFoundException;
+import javax.management.InstanceAlreadyExistsException;
+import javax.management.InstanceNotFoundException;
+import javax.management.IntrospectionException;
+import javax.management.InvalidAttributeValueException;
+import javax.management.ListenerNotFoundException;
+import javax.management.MalformedObjectNameException;
+import javax.management.MBeanException;
+import javax.management.MBeanInfo;
+import javax.management.MBeanRegistrationException;
+import javax.management.MBeanServer;
+import javax.management.NotCompliantMBeanException;
+import javax.management.NotificationFilter;
+import javax.management.NotificationListener;
+import javax.management.ObjectInstance;
+import javax.management.ObjectName;
+import javax.management.OperationsException;
+import javax.management.QueryExp;
+import javax.management.ReflectionException;
+import javax.management.loading.ClassLoaderRepository;
+
+import org.fusesource.commons.management.ManagementStrategy;
+
+public class MBeanServerWrapper implements MBeanServer {
+
+    private MBeanServer delegate;
+    private ManagementStrategy strategy;
+    
+    MBeanServerWrapper(MBeanServer delegate, ManagementStrategy strategy) {
+        this.delegate = delegate;
+        this.strategy = strategy;
+    }
+    
+    public void addNotificationListener(ObjectName name,
+            NotificationListener listener, NotificationFilter filter,
+            Object handback) throws InstanceNotFoundException {
+        delegate.addNotificationListener(name, listener, filter, handback);
+    }
+
+    public void addNotificationListener(ObjectName name, ObjectName listener,
+            NotificationFilter filter, Object handback)
+            throws InstanceNotFoundException {
+        delegate.addNotificationListener(name, listener, filter, handback);
+    }
+
+    public ObjectInstance createMBean(String className, ObjectName name)
+            throws ReflectionException, InstanceAlreadyExistsException,
+            MBeanRegistrationException, MBeanException,
+            NotCompliantMBeanException {
+        return delegate.createMBean(className, name);
+    }
+
+    public ObjectInstance createMBean(String className, ObjectName name,
+            ObjectName loaderName) throws ReflectionException,
+            InstanceAlreadyExistsException, MBeanRegistrationException,
+            MBeanException, NotCompliantMBeanException,
+            InstanceNotFoundException {
+        return delegate.createMBean(className, name, loaderName);
+    }
+
+    public ObjectInstance createMBean(String className, ObjectName name,
+            Object[] params, String[] signature) throws ReflectionException,
+            InstanceAlreadyExistsException, MBeanRegistrationException,
+            MBeanException, NotCompliantMBeanException {
+        return delegate.createMBean(className, name, params, signature);
+    }
+
+    public ObjectInstance createMBean(String className, ObjectName name,
+            ObjectName loaderName, Object[] params, String[] signature)
+            throws ReflectionException, InstanceAlreadyExistsException,
+            MBeanRegistrationException, MBeanException,
+            NotCompliantMBeanException, InstanceNotFoundException {
+        return delegate.createMBean(className, name, loaderName, params, signature);
+    }
+
+    public ObjectInputStream deserialize(ObjectName name, byte[] data)
+            throws InstanceNotFoundException, OperationsException {
+        return delegate.deserialize(name, data);
+    }
+
+    public ObjectInputStream deserialize(String className, byte[] data)
+            throws OperationsException, ReflectionException {
+        return delegate.deserialize(className, data);
+    }
+
+    public ObjectInputStream deserialize(String className,
+            ObjectName loaderName, byte[] data)
+            throws InstanceNotFoundException, OperationsException,
+            ReflectionException {
+        return delegate.deserialize(className, loaderName, data);
+    }
+
+    public Object getAttribute(ObjectName name, String attribute)
+            throws MBeanException, AttributeNotFoundException,
+            InstanceNotFoundException, ReflectionException {
+        return delegate.getAttribute(name, attribute);
+    }
+
+    public AttributeList getAttributes(ObjectName name, String[] attributes)
+            throws InstanceNotFoundException, ReflectionException {
+        return delegate.getAttributes(name, attributes);
+    }
+
+    public ClassLoader getClassLoader(ObjectName loaderName)
+            throws InstanceNotFoundException {
+        return delegate.getClassLoader(loaderName);
+    }
+
+    public ClassLoader getClassLoaderFor(ObjectName mbeanName)
+            throws InstanceNotFoundException {
+        return delegate.getClassLoaderFor(mbeanName);
+    }
+
+    public ClassLoaderRepository getClassLoaderRepository() {
+        return delegate.getClassLoaderRepository();
+    }
+
+    public String getDefaultDomain() {
+        return delegate.getDefaultDomain();
+    }
+
+    public String[] getDomains() {
+        return delegate.getDomains();
+    }
+
+    public Integer getMBeanCount() {
+        return delegate.getMBeanCount();
+    }
+
+    public MBeanInfo getMBeanInfo(ObjectName name)
+            throws InstanceNotFoundException, IntrospectionException,
+            ReflectionException {
+        return delegate.getMBeanInfo(name);
+    }
+
+    public ObjectInstance getObjectInstance(ObjectName name)
+            throws InstanceNotFoundException {
+        return delegate.getObjectInstance(name);
+    }
+
+    public Object instantiate(String className) throws ReflectionException,
+            MBeanException {
+        return delegate.instantiate(className);
+    }
+
+    public Object instantiate(String className, ObjectName loaderName)
+            throws ReflectionException, MBeanException,
+            InstanceNotFoundException {
+        return delegate.instantiate(className, loaderName);
+    }
+
+    public Object instantiate(String className, Object[] params,
+            String[] signature) throws ReflectionException, MBeanException {
+        return delegate.instantiate(className, params, signature);
+    }
+
+    public Object instantiate(String className, ObjectName loaderName,
+            Object[] params, String[] signature) throws ReflectionException,
+            MBeanException, InstanceNotFoundException {
+        return delegate.instantiate(className, loaderName, params, signature);
+    }
+
+    public Object invoke(ObjectName name, String operationName,
+            Object[] params, String[] signature)
+            throws InstanceNotFoundException, MBeanException,
+            ReflectionException {
+        return delegate.invoke(name, operationName, params, signature);
+    }
+
+    public boolean isInstanceOf(ObjectName name, String className)
+            throws InstanceNotFoundException {
+        return delegate.isInstanceOf(name, className);
+    }
+
+    public boolean isRegistered(ObjectName name) {
+        return strategy.isManaged(null, name);
+    }
+
+    public Set queryMBeans(ObjectName name, QueryExp query) {
+        return delegate.queryMBeans(name, query);
+    }
+
+    public Set queryNames(ObjectName name, QueryExp query) {
+        return delegate.queryNames(name, query);
+    }
+
+    public ObjectInstance registerMBean(Object object, ObjectName name)
+            throws InstanceAlreadyExistsException, MBeanRegistrationException,
+            NotCompliantMBeanException {
+        ObjectInstance instance = null;
+        try {
+            strategy.manageNamedObject(object, name);
+            instance = new ObjectInstance(name.toString(), object.getClass().getName());
+        } catch (MalformedObjectNameException mone) {
+            // ignore
+        } catch (Exception ex) {
+            if (ex.getCause() instanceof InstanceAlreadyExistsException) {
+                throw (InstanceAlreadyExistsException)ex.getCause();
+            } else if (ex.getCause() instanceof MBeanRegistrationException) {
+                throw (MBeanRegistrationException)ex.getCause();
+            } if (ex.getCause() instanceof NotCompliantMBeanException) {
+                throw (NotCompliantMBeanException)ex.getCause();
+            } else {
+                throw (RuntimeException)ex;
+            }
+        }
+        return instance;
+    }
+
+    public void removeNotificationListener(ObjectName name, ObjectName listener)
+            throws InstanceNotFoundException, ListenerNotFoundException {
+        delegate.removeNotificationListener(name, listener);
+    }
+
+    public void removeNotificationListener(ObjectName name,
+            NotificationListener listener) throws InstanceNotFoundException,
+            ListenerNotFoundException {
+        delegate.removeNotificationListener(name, listener);
+    }
+
+    public void removeNotificationListener(ObjectName name,
+            ObjectName listener, NotificationFilter filter, Object handback)
+            throws InstanceNotFoundException, ListenerNotFoundException {
+        delegate.removeNotificationListener(name, listener, filter, handback);
+    }
+
+    public void removeNotificationListener(ObjectName name,
+            NotificationListener listener, NotificationFilter filter,
+            Object handback) throws InstanceNotFoundException,
+            ListenerNotFoundException {
+        delegate.removeNotificationListener(name, listener, filter, handback);
+    }
+
+    public void setAttribute(ObjectName name, Attribute attribute)
+            throws InstanceNotFoundException, AttributeNotFoundException,
+            InvalidAttributeValueException, MBeanException, ReflectionException {
+        delegate.setAttribute(name, attribute);
+    }
+
+    public AttributeList setAttributes(ObjectName name, AttributeList attributes)
+            throws InstanceNotFoundException, ReflectionException {
+        return delegate.setAttributes(name, attributes);
+    }
+
+    public void unregisterMBean(ObjectName name)
+            throws InstanceNotFoundException, MBeanRegistrationException {
+        try {
+            strategy.unmanageNamedObject(name);
+        } catch (Exception ex) {
+            if (ex.getCause() instanceof InstanceNotFoundException) {
+                throw (InstanceNotFoundException)ex.getCause();
+            } else if (ex.getCause() instanceof MBeanRegistrationException) {
+                throw (MBeanRegistrationException)ex.getCause();
+            } else {
+                throw (RuntimeException)ex;
+            }
+        }
+
+    }
+
+}

Modified: servicemix/smx4/nmr/trunk/nmr/api/src/main/java/org/apache/servicemix/nmr/api/NMR.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/api/src/main/java/org/apache/servicemix/nmr/api/NMR.java?rev=807471&r1=807470&r2=807471&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/api/src/main/java/org/apache/servicemix/nmr/api/NMR.java (original)
+++ servicemix/smx4/nmr/trunk/nmr/api/src/main/java/org/apache/servicemix/nmr/api/NMR.java Tue Aug 25 04:15:57 2009
@@ -30,6 +30,13 @@
 public interface NMR {
 
     /**
+     * Access the NMR id.
+     *
+     * @return the NMR id
+     */
+    String getId();
+
+    /**
      * Access the endpoint registry.
      *
      * @return the endpoint registry

Modified: servicemix/smx4/nmr/trunk/nmr/core/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/core/pom.xml?rev=807471&r1=807470&r2=807471&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/core/pom.xml (original)
+++ servicemix/smx4/nmr/trunk/nmr/core/pom.xml Tue Aug 25 04:15:57 2009
@@ -72,6 +72,11 @@
             <artifactId>easymock</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.fusesource.commonman</groupId>
+            <artifactId>commons-management</artifactId>
+            <version>${commons.management.version}</version>
+        </dependency>
     </dependencies>
 
     <build>
@@ -93,4 +98,4 @@
         </plugins>
     </build>
 
-</project>
\ No newline at end of file
+</project>

Added: servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/NmrStartedEvent.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/NmrStartedEvent.java?rev=807471&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/NmrStartedEvent.java (added)
+++ servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/NmrStartedEvent.java Tue Aug 25 04:15:57 2009
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.servicemix.nmr.core;
+
+import java.util.EventObject;
+
+import org.apache.servicemix.nmr.api.NMR;
+
+/**
+ * Event representing an NMR instance having started.
+ */
+public class NmrStartedEvent extends EventObject {
+
+    private NMR nmr;
+
+    public NmrStartedEvent(NMR source) {
+        super(source);
+        this.nmr = source;
+    }
+
+    public NMR getNmr() {
+        return nmr;
+    }
+
+    public String toString() {
+        return "Started NMR: " + nmr.getId();
+    }
+}

Added: servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/NmrStoppedEvent.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/NmrStoppedEvent.java?rev=807471&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/NmrStoppedEvent.java (added)
+++ servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/NmrStoppedEvent.java Tue Aug 25 04:15:57 2009
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.servicemix.nmr.core;
+
+import java.util.EventObject;
+
+import org.apache.servicemix.nmr.api.NMR;
+
+/**
+ * Event representing an NMR instance having stopped.
+ */
+public class NmrStoppedEvent extends EventObject {
+
+    private NMR nmr;
+
+    public NmrStoppedEvent(NMR source) {
+        super(source);
+        this.nmr = source;
+    }
+
+    public NMR getNmr() {
+        return nmr;
+    }
+
+    public String toString() {
+        return "Stopped NMR: " + nmr.getId();
+    }
+}

Modified: servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/ServiceMix.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/ServiceMix.java?rev=807471&r1=807470&r2=807471&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/ServiceMix.java (original)
+++ servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/ServiceMix.java Tue Aug 25 04:15:57 2009
@@ -16,6 +16,8 @@
  */
 package org.apache.servicemix.nmr.core;
 
+import java.util.EventObject;
+
 import org.apache.servicemix.nmr.api.Channel;
 import org.apache.servicemix.nmr.api.EndpointRegistry;
 import org.apache.servicemix.nmr.api.NMR;
@@ -27,6 +29,9 @@
 import org.apache.servicemix.executors.ExecutorFactory;
 import org.apache.servicemix.executors.impl.ExecutorFactoryImpl;
 
+import org.fusesource.commons.management.ManagementStrategy;
+
+
 /**
  * This class is the servicemix class implementing the NMR
  */
@@ -39,6 +44,8 @@
     private FlowRegistry flows;
     private WireRegistry wires;
     private ExecutorFactory executorFactory;
+    private ManagementStrategy managementStrategy;
+    private String id;
 
     /**
      * Initialize ServiceMix
@@ -65,6 +72,14 @@
         if (wires == null) {
             wires = new WireRegistryImpl();
         }
+        fireEvent(new NmrStartedEvent(this));
+    }
+
+    /**
+     * Shutdown ServiceMix
+     */
+    public void shutdown() {
+        fireEvent(new NmrStoppedEvent(this));
     }
 
     /**
@@ -164,4 +179,48 @@
     public void setWireRegistry(WireRegistry wires) {
         this.wires = wires;
     }
+
+    /**
+     * Access the management strategy
+     *
+     * @return the management strategy
+     */
+    public ManagementStrategy getManagementStrategy() {
+        return managementStrategy;
+    }
+ 
+    /**
+     * Set the management strategy
+     * 
+     * @param managementStrategy the management strategy
+     */
+    public void setManagementStrategy(ManagementStrategy managementStrategy) {
+        this.managementStrategy = managementStrategy;
+    }
+
+    /**
+     * Access the NMR id
+     *
+     * @return the NMR id
+     */
+    public String getId() {
+        return id;
+    }
+ 
+    /**
+     * Set the NMR id
+     * 
+     * @param id the NMR id
+     */
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    private void fireEvent(EventObject event) {
+        try { 
+            getManagementStrategy().notify(event);
+        } catch (Exception e) {
+            // ignore
+        }  
+    }
 }

Modified: servicemix/smx4/nmr/trunk/nmr/management/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/management/pom.xml?rev=807471&r1=807470&r2=807471&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/management/pom.xml (original)
+++ servicemix/smx4/nmr/trunk/nmr/management/pom.xml Tue Aug 25 04:15:57 2009
@@ -26,6 +26,10 @@
         <version>1.1.0-SNAPSHOT</version>
     </parent>
 
+    <properties>
+      <junit4.version>4.6</junit4.version>
+    </properties>
+
     <groupId>org.apache.servicemix.nmr</groupId>
     <artifactId>org.apache.servicemix.nmr.management</artifactId>
     <packaging>bundle</packaging>
@@ -63,6 +67,23 @@
             <artifactId>commons-logging</artifactId>
             <scope>provided</scope>
         </dependency>
+      <dependency>
+          <groupId>org.fusesource.commonman</groupId>
+          <artifactId>commons-management</artifactId>
+          <version>${commons.management.version}</version>
+      </dependency>
+      <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>${junit4.version}</version>
+            <scope>test</scope>
+       </dependency>
+       <dependency>
+            <groupId>org.easymock</groupId>
+            <artifactId>easymockclassextension</artifactId>
+            <version>${easymock.version}</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
@@ -82,4 +103,4 @@
         </plugins>
     </build>
 
-</project>
\ No newline at end of file
+</project>

Modified: servicemix/smx4/nmr/trunk/nmr/management/src/main/java/org/apache/servicemix/nmr/management/DefaultNamingStrategy.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/management/src/main/java/org/apache/servicemix/nmr/management/DefaultNamingStrategy.java?rev=807471&r1=807470&r2=807471&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/management/src/main/java/org/apache/servicemix/nmr/management/DefaultNamingStrategy.java (original)
+++ servicemix/smx4/nmr/trunk/nmr/management/src/main/java/org/apache/servicemix/nmr/management/DefaultNamingStrategy.java Tue Aug 25 04:15:57 2009
@@ -16,15 +16,22 @@
  */
 package org.apache.servicemix.nmr.management;
 
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
 import javax.management.ObjectName;
 import javax.management.MalformedObjectNameException;
 
-import org.apache.servicemix.nmr.api.Endpoint;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
  */
 public class DefaultNamingStrategy implements NamingStrategy {
 
+    private static final Log LOG = LogFactory.getLog(DefaultNamingStrategy.class);
+
     private String jmxDomainName;
 
     public String getJmxDomainName() {
@@ -38,9 +45,15 @@
     public ObjectName getObjectName(ManagedEndpoint endpoint) throws MalformedObjectNameException {
         return new ObjectName(jmxDomainName + ":Type=Endpoint,Id=" + sanitize(getId(endpoint)));
     }
-
-    private String getId(ManagedEndpoint endpoint) {
-        return endpoint.getEndpoint().getId();
+    
+    public ObjectName getObjectName(Nameable nameable) throws MalformedObjectNameException {
+        String name = jmxDomainName + ":" +
+                (nameable.getParent() != null ? "ContainerName=" + sanitize(nameable.getParent()) + "," : "") +
+                "Type=" + sanitize(nameable.getType()) +
+                ",Name=" + sanitize(nameable.getName()) +
+                (nameable.getVersion() != null ? ",Version=" + sanitize(nameable.getVersion()) : "") +
+                (nameable.getSubType() != null ? ",SubType=" + sanitize(nameable.getSubType()) : "");
+        return new ObjectName(name);
     }
 
     private String sanitize(String in) {
@@ -56,5 +69,63 @@
         return result;
     }
 
+    public ObjectName getCustomObjectName(String type, String name) {
+        Map<String, String> result = new LinkedHashMap<String, String>();
+        result.put("Type", "Component");
+        result.put("Name", sanitize(name));
+        result.put("SubType", sanitize(type));
+        return createObjectName(result);
+    }
+
+    public ObjectName createObjectName(Map<String, String> props) {
+        StringBuffer sb = new StringBuffer();
+        sb.append(getJmxDomainName()).append(':');
+        int i = 0;
+        for (Iterator it = props.entrySet().iterator(); it.hasNext();) {
+            Map.Entry entry = (Map.Entry) it.next();
+            if (i++ > 0) {
+                sb.append(",");
+            }
+            sb.append(entry.getKey()).append("=").append(entry.getValue());
+        }
+        ObjectName result = null;
+        try {
+            result = new ObjectName(sb.toString());
+        } catch (MalformedObjectNameException e) {
+            // shouldn't happen
+            String error = "Could not create ObjectName for " + props;
+            LOG.error(error, e);
+            throw new RuntimeException(error);
+        }
+        return result;
+    }
+
+    public static ObjectName getSystemObjectName(String domainName, String containerName, Class interfaceType) {
+        String tmp = domainName + ":ContainerName=" + containerName + ",Type=SystemService,Name=" + getSystemServiceName(interfaceType);
+        ObjectName result = null;
+        try {
+            result = new ObjectName(tmp);
+        } catch (MalformedObjectNameException e) {
+            LOG.error("Failed to build ObjectName:", e);
+        } catch (NullPointerException e) {
+            LOG.error("Failed to build ObjectName:", e);
+        }
+        return result;
+    }
+
+    public static String getSystemServiceName(Class interfaceType) {
+        String name = interfaceType.getName();
+        name = name.substring(name.lastIndexOf('.') + 1);
+        if (name.endsWith("MBean")) {
+            name = name.substring(0, name.length() - 5);
+        }
+        return name;
+    }
+    
+    private String getId(ManagedEndpoint endpoint) {
+        return endpoint.getEndpoint().getId();
+    }
+
+
 }