You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2007/12/20 09:26:32 UTC

svn commit: r605831 - in /servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime: ComponentRegistry.java impl/ComponentContextImpl.java impl/ComponentRegistryImpl.java

Author: gnodet
Date: Thu Dec 20 00:26:31 2007
New Revision: 605831

URL: http://svn.apache.org/viewvc?rev=605831&view=rev
Log:
Add a getComponent method on the ComponentRegistry

Modified:
    servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/ComponentRegistry.java
    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

Modified: servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/ComponentRegistry.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/ComponentRegistry.java?rev=605831&r1=605830&r2=605831&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/ComponentRegistry.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/ComponentRegistry.java Thu Dec 20 00:26:31 2007
@@ -28,4 +28,14 @@
  */
 public interface ComponentRegistry extends ServiceRegistry<Component>  {
 
+    public static final String NAME = "NAME";
+    public static final String TYPE = "TYPE";
+
+    /**
+     * Retrieve a component given its name
+     * @param name the name of the component
+     * @return the component, or null if not registered
+     */
+    Component getComponent(String name);
+
 }

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=605831&r1=605830&r2=605831&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 Thu Dec 20 00:26:31 2007
@@ -39,6 +39,7 @@
 import org.w3c.dom.Document;
 import org.w3c.dom.DocumentFragment;
 
+import org.apache.servicemix.jbi.runtime.ComponentRegistry;
 import org.apache.servicemix.nmr.api.Endpoint;
 import org.apache.servicemix.nmr.api.Exchange;
 import org.apache.servicemix.nmr.api.NMR;
@@ -61,11 +62,9 @@
     private DeliveryChannel dc;
     private List<EndpointImpl> endpoints;
     private EndpointImpl componentEndpoint;
+    private String name;
 
     public ComponentContextImpl(NMR nmr, Component component, Map<String,?> properties) {
-        if (properties == null) {
-            properties = new HashMap<String, Object>();
-        }
         this.nmr = nmr;
         this.component = component;
         this.properties = properties;
@@ -75,6 +74,7 @@
         this.componentEndpoint.setQueue(queue);
         this.nmr.getEndpointRegistry().register(componentEndpoint, properties);
         this.dc = new DeliveryChannelImpl(this, componentEndpoint.getChannel(), queue);
+        this.name = (String) properties.get(ComponentRegistry.NAME);
     }
 
     public NMR getNmr() {
@@ -113,7 +113,7 @@
     }
 
     public String getComponentName() {
-        return null;  //To change body of implemented methods use File | Settings | File Templates.
+        return name;
     }
 
     public DeliveryChannel getDeliveryChannel() throws MessagingException {

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=605831&r1=605830&r2=605831&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 Thu Dec 20 00:26:31 2007
@@ -16,15 +16,18 @@
  */
 package org.apache.servicemix.jbi.runtime.impl;
 
-import org.apache.servicemix.nmr.api.NMR;
-import org.apache.servicemix.nmr.api.ServiceMixException;
-import org.apache.servicemix.nmr.core.ServiceRegistryImpl;
-import org.apache.servicemix.jbi.runtime.ComponentRegistry;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.concurrent.ConcurrentHashMap;
 
 import javax.jbi.JBIException;
 import javax.jbi.component.Component;
 import javax.jbi.component.ComponentContext;
-import java.util.Map;
+
+import org.apache.servicemix.jbi.runtime.ComponentRegistry;
+import org.apache.servicemix.nmr.api.NMR;
+import org.apache.servicemix.nmr.api.ServiceMixException;
+import org.apache.servicemix.nmr.core.ServiceRegistryImpl;
 
 /**
  * Created by IntelliJ IDEA.
@@ -36,6 +39,19 @@
 public class ComponentRegistryImpl extends ServiceRegistryImpl<Component>  implements ComponentRegistry {
 
     private NMR nmr;
+    private Map<String, Component> components;
+
+    public ComponentRegistryImpl() {
+        components = new ConcurrentHashMap<String, Component>();
+    }
+
+    public NMR getNmr() {
+        return nmr;
+    }
+
+    public void setNmr(NMR nmr) {
+        this.nmr = nmr;
+    }
 
     /**
      * Register a service with the given metadata.
@@ -45,9 +61,18 @@
      */
     public void register(Component component, Map<String, ?> properties) {
         try {
+            if (properties == null) {
+                properties = new HashMap<String, Object>();
+            }
+            String name = (String) properties.get(NAME);
             ComponentContext context = new ComponentContextImpl(nmr, component, properties);
             component.getLifeCycle().init(context);
             component.getLifeCycle().start();
+            if (name != null) {
+                components.put(name, component);
+            } else {
+                // TODO: log a warning
+            }
         } catch (JBIException e) {
             throw new ServiceMixException(e);
         }
@@ -62,16 +87,16 @@
         try {
             component.getLifeCycle().stop();
             component.getLifeCycle().shutDown();
+            String name = properties != null ? (String) properties.get(NAME) : null;
+            if (name != null) {
+                components.remove(name);
+            }
         } catch (JBIException e) {
             throw new ServiceMixException(e);
         }
     }
 
-    public NMR getNmr() {
-        return nmr;
-    }
-
-    public void setNmr(NMR nmr) {
-        this.nmr = nmr;
+    public Component getComponent(String name) {
+        return components.get(name);
     }
 }