Author: gertv
Date: Wed Feb 18 22:43:54 2009
New Revision: 745680

URL: http://svn.apache.org/viewvc?rev=745680&view=rev
Log:
SMX4NMR-20: create a separate WireRegistry and make it OSGi-aware

Added:
    
servicemix/smx4/nmr/trunk/nmr/api/src/main/java/org/apache/servicemix/nmr/api/WireRegistry.java
    
servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/WireRegistryImpl.java
    
servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/ServiceMixTest.java
    
servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/WireRegistryImplTest.java
Modified:
    servicemix/smx4/nmr/trunk/branding/   (props changed)
    
servicemix/smx4/nmr/trunk/jbi/osgi/src/main/java/org/apache/servicemix/jbi/osgi/NMRWrapper.java
    
servicemix/smx4/nmr/trunk/jbi/osgi/src/main/java/org/apache/servicemix/jbi/osgi/RegistryWrapper.java
    
servicemix/smx4/nmr/trunk/nmr/api/src/main/java/org/apache/servicemix/nmr/api/EndpointRegistry.java
    
servicemix/smx4/nmr/trunk/nmr/api/src/main/java/org/apache/servicemix/nmr/api/NMR.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/ServiceMix.java
    
servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/EndpointRegistryImplTest.java
    
servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/IntegrationTest.java
    
servicemix/smx4/nmr/trunk/nmr/osgi/src/main/resources/META-INF/spring/servicemix-nmr.xml

Propchange: servicemix/smx4/nmr/trunk/branding/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Wed Feb 18 22:43:54 2009
@@ -0,0 +1,5 @@
+eclipse-classes
+.classpath
+.project
+.settings
+target

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=745680&r1=745679&r2=745680&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
 Wed Feb 18 22:43:54 2009
@@ -19,6 +19,7 @@
 import org.apache.servicemix.nmr.api.Channel;
 import org.apache.servicemix.nmr.api.EndpointRegistry;
 import org.apache.servicemix.nmr.api.NMR;
+import org.apache.servicemix.nmr.api.WireRegistry;
 import org.apache.servicemix.nmr.api.event.ListenerRegistry;
 import org.apache.servicemix.nmr.api.internal.FlowRegistry;
 import org.osgi.framework.BundleContext;
@@ -66,6 +67,10 @@
     public FlowRegistry getFlowRegistry() {
         return nmr.getFlowRegistry();
     }
+    
+    public WireRegistry getWireRegistry() {
+        return nmr.getWireRegistry();
+    }
 
     public Channel createChannel() {
         return nmr.createChannel();

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=745680&r1=745679&r2=745680&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 Feb 18 22:43:54 2009
@@ -94,13 +94,5 @@
 
     public Set<Endpoint> getServices() {
         return registry.getServices();
-    }
-    
-    public void register(Wire wire) {
-        registry.register(wire);
-    }
-    
-    public void unregister(Wire wire) {
-        registry.unregister(wire);
-    }
+    }    
 }

Modified: 
servicemix/smx4/nmr/trunk/nmr/api/src/main/java/org/apache/servicemix/nmr/api/EndpointRegistry.java
URL: 
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/api/src/main/java/org/apache/servicemix/nmr/api/EndpointRegistry.java?rev=745680&r1=745679&r2=745680&view=diff
==============================================================================
--- 
servicemix/smx4/nmr/trunk/nmr/api/src/main/java/org/apache/servicemix/nmr/api/EndpointRegistry.java
 (original)
+++ 
servicemix/smx4/nmr/trunk/nmr/api/src/main/java/org/apache/servicemix/nmr/api/EndpointRegistry.java
 Wed Feb 18 22:43:54 2009
@@ -89,20 +89,5 @@
      */
     Reference lookup(String filter);
 
-    /**
-     * Register a {...@link Wire}.  This will allow you to access an existing 
endpoint through the wire's from address as well.
-     * 
-     * @param wire the wire to be registered 
-     */
-    void register(Wire wire);
-    
-    /**
-     * Unregister an existing {...@link Wire} from the registry.  After 
calling this method, the registry will no longer take the
-     * wire into account when resolving endpoints.
-     * 
-     * @param wire the wire to be unregistered
-     */
-    void unregister(Wire wire);
-
 }
 

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=745680&r1=745679&r2=745680&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
 Wed Feb 18 22:43:54 2009
@@ -49,6 +49,13 @@
      * @return the flow registry
      */
     FlowRegistry getFlowRegistry();
