servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r633939 [1/2] - in /servicemix/smx4/nmr/trunk: jbi/ jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ jbi/itests/src/test/java/org/apache/servicemix/jbi/ jbi/management/ jbi/management/src/ jbi/management/src/main/ jbi/man...
Date Wed, 05 Mar 2008 17:24:06 GMT
Author: gnodet
Date: Wed Mar  5 09:23:59 2008
New Revision: 633939

URL: http://svn.apache.org/viewvc?rev=633939&view=rev
Log:
SMX4NMR-11: Create JMX layer for managing endpoints and JBI artifacts

Added:
    servicemix/smx4/nmr/trunk/jbi/itests/src/test/java/org/apache/servicemix/jbi/FrameworkUtil.java
    servicemix/smx4/nmr/trunk/jbi/management/   (with props)
    servicemix/smx4/nmr/trunk/jbi/management/pom.xml
    servicemix/smx4/nmr/trunk/jbi/management/src/
    servicemix/smx4/nmr/trunk/jbi/management/src/main/
    servicemix/smx4/nmr/trunk/jbi/management/src/main/java/
    servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/
    servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/
    servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/
    servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/
    servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/
    servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/DefaultNamingStrategy.java
    servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagedComponent.java
    servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagedJbiRegistry.java
    servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagedServiceAssembly.java
    servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagedSharedLibrary.java
    servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagementAgent.java
    servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/NamingStrategy.java
    servicemix/smx4/nmr/trunk/jbi/management/src/main/resources/
    servicemix/smx4/nmr/trunk/jbi/management/src/main/resources/META-INF/
    servicemix/smx4/nmr/trunk/jbi/management/src/main/resources/META-INF/spring/
    servicemix/smx4/nmr/trunk/jbi/management/src/main/resources/META-INF/spring/servicemix-jbi-management.xml
    servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/FrameworkUtil.java
    servicemix/smx4/nmr/trunk/nmr/management/   (with props)
    servicemix/smx4/nmr/trunk/nmr/management/pom.xml
    servicemix/smx4/nmr/trunk/nmr/management/src/
    servicemix/smx4/nmr/trunk/nmr/management/src/main/
    servicemix/smx4/nmr/trunk/nmr/management/src/main/java/
    servicemix/smx4/nmr/trunk/nmr/management/src/main/java/org/
    servicemix/smx4/nmr/trunk/nmr/management/src/main/java/org/apache/
    servicemix/smx4/nmr/trunk/nmr/management/src/main/java/org/apache/servicemix/
    servicemix/smx4/nmr/trunk/nmr/management/src/main/java/org/apache/servicemix/nmr/
    servicemix/smx4/nmr/trunk/nmr/management/src/main/java/org/apache/servicemix/nmr/management/
    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/
    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/
    servicemix/smx4/nmr/trunk/nmr/management/src/main/resources/META-INF/
    servicemix/smx4/nmr/trunk/nmr/management/src/main/resources/META-INF/spring/
    servicemix/smx4/nmr/trunk/nmr/management/src/main/resources/META-INF/spring/servicemix-nmr-management.xml
    servicemix/smx4/nmr/trunk/nmr/management/src/test/
    servicemix/smx4/nmr/trunk/nmr/management/src/test/java/
    servicemix/smx4/nmr/trunk/nmr/management/src/test/java/org/
    servicemix/smx4/nmr/trunk/nmr/management/src/test/java/org/apache/
    servicemix/smx4/nmr/trunk/nmr/management/src/test/java/org/apache/servicemix/
    servicemix/smx4/nmr/trunk/nmr/management/src/test/java/org/apache/servicemix/nmr/
    servicemix/smx4/nmr/trunk/nmr/management/src/test/java/org/apache/servicemix/nmr/management/
    servicemix/smx4/nmr/trunk/nmr/management/src/test/java/org/apache/servicemix/nmr/management/stats/
    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/StatisticTestSupport.java
    servicemix/smx4/nmr/trunk/nmr/management/src/test/java/org/apache/servicemix/nmr/management/stats/TimeStatisticTest.java
    servicemix/smx4/nmr/trunk/nmr/osgi/src/main/java/
    servicemix/smx4/nmr/trunk/nmr/osgi/src/main/java/org/
    servicemix/smx4/nmr/trunk/nmr/osgi/src/main/java/org/apache/
    servicemix/smx4/nmr/trunk/nmr/osgi/src/main/java/org/apache/servicemix/
    servicemix/smx4/nmr/trunk/nmr/osgi/src/main/java/org/apache/servicemix/nmr/
    servicemix/smx4/nmr/trunk/nmr/osgi/src/main/java/org/apache/servicemix/nmr/osgi/
    servicemix/smx4/nmr/trunk/nmr/osgi/src/main/java/org/apache/servicemix/nmr/osgi/InternalRegistryWrapper.java
Modified:
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ComponentImpl.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java
    servicemix/smx4/nmr/trunk/jbi/itests/src/test/java/org/apache/servicemix/jbi/IntegrationTest.java
    servicemix/smx4/nmr/trunk/jbi/osgi/pom.xml
    servicemix/smx4/nmr/trunk/jbi/osgi/src/main/java/org/apache/servicemix/jbi/osgi/RegistryWrapper.java
    servicemix/smx4/nmr/trunk/jbi/pom.xml
    servicemix/smx4/nmr/trunk/jbi/runtime/   (props changed)
    servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentContextImpl.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/EndpointImpl.java
    servicemix/smx4/nmr/trunk/nmr/api/src/main/java/org/apache/servicemix/nmr/api/event/EndpointListener.java
    servicemix/smx4/nmr/trunk/nmr/api/src/main/java/org/apache/servicemix/nmr/api/internal/InternalEndpoint.java
    servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/ChannelImpl.java
    servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/ClientChannel.java
    servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/EndpointRegistryImpl.java
    servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/InternalEndpointWrapper.java
    servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/ServiceRegistryImpl.java
    servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/EndpointRegistryImplTest.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/nmr/pom.xml

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ComponentImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ComponentImpl.java?rev=633939&r1=633938&r2=633939&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ComponentImpl.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ComponentImpl.java Wed Mar  5 09:23:59 2008
@@ -92,29 +92,48 @@
     }
 
     public void start() throws JBIException {
+        start(true);
+    }
+
+    public void start(boolean saveState) throws JBIException {
         component.getLifeCycle().start();
         state = State.Started;
-        saveState();
+        if (saveState) {
+            saveState();
+        }
     }
 
     public void stop() throws JBIException {
+        stop(true);
+
+    }
+
+    public void stop(boolean saveState) throws JBIException {
         // TODO: stop deployed SAs
         if (state == State.Started) {
             component.getLifeCycle().stop();
             state = State.Stopped;
-            saveState();
+            if (saveState) {
+                saveState();
+            }
         }
     }
 
     public void shutDown() throws JBIException {
+        shutDown(true);
+    }
+
+    public void shutDown(boolean saveState) throws JBIException {
         // TODO: shutdown deployed SAs
         if (state == State.Started) {
-            stop();
+            stop(saveState);
         }
         if (state == State.Stopped) {
             component.getLifeCycle().shutDown();
             state = State.Shutdown;
-            saveState();
+            if (saveState) {
+                saveState();
+            }
         }
     }
 