+    
+    /**
+     * Access the wire registry
+     * 
+     * @return the wire registry
+     */
+    WireRegistry getWireRegistry();
 
     /**
      * Create a channel to interact with the NMR without exposing an endpoint.

Added: 
servicemix/smx4/nmr/trunk/nmr/api/src/main/java/org/apache/servicemix/nmr/api/WireRegistry.java
URL: 
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/api/src/main/java/org/apache/servicemix/nmr/api/WireRegistry.java?rev=745680&view=auto
==============================================================================
--- 
servicemix/smx4/nmr/trunk/nmr/api/src/main/java/org/apache/servicemix/nmr/api/WireRegistry.java
 (added)
+++ 
servicemix/smx4/nmr/trunk/nmr/api/src/main/java/org/apache/servicemix/nmr/api/WireRegistry.java
 Wed Feb 18 22:43:54 2009
@@ -0,0 +1,26 @@
+/*
+ * 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.api;
+
+import org.apache.servicemix.nmr.api.service.ServiceRegistry;
+
+/**
+ * This registry is used to register/unregister {...@link Wire}s.
+ */
+public interface WireRegistry extends ServiceRegistry<Wire> {
+    
+}

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=745680&r1=745679&r2=745680&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 Feb 18 22:43:54 2009
@@ -202,9 +202,9 @@
      */
     protected Map<String, ?> handleWiring(Map<String, ?> properties) {
         //check for wires on this Map
-        for (Map<String, ?> key : wires.keySet()) {
-            if (ServiceHelper.equals(properties, key)) {
-                return wires.get(key).getTo();
+        for (Wire wire : nmr.getWireRegistry().getServices()) {
+            if (ServiceHelper.equals(properties, wire.getFrom())) {
+                return wire.getTo();
             }
         }
         //no wires registered, just returning the Map itself 

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=745680&r1=745679&r2=745680&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
 Wed Feb 18 22:43:54 2009
@@ -19,6 +19,7 @@
 import org.apache.servicemix.nmr.api.Channel;
 import org.apache.servicemix.nmr.api.EndpointRegistry;
 import org.apache.servicemix.nmr.api.NMR;
+import org.apache.servicemix.nmr.api.WireRegistry;
 import org.apache.servicemix.nmr.api.event.ListenerRegistry;
 import org.apache.servicemix.nmr.api.internal.Flow;
 import org.apache.servicemix.nmr.api.internal.FlowRegistry;
@@ -32,6 +33,7 @@
     private EndpointRegistry endpoints;
     private ListenerRegistry listeners;
     private FlowRegistry flows;
+    private WireRegistry wires;
 
     /**
      * Initialize ServiceMix
@@ -49,7 +51,9 @@
             flows = new FlowRegistryImpl();
             flows.register(new StraightThroughFlow(), 
ServiceHelper.createMap(Flow.ID, StraightThroughFlow.class.getName()));
         }
-
+        if (wires == null) {
+            wires = new WireRegistryImpl();
+        }
     }
 
     /**
@@ -114,4 +118,20 @@
     public Channel createChannel() {
         return new ClientChannel(this);
     }
+
+    /**
+     * {...@inheritdoc}
+     */
+    public WireRegistry getWireRegistry() {
+        return wires;
+    }
+
+    /**
+     * Set the wire registry
+     * 
+     * @param wires the wire registry
+     */
+    public void setWireRegistry(WireRegistry wires) {
+        this.wires = wires;
+    }
 }

Added: 
servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/WireRegistryImpl.java
URL: 
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/WireRegistryImpl.java?rev=745680&view=auto
==============================================================================
--- 
servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/WireRegistryImpl.java
 (added)
+++ 
servicemix/smx4/nmr/trunk/nmr/core/src/main/java/org/apache/servicemix/nmr/core/WireRegistryImpl.java
 Wed Feb 18 22:43:54 2009
@@ -0,0 +1,27 @@
+/*
+ * 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.servicemix.nmr.api.Wire;
+import org.apache.servicemix.nmr.api.WireRegistry;
+
+/**
+ * Default implementation for a {...@link WireRegistry}
+ */
+public class WireRegistryImpl extends ServiceRegistryImpl<Wire> implements 
WireRegistry {
+
+}

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=745680&r1=745679&r2=745680&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 Feb 18 22:43:54 2009
@@ -166,7 +166,7 @@
     private Endpoint createWiredEndpoint(Map<String, Object> from, Map<String, 
Object> to) {
         final Endpoint endpoint = new DummyEndpoint();
         registry.register(endpoint, to);
-        registry.register(ServiceHelper.createWire(from, to));
+        nmr.getWireRegistry().register(ServiceHelper.createWire(from, to), 
null);
         return endpoint;
     }
 

Modified: 
servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/IntegrationTest.java
URL: 
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/IntegrationTest.java?rev=745680&r1=745679&r2=745680&view=diff
==============================================================================
--- 
servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/IntegrationTest.java
 (original)
+++ 
servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/IntegrationTest.java
 Wed Feb 18 22:43:54 2009
@@ -60,7 +60,7 @@
         Map<String, Object> wire = ServiceHelper.createMap(Endpoint.NAME, 
"wire");
         //register the endpoint and a wire to the endpoint
         nmr.getEndpointRegistry().register(endpoint, target);
-        nmr.getEndpointRegistry().register(ServiceHelper.createWire(wire, 
target));
+        nmr.getWireRegistry().register(ServiceHelper.createWire(wire, target), 
null);
         
         Channel client = nmr.createChannel();
         Exchange e = client.createExchange(Pattern.InOnly);

Added: 
servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/ServiceMixTest.java
URL: 
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/ServiceMixTest.java?rev=745680&view=auto
==============================================================================
--- 
servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/ServiceMixTest.java
 (added)
+++ 
servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/ServiceMixTest.java
 Wed Feb 18 22:43:54 2009
@@ -0,0 +1,47 @@
+/*
+ * 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.servicemix.nmr.api.WireRegistry;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ * Test cases for {...@link ServiceMix}
+ */
+public class ServiceMixTest {
+    
+    @Test
+    public void testInit() {
+        ServiceMix servicemix = new ServiceMix();
+        servicemix.init();
+        assertNotNull(servicemix.getEndpointRegistry());
+        assertNotNull(servicemix.getFlowRegistry());
+        assertNotNull(servicemix.getListenerRegistry());
+        assertNotNull(servicemix.getWireRegistry());
+    }
+    
+    @Test
+    public void testSetWireRegistry() {
+        ServiceMix servicemix = new ServiceMix();
+        WireRegistry registry = new WireRegistryImpl();
+        servicemix.setWireRegistry(registry);
+        servicemix.init();
+        assertSame("Should use the registry that was set instead of creating a 
new now",
+                   registry, servicemix.getWireRegistry());
+    }
+}

Added: 
servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/WireRegistryImplTest.java
URL: 
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/WireRegistryImplTest.java?rev=745680&view=auto
==============================================================================
--- 
servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/WireRegistryImplTest.java
 (added)
+++ 
servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/WireRegistryImplTest.java
 Wed Feb 18 22:43:54 2009
@@ -0,0 +1,58 @@
+/*
+ * 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.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.servicemix.nmr.api.Wire;
+import org.apache.servicemix.nmr.api.WireRegistry;
+
+/**
+ * Test cases for {...@link WireRegistryImpl}
+ */
+public class WireRegistryImplTest extends TestCase {
+    
+    public void testBasicRegistryBehavior() {
+        Wire wire = new MockWire();
+        Map<String, Object> properties = new HashMap<String, Object>();
+        properties.put("wire-length", 12);
+        properties.put("wire-type", "coton");
+        
+        WireRegistry registry = new WireRegistryImpl();
+        registry.register(wire, properties);
+        assertEquals(1, registry.getServices().size());
+        assertEquals(properties, registry.getProperties(wire));
+        
+        registry.unregister(wire, properties);
+        assertEquals(0, registry.getServices().size());
+        assertEquals(null, registry.getProperties(wire));
+    }
+    
+    private static final class MockWire implements Wire {
+
+        public Map<String, ?> getFrom() {
+            return null;
+        }
+
+        public Map<String, ?> getTo() {
+            return null;
+        }
+    }
+}

Modified: 
servicemix/smx4/nmr/trunk/nmr/osgi/src/main/resources/META-INF/spring/servicemix-nmr.xml
URL: 
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/osgi/src/main/resources/META-INF/spring/servicemix-nmr.xml?rev=745680&r1=745679&r2=745680&view=diff
==============================================================================
--- 
servicemix/smx4/nmr/trunk/nmr/osgi/src/main/resources/META-INF/spring/servicemix-nmr.xml
 (original)
+++ 
servicemix/smx4/nmr/trunk/nmr/osgi/src/main/resources/META-INF/spring/servicemix-nmr.xml
 Wed Feb 18 22:43:54 2009
@@ -34,6 +34,7 @@
         <property name="endpointRegistry" ref="endpointRegistry" />
         <property name="listenerRegistry" ref="listenerRegistry" />
         <property name="flowRegistry" ref="flowRegistry" />
+        <property name="wireRegistry" ref="wireRegistry" />
     </bean>
     <osgi:service ref="servicemix">
         <osgi:interfaces>
@@ -76,6 +77,14 @@
                cardinality="0..N">
         <osgi:listener ref="endpointRegistry" bind-method="register" 
unbind-method="unregister" />
     </osgi:list>
+    
+    <!-- Wire registry and service tracker -->
+    <bean id="wireRegistry" 
class="org.apache.servicemix.nmr.core.WireRegistryImpl"/>
+    <osgi:list id="wires"
+               interface="org.apache.servicemix.nmr.api.Wire"
+               cardinality="0..N">
+        <osgi:listener ref="wireRegistry" bind-method="register" 
unbind-method="unregister" />
+    </osgi:list>
 
     <!-- AuthorizationService -->
     <bean id="authorizationService" 
class="org.apache.servicemix.nmr.core.security.DefaultAuthorizationService" />


Reply via email to