@@ -139,6 +158,10 @@
             default:
                 return LifeCycleMBean.UNKNOWN;
         }
+    }
+
+    public State getState() {
+        return state;
     }
 
     protected class ComponentWrapper implements javax.jbi.component.Component, ComponentLifeCycle {

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=633939&r1=633938&r2=633939&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 Wed Mar  5 09:23:59 2008
@@ -74,6 +74,8 @@
 
     private Map<String, ServiceAssemblyImpl> serviceAssemblies;
 
+    private Map<String, ComponentImpl> components;
+
     private Map<Bundle, List<ServiceRegistration>> services;
 
     private List<Bundle> pendingBundles;
@@ -87,6 +89,7 @@
     public Deployer() throws JBIException{
         sharedLibraries = new ConcurrentHashMap<String, SharedLibraryImpl>();
         serviceAssemblies = new ConcurrentHashMap<String, ServiceAssemblyImpl>();
+        components = new ConcurrentHashMap<String, ComponentImpl>();
         services = new ConcurrentHashMap<Bundle, List<ServiceRegistration>>();
         pendingBundles = new ArrayList<Bundle>();
         // TODO: control that using properties
@@ -200,6 +203,7 @@
         Class clazz = classLoader.loadClass(componentDesc.getComponentClassName());
         javax.jbi.component.Component innerComponent = (javax.jbi.component.Component) clazz.newInstance();
         ComponentImpl component = new ComponentImpl(componentDesc, innerComponent, prefs, autoStart, this);
+        components.put(name, component);
         // populate props from the component meta-data
         Dictionary<String, String> props = new Hashtable<String, String>();
         props.put(NAME, name);
@@ -315,11 +319,21 @@
 
     protected void uninstallComponent(ComponentDesc componentDesc, Bundle bundle) throws Exception {
         String name = componentDesc.getIdentification().getName();
-        File file = new File(System.getProperty("servicemix.base"), "data/jbi/" + name);
-        FileUtil.deleteFile(file);
+        ComponentImpl component = components.remove(name);
+        if (component != null) {
+            if (component.getState() == ComponentImpl.State.Started) {
+                component.stop(false);
+            }
+            if (component.getState() == ComponentImpl.State.Stopped) {
+                component.shutDown(false);
+            }
+            File file = new File(System.getProperty("servicemix.base"), "data/jbi/" + name);
+            FileUtil.deleteFile(file);
+        }
     }
     protected void undeployServiceAssembly(ServiceAssemblyDesc serviceAssembyDesc, Bundle bundle) throws Exception {
-        ServiceAssemblyImpl sa = serviceAssemblies.remove(serviceAssembyDesc.getIdentification().getName());
+        String name = serviceAssembyDesc.getIdentification().getName();
+        ServiceAssemblyImpl sa = serviceAssemblies.remove(name);
         if (sa != null) {
             if (sa.getState() == ServiceAssemblyImpl.State.Started) {
                 sa.stop(false);

Added: servicemix/smx4/nmr/trunk/jbi/itests/src/test/java/org/apache/servicemix/jbi/FrameworkUtil.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/itests/src/test/java/org/apache/servicemix/jbi/FrameworkUtil.java?rev=633939&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/itests/src/test/java/org/apache/servicemix/jbi/FrameworkUtil.java (added)
+++ servicemix/smx4/nmr/trunk/jbi/itests/src/test/java/org/apache/servicemix/jbi/FrameworkUtil.java Wed Mar  5 09:23:59 2008
@@ -0,0 +1,31 @@
+/*
+ * 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;
+
+import org.apache.felix.framework.FilterImpl;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+
+/**
+ */
+public class FrameworkUtil {
+
+    public static Filter createFilter(String f) throws InvalidSyntaxException {
+        return new FilterImpl(f);
+    }
+
+}

Modified: servicemix/smx4/nmr/trunk/jbi/itests/src/test/java/org/apache/servicemix/jbi/IntegrationTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/itests/src/test/java/org/apache/servicemix/jbi/IntegrationTest.java?rev=633939&r1=633938&r2=633939&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/itests/src/test/java/org/apache/servicemix/jbi/IntegrationTest.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/itests/src/test/java/org/apache/servicemix/jbi/IntegrationTest.java Wed Mar  5 09:23:59 2008
@@ -36,6 +36,7 @@
         System.setProperty("org.apache.servicemix.filemonitor.generatedJarDir", new File(f, "data/generate-bundles").getAbsolutePath());
         System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
         System.setProperty("javax.xml.parsers.SAXParserFactory", "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl");
+        System.setProperty("org.osgi.vendor.framework", "org.apache.servicemix.jbi");
     }
 
     private Properties dependencies;

Propchange: servicemix/smx4/nmr/trunk/jbi/management/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Wed Mar  5 09:23:59 2008
@@ -0,0 +1,7 @@
+target
+*.iml
+*.ipr
+*.iws
+.classpath
+.project
+.settings

Added: servicemix/smx4/nmr/trunk/jbi/management/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/management/pom.xml?rev=633939&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/management/pom.xml (added)
+++ servicemix/smx4/nmr/trunk/jbi/management/pom.xml Wed Mar  5 09:23:59 2008
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <!--
+
+        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.
+    -->
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.servicemix.jbi</groupId>
+        <artifactId>jbi</artifactId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+
+    <groupId>org.apache.servicemix.jbi</groupId>
+    <artifactId>org.apache.servicemix.jbi.management</artifactId>
+    <packaging>bundle</packaging>
+    <name>ServiceMix JBI Management</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.servicemix.jbi</groupId>
+            <artifactId>org.apache.servicemix.jbi.runtime</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.servicemix.jbi</groupId>
+            <artifactId>org.apache.servicemix.jbi.deployer</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <version>${felix.osgi.version}</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <configuration>
+                    <instructions>
+                        <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
+                        <Import-Package>*</Import-Package>
+                        <Export-Package>${pom.artifactId}*;version=${pom.version}</Export-Package>
+                        <Spring-Context>*;publish-context:=false;create-asynchronously:=true</Spring-Context>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>

Added: servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/DefaultNamingStrategy.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/DefaultNamingStrategy.java?rev=633939&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/DefaultNamingStrategy.java (added)
+++ servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/DefaultNamingStrategy.java Wed Mar  5 09:23:59 2008
@@ -0,0 +1,70 @@
+/*
+ * 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.management;
+
+import javax.management.ObjectName;
+import javax.management.MalformedObjectNameException;
+
+/**
+ */
+public class DefaultNamingStrategy implements NamingStrategy {
+
+    private String jmxDomainName;
+
+    public String getJmxDomainName() {
+        return jmxDomainName;
+    }
+
+    public void setJmxDomainName(String jmxDomainName) {
+        this.jmxDomainName = jmxDomainName;
+    }
+
+    public ObjectName getObjectName(ManagedSharedLibrary sharedLibrary) throws MalformedObjectNameException {
+        return new ObjectName(jmxDomainName + ":" +
+                                    "Type=SharedLibrary," +
+                                    "Name=" + sanitize(sharedLibrary.getName()) + "," +
+                                    "Version=" + sanitize(sharedLibrary.getVersion()));
+    }
+
+    public ObjectName getObjectName(ManagedComponent component) throws MalformedObjectNameException {
+        return new ObjectName(jmxDomainName + ":" +
+                                    "Type=Component," +
+                                    "Name=" + sanitize(component.getName()) + "," +
+                                    "SubType=LifeCycle");
+    }
+
+    public ObjectName getObjectName(ManagedServiceAssembly serviceAssembly) throws MalformedObjectNameException {
+        return new ObjectName(jmxDomainName + ":" +
+                                    "Type=ServiceAssembly," +
+                                    "Name=" + sanitize(serviceAssembly.getName()));
+    }
+
+    private String sanitize(String in) {
+        String result = null;
+        if (in != null) {
+            result = in.replace(':', '_');
+            result = result.replace('/', '_');
+            result = result.replace('\\', '_');
+            result = result.replace('?', '_');
+            result = result.replace('=', '_');
+            result = result.replace(',', '_');
+        }
+        return result;
+    }
+
+}
+

Added: servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagedComponent.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagedComponent.java?rev=633939&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagedComponent.java (added)
+++ servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagedComponent.java Wed Mar  5 09:23:59 2008
@@ -0,0 +1,71 @@
+/*
+ * 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.management;
+
+import java.util.Map;
+
+import javax.jbi.JBIException;
+import javax.jbi.management.ComponentLifeCycleMBean;
+import javax.management.ObjectName;
+
+import org.apache.servicemix.jbi.deployer.Component;
+import org.springframework.jmx.export.annotation.ManagedAttribute;
+import org.springframework.jmx.export.annotation.ManagedOperation;
+import org.springframework.jmx.export.annotation.ManagedResource;
+
+/**
+ */
+@ManagedResource(description = "Managed Component", currencyTimeLimit = 15)
+public class ManagedComponent implements ComponentLifeCycleMBean {
+
+    private final Component component;
+    private final Map<String, ?> properties;
+
+    public ManagedComponent(Component component, Map<String, ?> properties) {
+        this.component = component;
+        this.properties = properties;
+    }
+
+    public String getName() {
+        return component.getName();
+    }
+
+    @ManagedAttribute
+    public ObjectName getExtensionMBeanName() throws JBIException {
+        return component.getExtensionMBeanName();
+    }
+
+    @ManagedOperation
+    public void start() throws JBIException {
+        component.start();
+    }
+
+    @ManagedOperation
+    public void stop() throws JBIException {
+        component.stop();
+    }
+
+    @ManagedOperation
+    public void shutDown() throws JBIException {
+        component.shutDown();
+    }
+
+    @ManagedAttribute
+    public String getCurrentState() {
+        return component.getCurrentState();
+    }
+}

Added: servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagedJbiRegistry.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagedJbiRegistry.java?rev=633939&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagedJbiRegistry.java (added)
+++ servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagedJbiRegistry.java Wed Mar  5 09:23:59 2008
@@ -0,0 +1,136 @@
+/*
+ * 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.management;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+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.ServiceAssembly;
+import org.apache.servicemix.jbi.deployer.SharedLibrary;
+import org.springframework.beans.factory.InitializingBean;
+
+/**
+ */
+public class ManagedJbiRegistry implements InitializingBean {
+
+    private static final transient Log LOG = LogFactory.getLog(ManagedJbiRegistry.class);
+
+    private NamingStrategy namingStrategy;
+    private ManagementAgent managementAgent;
+    private Map<String, ManagedSharedLibrary> sharedLibraries;
+    private Map<String, ManagedComponent> components;
+    private Map<String, ManagedServiceAssembly> serviceAssemblies;
+
+    public ManagedJbiRegistry() {
+        this.sharedLibraries = new ConcurrentHashMap<String, ManagedSharedLibrary>();
+        this.components = new ConcurrentHashMap<String, ManagedComponent>();
+        this.serviceAssemblies = new ConcurrentHashMap<String, ManagedServiceAssembly>();
+    }
+
+    public NamingStrategy getNamingStrategy() {
+        return namingStrategy;
+    }
+
+    public void setNamingStrategy(NamingStrategy namingStrategy) {
+        this.namingStrategy = namingStrategy;
+    }
+
+    public ManagementAgent getManagementAgent() {
+        return managementAgent;
+    }
+
+    public void setManagementAgent(ManagementAgent managementAgent) {
+        this.managementAgent = managementAgent;
+    }
+
+    public void registerSharedLibrary(SharedLibrary sharedLibrary, Map<String, ?> properties) {
+        try {
+            LOG.info("Registering SharedLibrary: " + sharedLibrary + " with properties " + properties);
+            ManagedSharedLibrary sl = new ManagedSharedLibrary(sharedLibrary, properties);
+            sharedLibraries.put(sharedLibrary.getName() + "-" + sharedLibrary.getVersion(), sl);
+            managementAgent.register(sl, namingStrategy.getObjectName(sl));
+        } catch (Exception e) {
+            LOG.warn("Unable to register managed SharedLibrary: " + e, e);
+        }
+    }
+
+    public void unregisterSharedLibrary(SharedLibrary sharedLibrary, Map<String, ?> properties) {
+        try {
+            LOG.info("Unregistering SharedLibrary: " + sharedLibrary + " with properties " + properties);
+            ManagedSharedLibrary sl = sharedLibraries.remove(sharedLibrary.getName() + "-" + sharedLibrary.getVersion());
+            managementAgent.unregister(namingStrategy.getObjectName(sl));
+        } catch (Exception e) {
+            LOG.warn("Unable to unregister managed SharedLibrary: " + e, e);
+        }
+    }
+
+    public void registerComponent(Component component, Map<String, ?> properties) {
+        try {
+            LOG.info("Registering Component: " + component + " with properties " + properties);
+            ManagedComponent comp = new ManagedComponent(component, properties);
+            components.put(component.getName(), comp);
+            managementAgent.register(comp, namingStrategy.getObjectName(comp));
+        } catch (Exception e) {
+            LOG.warn("Unable to register managed Component: " + e, e);
+        }
+    }
+
+    public void unregisterComponent(Component component, Map<String, ?> properties) {
+        try {
+            LOG.info("Unregistering Component: " + component + " with properties " + properties);
+            ManagedComponent comp = components.remove(component.getName());
+            managementAgent.unregister(namingStrategy.getObjectName(comp));
+        } catch (Exception e) {
+            LOG.warn("Unable to unregister managed Component: " + e, e);
+        }
+    }
+
+    public void registerServiceAssembly(ServiceAssembly serviceAssembly, Map<String, ?> properties) {
+        try {
+            LOG.info("Registering ServiceAssembly: " + serviceAssembly + " with properties " + properties);
+            ManagedServiceAssembly sa = new ManagedServiceAssembly(serviceAssembly, properties);
+            serviceAssemblies.put(serviceAssembly.getName(), sa);
+            managementAgent.register(sa, namingStrategy.getObjectName(sa));
+        } catch (Exception e) {
+            LOG.warn("Unable to register ServiceAssembly: " + e, e);
+        }
+    }
+
+    public void unregisterServiceAssembly(ServiceAssembly serviceAssembly, Map<String, ?> properties) {
+        try {
+            LOG.info("Unregistering ServiceAssembly: " + serviceAssembly + " with properties " + properties);
+            ManagedServiceAssembly sa = serviceAssemblies.remove(serviceAssembly.getName());
+            managementAgent.unregister(namingStrategy.getObjectName(sa));
+        } catch (Exception e) {
+            LOG.warn("Unable to unregister managed ServiceAssembly: " + e, e);
+        }
+    }
+
+    public void afterPropertiesSet() throws Exception {
+        if (managementAgent == null) {
+            throw new IllegalArgumentException("managementAgent must not be null");
+        }
+        if (namingStrategy == null) {
+            throw new IllegalArgumentException("namingStrategy must not be null");
+        }
+
+    }
+
+}

Added: servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagedServiceAssembly.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagedServiceAssembly.java?rev=633939&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagedServiceAssembly.java (added)
+++ servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagedServiceAssembly.java Wed Mar  5 09:23:59 2008
@@ -0,0 +1,65 @@
+/*
+ * 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.management;
+
+import java.util.Map;
+
+import javax.jbi.JBIException;
+import javax.jbi.management.LifeCycleMBean;
+
+import org.apache.servicemix.jbi.deployer.ServiceAssembly;
+import org.springframework.jmx.export.annotation.ManagedAttribute;
+import org.springframework.jmx.export.annotation.ManagedOperation;
+import org.springframework.jmx.export.annotation.ManagedResource;
+
+/**
+ */
+@ManagedResource(description = "Managed ServiceAssembly", currencyTimeLimit = 15)
+public class ManagedServiceAssembly implements LifeCycleMBean {
+
+    private final ServiceAssembly serviceAssembly;
+    private final Map<String, ?> properties;
+
+    public ManagedServiceAssembly(ServiceAssembly serviceAssembly, Map<String, ?> properties) {
+        this.serviceAssembly = serviceAssembly;
+        this.properties = properties;
+    }
+
+    public String getName() {
+        return serviceAssembly.getName();
+    }
+
+    @ManagedOperation
+    public void start() throws JBIException {
+        serviceAssembly.start();
+    }
+
+    @ManagedOperation
+    public void stop() throws JBIException {
+        serviceAssembly.stop();
+    }
+
+    @ManagedOperation
+    public void shutDown() throws JBIException {
+        serviceAssembly.shutDown();
+    }
+
+    @ManagedAttribute
+    public String getCurrentState() {
+        return serviceAssembly.getCurrentState();
+    }
+}

Added: servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagedSharedLibrary.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagedSharedLibrary.java?rev=633939&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagedSharedLibrary.java (added)
+++ servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagedSharedLibrary.java Wed Mar  5 09:23:59 2008
@@ -0,0 +1,48 @@
+/*
+ * 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.management;
+
+import java.util.Map;
+
+import org.apache.servicemix.jbi.deployer.SharedLibrary;
+import org.springframework.jmx.export.annotation.ManagedResource;
+
+/**
+ */
+@ManagedResource(description = "Managed SharedLibrary", currencyTimeLimit = 15)
+public class ManagedSharedLibrary {
+
+    private final SharedLibrary sharedLibrary;
+    private final Map<String, ?> properties;
+
+    public ManagedSharedLibrary(SharedLibrary sharedLibrary, Map<String, ?> properties) {
+        this.sharedLibrary = sharedLibrary;
+        this.properties = properties;
+    }
+
+    public String getId() {
+        return sharedLibrary.getName() + "-" + sharedLibrary.getVersion();
+    }
+
+    public String getName() {
+        return sharedLibrary.getName();
+    }
+
+    public String getVersion() {
+        return sharedLibrary.getVersion();
+    }
+}

Added: servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagementAgent.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagementAgent.java?rev=633939&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagementAgent.java (added)
+++ servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagementAgent.java Wed Mar  5 09:23:59 2008
@@ -0,0 +1,126 @@
+/*
+ * 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.management;
+
+import java.util.Set;
+import java.util.HashSet;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.management.JMException;
+import javax.management.NotCompliantMBeanException;
+import javax.management.ObjectInstance;
+import javax.management.InstanceAlreadyExistsException;
+import javax.management.modelmbean.ModelMBeanInfo;
+import javax.management.modelmbean.RequiredModelMBean;
+import javax.management.modelmbean.InvalidTargetObjectTypeException;
+
+import org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler;
+import org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource;
+import org.springframework.beans.factory.DisposableBean;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ */
+public class ManagementAgent implements DisposableBean {
+
+    private static final transient Log LOG = LogFactory.getLog(ManagementAgent.class);
+
+    private MBeanServer mbeanServer;
+    private MetadataMBeanInfoAssembler assembler;
+    private Set<ObjectName> mbeans = new HashSet<ObjectName>();
+
+    public ManagementAgent() {
+        assembler = new MetadataMBeanInfoAssembler();
+        assembler.setAttributeSource(new AnnotationJmxAttributeSource());
+    }
+
+    public MBeanServer getMbeanServer() {
+        return mbeanServer;
+    }
+
+    public void setMbeanServer(MBeanServer mbeanServer) {
+        this.mbeanServer = mbeanServer;
+    }
+
+    public void destroy() throws Exception {
+        // Using the array to hold the busMBeans to avoid the
+        // CurrentModificationException
+        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++;
+            }
+        }
+        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 {
+        register(obj, name, false);
+    }
+
+    public void register(Object obj, ObjectName name, boolean forceRegistration) throws JMException {
+        try {
+            registerMBeanWithServer(obj, name, forceRegistration);
+        } catch (NotCompliantMBeanException e) {
+            // If this is not a "normal" MBean, then try to deploy it using JMX
+            // annotations
+            ModelMBeanInfo mbi = assembler.getMBeanInfo(obj, name.toString());
+            RequiredModelMBean mbean = (RequiredModelMBean) mbeanServer.instantiate(RequiredModelMBean.class.getName());
+            mbean.setModelMBeanInfo(mbi);
+            try {
+                mbean.setManagedResource(obj, "ObjectReference");
+            } catch (InvalidTargetObjectTypeException itotex) {
+                throw new JMException(itotex.getMessage());
+            }
+            registerMBeanWithServer(mbean, name, forceRegistration);
+        }
+    }
+
+    public void unregister(ObjectName name) throws JMException {
+        mbeanServer.unregisterMBean(name);
+    }
+
+    private void registerMBeanWithServer(Object obj, ObjectName name, boolean forceRegistration) throws JMException {
+        ObjectInstance instance = null;
+        try {
+            instance = mbeanServer.registerMBean(obj, name);
+        } catch (InstanceAlreadyExistsException e) {
+            if (forceRegistration) {
+                mbeanServer.unregisterMBean(name);
+                instance = mbeanServer.registerMBean(obj, name);
+            } else {
+                throw e;
+            }
+        }
+
+        if (instance != null) {
+            mbeans.add(name);
+        }
+    }
+
+}

Added: servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/NamingStrategy.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/NamingStrategy.java?rev=633939&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/NamingStrategy.java (added)
+++ servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/NamingStrategy.java Wed Mar  5 09:23:59 2008
@@ -0,0 +1,32 @@
+/*
+ * 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.management;
+
+import javax.management.ObjectName;
+import javax.management.MalformedObjectNameException;
+
+/**
+ */
+public interface NamingStrategy {
+
+    ObjectName getObjectName(ManagedSharedLibrary sharedLibrary) throws MalformedObjectNameException;
+
+    ObjectName getObjectName(ManagedComponent component) throws MalformedObjectNameException;
+
+    ObjectName getObjectName(ManagedServiceAssembly serviceAssembly) throws MalformedObjectNameException;
+
+}

Added: servicemix/smx4/nmr/trunk/jbi/management/src/main/resources/META-INF/spring/servicemix-jbi-management.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/management/src/main/resources/META-INF/spring/servicemix-jbi-management.xml?rev=633939&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/management/src/main/resources/META-INF/spring/servicemix-jbi-management.xml (added)
+++ servicemix/smx4/nmr/trunk/jbi/management/src/main/resources/META-INF/spring/servicemix-jbi-management.xml Wed Mar  5 09:23:59 2008
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:osgi="http://www.springframework.org/schema/osgi"
+       xmlns:util="http://www.springframework.org/schema/util"
+       xsi:schemaLocation="
+  http://www.springframework.org/schema/beans
+  http://www.springframework.org/schema/beans/spring-beans.xsd
+  http://www.springframework.org/schema/util
+  http://www.springframework.org/schema/util/spring-util.xsd
+  http://www.springframework.org/schema/osgi
+  http://www.springframework.org/schema/osgi/spring-osgi.xsd">
+
+    <!-- MBeanServer -->
+    <osgi:reference id="mbeanServer"
+                    interface="javax.management.MBeanServer"
+                    cardinality="1..1" />
+
+    <!-- Registries -->
+    <bean id="managedJbiRegistry" class="org.apache.servicemix.jbi.management.ManagedJbiRegistry">
+        <property name="namingStrategy" ref="namingStrategy" />
+        <property name="managementAgent" ref="managementAgent" />
+    </bean>
+
+    <bean id="namingStrategy" class="org.apache.servicemix.jbi.management.DefaultNamingStrategy">
+        <property name="jmxDomainName" value="org.apache.servicemix" />
+    </bean>
+
+    <bean id="managementAgent" class="org.apache.servicemix.jbi.management.ManagementAgent">
+        <property name="mbeanServer" ref="mbeanServer" />
+    </bean>
+
+    <!-- Shared Libraries -->
+    <osgi:list id="sharedLibraries"
+               interface="org.apache.servicemix.jbi.deployer.SharedLibrary"
+               cardinality="0..N">
+        <osgi:listener ref="managedJbiRegistry" bind-method="registerSharedLibrary" unbind-method="unregisterSharedLibrary" />
+    </osgi:list>
+
+    <!-- Components -->
+    <osgi:list id="components"
+               interface="org.apache.servicemix.jbi.deployer.Component"
+               cardinality="0..N">
+        <osgi:listener ref="managedJbiRegistry" bind-method="registerComponent" unbind-method="unregisterComponent" />
+    </osgi:list>
+
+    <!-- Service Assemblies -->
+    <osgi:list id="serviceAssemblies"
+               interface="org.apache.servicemix.jbi.deployer.ServiceAssembly"
+               cardinality="0..N">
+        <osgi:listener ref="managedJbiRegistry" bind-method="registerServiceAssembly" unbind-method="unregisterServiceAssembly" />
+    </osgi:list>
+
+</beans>

Modified: servicemix/smx4/nmr/trunk/jbi/osgi/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/osgi/pom.xml?rev=633939&r1=633938&r2=633939&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/osgi/pom.xml (original)
+++ servicemix/smx4/nmr/trunk/jbi/osgi/pom.xml Wed Mar  5 09:23:59 2008
@@ -36,6 +36,11 @@
     <dependencies>
         <dependency>
             <groupId>org.apache.servicemix.jbi</groupId>
+            <artifactId>org.apache.servicemix.jbi.api</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.servicemix.jbi</groupId>
             <artifactId>org.apache.servicemix.jbi.runtime</artifactId>
             <version>${project.version}</version>
         </dependency>
@@ -59,7 +64,18 @@
                 <configuration>
                     <instructions>
                         <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
-                        <Import-Package>*</Import-Package>
+                        <Import-Package>
+                            javax.jbi.component,
+                            javax.management,
+                            javax.naming,
+                            javax.transaction,
+                            org.apache.servicemix.nmr.api,
+                            org.apache.servicemix.jbi.runtime,
+                            org.apache.servicemix.jbi.runtime.impl,
+                            org.apache.servicemix.jbi.osgi,
+                            org.osgi.service.url,
+                            *
+                        </Import-Package>
                         <Spring-Context>*;publish-context:=false;create-asynchronously:=true</Spring-Context>
                     </instructions>
                 </configuration>

Modified: servicemix/smx4/nmr/trunk/jbi/osgi/src/main/java/org/apache/servicemix/jbi/osgi/RegistryWrapper.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/osgi/src/main/java/org/apache/servicemix/jbi/osgi/RegistryWrapper.java?rev=633939&r1=633938&r2=633939&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/osgi/src/main/java/org/apache/servicemix/jbi/osgi/RegistryWrapper.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/osgi/src/main/java/org/apache/servicemix/jbi/osgi/RegistryWrapper.java Wed Mar  5 09:23:59 2008
@@ -40,6 +40,7 @@
  *
  */
 public class RegistryWrapper implements EndpointRegistry {
+
     private EndpointRegistry registry;
     private BundleContext bundleContext;
     private Map<Endpoint, ServiceRegistration> registrations = new ConcurrentHashMap();

Modified: servicemix/smx4/nmr/trunk/jbi/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/pom.xml?rev=633939&r1=633938&r2=633939&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/pom.xml (original)
+++ servicemix/smx4/nmr/trunk/jbi/pom.xml Wed Mar  5 09:23:59 2008
@@ -39,6 +39,7 @@
         <module>runtime</module>
         <module>deployer</module>
         <module>osgi</module>
+        <module>management</module>
         <module>commands</module>
         <module>itests</module>
     </modules>

Propchange: servicemix/smx4/nmr/trunk/jbi/runtime/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Wed Mar  5 09:23:59 2008
@@ -5,3 +5,4 @@
 .classpath
 .project
 .settings
+data

Modified: servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentContextImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentContextImpl.java?rev=633939&r1=633938&r2=633939&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentContextImpl.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentContextImpl.java Wed Mar  5 09:23:59 2008
@@ -435,7 +435,10 @@
         return null;
     }
 
-    
+    public Component getComponent() {
+        return component;
+    }
+
 
     protected static class SimpleServiceEndpoint implements ServiceEndpoint {
 

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=633939&r1=633938&r2=633939&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 Wed Mar  5 09:23:59 2008
@@ -29,9 +29,7 @@
 import org.apache.servicemix.jbi.runtime.ComponentRegistry;
 import org.apache.servicemix.jbi.runtime.DocumentRepository;
 import org.apache.servicemix.jbi.runtime.Environment;
-import org.apache.servicemix.jbi.runtime.impl.ManagementContext;
 import org.apache.servicemix.nmr.api.NMR;
-import org.apache.servicemix.nmr.api.ServiceMixException;
 import org.apache.servicemix.nmr.core.ServiceRegistryImpl;
 
 /**
@@ -43,12 +41,12 @@
 
     private NMR nmr;
     private DocumentRepository documentRepository;
-    private Map<String, Component> components;
+    private Map<String, ComponentContextImpl> contexts;
     private Environment environment;
     private ManagementContext managementContext;
 
     public ComponentRegistryImpl() {
-        components = new ConcurrentHashMap<String, Component>();
+        contexts = new ConcurrentHashMap<String, ComponentContextImpl>();
     }
 
     public NMR getNmr() {
@@ -89,27 +87,20 @@
      * @param component the component to register
      * @param properties the associated metadata
      */
-    public void register(Component component, Map<String, ?> properties) {
+    @Override
+    protected void doRegister(Component component, Map<String, ?> properties) throws JBIException {
+        LOGGER.info("JBI component registered with properties: " + properties);
         ClassLoader cl = Thread.currentThread().getContextClassLoader();
+        Thread.currentThread().setContextClassLoader(component.getClass().getClassLoader());
         try {
-            Thread.currentThread().setContextClassLoader(component.getClass().getClassLoader());
-            if (components.containsValue(component)) {
-                // Component is already registered
-                return;
-            }
-            if (properties == null) {
-                properties = new HashMap<String, Object>();
-            }
             String name = (String) properties.get(NAME);
-            ComponentContext context = new ComponentContextImpl(this, environment, managementContext, component, properties);
+            ComponentContextImpl context = new ComponentContextImpl(this, environment, managementContext, component, properties);
             component.getLifeCycle().init(context);
             if (name != null) {
-                components.put(name, component);
+                contexts.put(name, context);
             } else {
                 LOGGER.warn("Component has no name!");
             }
-        } catch (JBIException e) {
-            throw new ServiceMixException(e);
         } finally {
             Thread.currentThread().setContextClassLoader(cl);
         }
@@ -120,15 +111,18 @@
      *
      * @param component the component to unregister
      */
-    public void unregister(Component component, Map<String, ?> properties) {
+    @Override
+    protected void doUnregister(Component component, Map<String, ?> properties)throws JBIException {
+        LOGGER.info("JBI component unregistered with properties: " + properties);
         String name = properties != null ? (String) properties.get(NAME) : null;
         if (name != null) {
-            components.remove(name);
+            ComponentContextImpl context = contexts.remove(name);
+            context.getDeliveryChannel().close();
         }
     }
 
     public Component getComponent(String name) {
-        return components.get(name);
+        return contexts.get(name).getComponent();
     }
 
 }

Modified: servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/EndpointImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/EndpointImpl.java?rev=633939&r1=633938&r2=633939&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/EndpointImpl.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/EndpointImpl.java Wed Mar  5 09:23:59 2008
@@ -26,11 +26,6 @@
 import java.util.Queue;
 
 /**
- * Created by IntelliJ IDEA.
- * User: gnodet
- * Date: Oct 5, 2007
- * Time: 11:08:00 AM
- * To change this template use File | Settings | File Templates.
  */
 public class EndpointImpl implements Endpoint, ServiceEndpoint {
 
@@ -50,11 +45,13 @@
     }
 
     public DocumentFragment getAsReference(QName operationName) {
-        return null;  //To change body of implemented methods use File | Settings | File Templates.
+        // TODO
+        return null;
     }
 
     public QName[] getInterfaces() {
-        return new QName[0];  //To change body of implemented methods use File | Settings | File Templates.
+        // TODO
+        return new QName[0];
     }
 
     public Channel getChannel() {
@@ -87,5 +84,13 @@
 
     public void setEndpointName(String endpointName) {
         this.endpointName = endpointName;
+    }
+
+    public boolean equals(Object o) {
+        return this == o;
+    }
+
+    public int hashCode() {
+        return super.hashCode();
     }
 }

Modified: servicemix/smx4/nmr/trunk/nmr/api/src/main/java/org/apache/servicemix/nmr/api/event/EndpointListener.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/api/src/main/java/org/apache/servicemix/nmr/api/event/EndpointListener.java?rev=633939&r1=633938&r2=633939&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/api/src/main/java/org/apache/servicemix/nmr/api/event/EndpointListener.java (original)
+++ servicemix/smx4/nmr/trunk/nmr/api/src/main/java/org/apache/servicemix/nmr/api/event/EndpointListener.java Wed Mar  5 09:23:59 2008
@@ -17,6 +17,7 @@
 package org.apache.servicemix.nmr.api.event;
 
 import org.apache.servicemix.nmr.api.Endpoint;
+import org.apache.servicemix.nmr.api.internal.InternalEndpoint;
 
 
 /**
@@ -31,13 +32,13 @@
      *
      * @param endpoint the registered endpoint
      */
-    void endpointRegistered(Endpoint endpoint);
+    void endpointRegistered(InternalEndpoint endpoint);
 
     /**
      * An endpoint has been unregistered
      *
      * @param endpoint the unregistered endpoint
      */
-    void endpointUnregistered(Endpoint endpoint);
+    void endpointUnregistered(InternalEndpoint endpoint);
     
 }

Modified: servicemix/smx4/nmr/trunk/nmr/api/src/main/java/org/apache/servicemix/nmr/api/internal/InternalEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/api/src/main/java/org/apache/servicemix/nmr/api/internal/InternalEndpoint.java?rev=633939&r1=633938&r2=633939&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/api/src/main/java/org/apache/servicemix/nmr/api/internal/InternalEndpoint.java (original)
+++ servicemix/smx4/nmr/trunk/nmr/api/src/main/java/org/apache/servicemix/nmr/api/internal/InternalEndpoint.java Wed Mar  5 09:23:59 2008
@@ -19,17 +19,35 @@
 import org.apache.servicemix.nmr.api.Endpoint;
 
 /**
+ * This interface represents a wrapper around an Endpoint
+ * which is to be used internally to access the Channel.
+ *
  * @version $Revision: $
  * @since 4.0
  */
 public interface InternalEndpoint extends Endpoint {
 
     /**
+     * Retrieve the endpoint id
+     *
+     * @return the id of the endpoint
+     */
+    String getId();
+
+    /**
      * Retrieve the channel associated with this endpoint.
      * This method is usually used by {@link Flow}s to deliver
      * exchanges to this endpoint.
-     * @return
+     *
+     * @return the channel for this endpoint
      */
     InternalChannel getChannel();
+
+    /**
+     * Retrieve the inner endpoint.
+     *
+     * @return the inner endpoint
+     */
+    Endpoint getEndpoint();
 
 }

Modified: servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/ChannelImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/ChannelImpl.java?rev=633939&r1=633938&r2=633939&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/ChannelImpl.java (original)
+++ servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/ChannelImpl.java Wed Mar  5 09:23:59 2008
@@ -153,7 +153,8 @@
      * the NMR.
      */
     public void close() {
-        // TODO
+        Map<String,?> props = nmr.getEndpointRegistry().getProperties(endpoint);
+        nmr.getEndpointRegistry().unregister(endpoint, props);
     }
 
     /**
@@ -191,12 +192,12 @@
         if (exchange.getDestination() == null) {
             exchange.setDestination(endpoint);
         }
+        // Change role
+        exchange.setRole(exchange.getRole() == Role.Provider ? Role.Consumer : Role.Provider);
         // Call listeners
         for (ExchangeListener l : nmr.getListenerRegistry().getListeners(ExchangeListener.class)) {
             l.exchangeDelivered(exchange);
         }
-        // Change role
-        exchange.setRole(exchange.getRole() == Role.Provider ? Role.Consumer : Role.Provider);
         // Check if sendSync was used, in which case we need to unblock the other side
         // rather than delivering the exchange
         // TODO:

Modified: servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/ClientChannel.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/ClientChannel.java?rev=633939&r1=633938&r2=633939&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/ClientChannel.java (original)
+++ servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/ClientChannel.java Wed Mar  5 09:23:59 2008
@@ -16,9 +16,11 @@
  */
 package org.apache.servicemix.nmr.core;
 
+import java.util.UUID;
 import java.util.concurrent.Executors;
 
 import org.apache.servicemix.nmr.api.Channel;
+import org.apache.servicemix.nmr.api.Endpoint;
 import org.apache.servicemix.nmr.api.Exchange;
 import org.apache.servicemix.nmr.api.NMR;
 import org.apache.servicemix.nmr.api.internal.InternalChannel;
@@ -38,6 +40,15 @@
     protected static class ClientEndpoint implements InternalEndpoint {
 
         private InternalChannel channel;
+        private String id = UUID.randomUUID().toString(); 
+
+        public String getId() {
+            return id;
+        }
+
+        public Endpoint getEndpoint() {
+            return this;
+        }
 
         public void setChannel(Channel channel) {
             this.channel = (InternalChannel) channel;

Modified: servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/EndpointRegistryImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/EndpointRegistryImpl.java?rev=633939&r1=633938&r2=633939&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/EndpointRegistryImpl.java (original)
+++ servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/EndpointRegistryImpl.java Wed Mar  5 09:23:59 2008
@@ -22,6 +22,7 @@
 import java.util.Set;
 import java.util.WeakHashMap;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.Executor;
 import java.util.concurrent.Executors;
 
@@ -48,10 +49,10 @@
 public class EndpointRegistryImpl implements EndpointRegistry {
 
     private NMR nmr;
-    private Map<Endpoint, InternalEndpoint> endpoints = new ConcurrentHashMap<Endpoint, InternalEndpoint>();
+    private ConcurrentMap<Endpoint, InternalEndpoint> endpoints = new ConcurrentHashMap<Endpoint, InternalEndpoint>();
     private Map<InternalEndpoint, Endpoint> wrappers = new ConcurrentHashMap<InternalEndpoint, Endpoint>();
-    private ServiceRegistry<InternalEndpoint> registry = new ServiceRegistryImpl<InternalEndpoint>();
     private Map<DynamicReferenceImpl, Boolean> references = new WeakHashMap<DynamicReferenceImpl, Boolean>();
+    private ServiceRegistry<InternalEndpoint> registry;
 
     public EndpointRegistryImpl() {
     }
@@ -68,10 +69,21 @@
         this.nmr = nmr;
     }
 
+    public ServiceRegistry<InternalEndpoint> getRegistry() {
+        return registry;
+    }
+
+    public void setRegistry(ServiceRegistry<InternalEndpoint> registry) {
+        this.registry = registry;
+    }
+
     public void init() {
         if (nmr == null) {
             throw new NullPointerException("nmr must be not null");
         }
+        if (registry == null) {
+            registry = new ServiceRegistryImpl<InternalEndpoint>();
+        }
     }
 
     /**
@@ -85,18 +97,19 @@
      * @see org.apache.servicemix.nmr.api.Endpoint
      */
     public void register(Endpoint endpoint, Map<String, ?> properties) {
-        Executor executor = Executors.newCachedThreadPool();
         InternalEndpointWrapper wrapper = new InternalEndpointWrapper(endpoint);
-        ChannelImpl channel = new ChannelImpl(wrapper, executor, nmr);
-        wrapper.setChannel(channel);
-        endpoints.put(endpoint, wrapper);
-        wrappers.put(wrapper, endpoint);
-        registry.register(wrapper, properties);
-        for (EndpointListener listener : nmr.getListenerRegistry().getListeners(EndpointListener.class)) {
-            listener.endpointRegistered(endpoint);
-        }
-        for (DynamicReferenceImpl ref : references.keySet()) {
-            ref.setDirty();
+        if (endpoints.putIfAbsent(endpoint, wrapper) == null) {
+            Executor executor = Executors.newCachedThreadPool();
+            ChannelImpl channel = new ChannelImpl(wrapper, executor, nmr);
+            wrapper.setChannel(channel);
+            wrappers.put(wrapper, endpoint);
+            registry.register(wrapper, properties);
+            for (EndpointListener listener : nmr.getListenerRegistry().getListeners(EndpointListener.class)) {
+                listener.endpointRegistered(wrapper);
+            }
+            for (DynamicReferenceImpl ref : references.keySet()) {
+                ref.setDirty();
+            }
         }
     }
 
@@ -118,7 +131,7 @@
         }
         registry.unregister(wrapper, properties);
         for (EndpointListener listener : nmr.getListenerRegistry().getListeners(EndpointListener.class)) {
-            listener.endpointUnregistered(endpoint);
+            listener.endpointUnregistered(wrapper);
         }
         for (DynamicReferenceImpl ref : references.keySet()) {
             ref.setDirty();

Modified: servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/InternalEndpointWrapper.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/InternalEndpointWrapper.java?rev=633939&r1=633938&r2=633939&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/InternalEndpointWrapper.java (original)
+++ servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/InternalEndpointWrapper.java Wed Mar  5 09:23:59 2008
@@ -16,6 +16,8 @@
  */
 package org.apache.servicemix.nmr.core;
 
+import java.util.UUID;
+
 import org.apache.servicemix.nmr.api.Channel;
 import org.apache.servicemix.nmr.api.Endpoint;
 import org.apache.servicemix.nmr.api.Exchange;
@@ -28,10 +30,12 @@
 public class InternalEndpointWrapper implements InternalEndpoint {
 
     private final Endpoint endpoint;
+    private final String id;
     private InternalChannel channel;
 
     public InternalEndpointWrapper(Endpoint endpoint) {
         this.endpoint = endpoint;
+        this.id = UUID.randomUUID().toString();
     }
 
     public InternalChannel getChannel() {
@@ -42,6 +46,10 @@
         return endpoint;
     }
 
+    public String getId() {
+        return id;
+    }
+
     /**
      * Set the channel so that the endpoint can send exchanges back
      * when they are processed or act as a consumer itself.
@@ -70,4 +78,15 @@
         endpoint.process(exchange);
     }
 
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (!(o instanceof InternalEndpointWrapper)) return false;
+        InternalEndpointWrapper that = (InternalEndpointWrapper) o;
+        if (id != null ? !id.equals(that.id) : that.id != null) return false;
+        return true;
+    }
+
+    public int hashCode() {
+        return (id != null ? id.hashCode() : 0);
+    }
 }

Modified: servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/ServiceRegistryImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/ServiceRegistryImpl.java?rev=633939&r1=633938&r2=633939&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/ServiceRegistryImpl.java (original)
+++ servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/ServiceRegistryImpl.java Wed Mar  5 09:23:59 2008
@@ -16,10 +16,15 @@
  */
 package org.apache.servicemix.nmr.core;
 
+import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.nmr.api.ServiceMixException;
 import org.apache.servicemix.nmr.api.service.ServiceRegistry;
 
 /**
@@ -28,16 +33,62 @@
  */
 public class ServiceRegistryImpl<T> implements ServiceRegistry<T> {
 
-    private Map<T, Map<String, ?>> registry = new ConcurrentHashMap<T, Map<String, ?>>();
+    private ConcurrentMap<T, Map<String, ?>> registry = new ConcurrentHashMap<T, Map<String, ?>>();
+
+    private final Log logger = LogFactory.getLog(getClass());
 
     public void register(T service, Map<String, ?> properties) {
         assert service != null : "service should not be null";
-        registry.put(service, properties);
+        if (properties == null) {
+            properties = new HashMap<String, Object>();
+        }
+        if (registry.putIfAbsent(service, properties) == null) {
+            try {
+                doRegister(service, properties);
+            } catch (Exception e) {
+                logger.warn("Unable to register service " +
+                        service + " with properties " + properties + ". Reason: " + e, e);
+                registry.remove(service);
+                throw new ServiceMixException("Unable to register service " +
+                        service + " with properties " + properties + ". Reason: " + e, e);
+            }
+        }
+    }
+
+    /**
+     * Placeholder to perform any registry specific operation
+     * when a new service is registered.
+     *
+     * @param service
+     * @param properties
+     * @throws Exception
+     */
+    protected void doRegister(T service, Map<String, ?> properties) throws Exception {
     }
 
     public void unregister(T service, Map<String, ?> properties) {
         assert service != null : "service should not be null";
-        registry.remove(service);
+        if (registry.remove(service) != null) {
+            try {
+                doUnregister(service, properties);
+            } catch (Exception e) {
+                logger.warn("Unable to unregister service " +
+                        service + " with properties " + properties + ". Reason: " + e, e);
+                throw new ServiceMixException("Unable to unregister service " + 
+                        service + " with properties " + properties + ". Reason: " + e, e);
+            }
+        }
+    }
+
+    /**
+     * Placeholder to perform any registry specific operation
+     * when a service is unregistered.
+     *
+     * @param service
+     * @param properties
+     * @throws Exception
+     */
+    protected void doUnregister(T service, Map<String, ?> properties) throws Exception {
     }
 
     public Set<T> getServices() {

Modified: servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/EndpointRegistryImplTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/EndpointRegistryImplTest.java?rev=633939&r1=633938&r2=633939&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/EndpointRegistryImplTest.java (original)
+++ servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/EndpointRegistryImplTest.java Wed Mar  5 09:23:59 2008
@@ -26,11 +26,13 @@
 import org.apache.servicemix.nmr.api.Exchange;
 import org.apache.servicemix.nmr.api.NMR;
 import org.apache.servicemix.nmr.api.Reference;
+import org.apache.servicemix.nmr.api.internal.InternalEndpoint;
 import org.apache.servicemix.nmr.api.event.EndpointListener;
 import org.apache.servicemix.nmr.api.service.ServiceHelper;
 import static org.junit.Assert.*;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.Ignore;
 
 public class EndpointRegistryImplTest {
 
@@ -79,6 +81,8 @@
 
     @Test
     public void testLdapFilter() throws Exception {
+        System.setProperty("org.osgi.vendor.framework", "org.apache.servicemix.nmr.core");
+
         Endpoint endpoint = new DummyEndpoint();
         Reference ref = registry.lookup("(NAME=id)");
         assertNotNull(ref);
@@ -100,10 +104,10 @@
         final CountDownLatch unregLatch = new CountDownLatch(1);
         Endpoint endpoint = new DummyEndpoint();
         nmr.getListenerRegistry().register(new EndpointListener() {
-            public void endpointRegistered(Endpoint endpoint) {
+            public void endpointRegistered(InternalEndpoint endpoint) {
                 regLatch.countDown();
             }
-            public void endpointUnregistered(Endpoint endpoint) {
+            public void endpointUnregistered(InternalEndpoint endpoint) {
                 unregLatch.countDown();
             }
         }, new HashMap<String,Object>());

Added: servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/FrameworkUtil.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/FrameworkUtil.java?rev=633939&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/FrameworkUtil.java (added)
+++ servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/FrameworkUtil.java Wed Mar  5 09:23:59 2008
@@ -0,0 +1,31 @@
+/*
+ * 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 org.apache.felix.framework.FilterImpl;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+
+/**
+ */
+public class FrameworkUtil {
+
+    public static Filter createFilter(String f) throws InvalidSyntaxException {
+        return new FilterImpl(f);
+    }
+
+}

Propchange: servicemix/smx4/nmr/trunk/nmr/management/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Wed Mar  5 09:23:59 2008
@@ -0,0 +1,7 @@
+target
+*.iml
+*.ipr
+*.iws
+.classpath
+.project
+.settings

Added: servicemix/smx4/nmr/trunk/nmr/management/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/management/pom.xml?rev=633939&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/management/pom.xml (added)
+++ servicemix/smx4/nmr/trunk/nmr/management/pom.xml Wed Mar  5 09:23:59 2008
@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <!--
+
+        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.
+    -->
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.servicemix.nmr</groupId>
+        <artifactId>nmr</artifactId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+
+    <groupId>org.apache.servicemix.nmr</groupId>
+    <artifactId>org.apache.servicemix.nmr.management</artifactId>
+    <packaging>bundle</packaging>
+    <name>ServiceMix NMR Management</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.servicemix.nmr</groupId>
+            <artifactId>org.apache.servicemix.nmr.api</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.servicemix.nmr</groupId>
+            <artifactId>org.apache.servicemix.nmr.core</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.servicemix.nmr</groupId>
+            <artifactId>org.apache.servicemix.nmr.spring</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.osgi</groupId>
+            <artifactId>spring-osgi-core</artifactId>
+            <version>${spring.osgi.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <version>${felix.osgi.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>${junit.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>commons-logging</groupId>
+            <artifactId>commons-logging</artifactId>
+            <version>${commons.logging.version}</version>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <configuration>
+                    <instructions>
+                        <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
+                        <Import-Package>*</Import-Package>
+                        <Export-Package>${pom.artifactId}*;version=${pom.version}</Export-Package>
+                        <Spring-Context>*;publish-context:=false;create-asynchronously:=true</Spring-Context>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>

Added: 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=633939&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/management/src/main/java/org/apache/servicemix/nmr/management/DefaultNamingStrategy.java (added)
+++ servicemix/smx4/nmr/trunk/nmr/management/src/main/java/org/apache/servicemix/nmr/management/DefaultNamingStrategy.java Wed Mar  5 09:23:59 2008
@@ -0,0 +1,60 @@
+/*
+ * 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.management;
+
+import javax.management.ObjectName;
+import javax.management.MalformedObjectNameException;
+
+import org.apache.servicemix.nmr.api.Endpoint;
+
+/**
+ */
+public class DefaultNamingStrategy implements NamingStrategy {
+
+    private String jmxDomainName;
+
+    public String getJmxDomainName() {
+        return jmxDomainName;
+    }
+
+    public void setJmxDomainName(String jmxDomainName) {
+        this.jmxDomainName = jmxDomainName;
+    }
+
+    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();
+    }
+
+    private String sanitize(String in) {
+        String result = null;
+        if (in != null) {
+            result = in.replace(':', '_');
+            result = result.replace('/', '_');
+            result = result.replace('\\', '_');
+            result = result.replace('?', '_');
+            result = result.replace('=', '_');
+            result = result.replace(',', '_');
+        }
+        return result;
+    }
+
+}
+



Mime
View raw message