servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r468001 - in /incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi: framework/EndpointRegistry.java servicedesc/EndpointSupport.java view/DotViewEndpointListener.java view/DotViewFlowListener.java
Date Thu, 26 Oct 2006 13:47:22 GMT
Author: gnodet
Date: Thu Oct 26 06:47:21 2006
New Revision: 468001

URL: http://svn.apache.org/viewvc?view=rev&rev=468001
Log:
Ensure that external / internal endpoints can be separated on the flow graph

Modified:
    incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/EndpointRegistry.java
    incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/servicedesc/EndpointSupport.java
    incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/view/DotViewEndpointListener.java
    incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/view/DotViewFlowListener.java

Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/EndpointRegistry.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/EndpointRegistry.java?view=diff&rev=468001&r1=468000&r2=468001
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/EndpointRegistry.java
(original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/EndpointRegistry.java
Thu Oct 26 06:47:21 2006
@@ -98,6 +98,23 @@
         return asEndpointArray(endpoints);
     }
     
+    public ServiceEndpoint[] getAllEndpointsForComponent(ComponentNameSpace cns) {
+        Collection endpoints = new ArrayList();
+        for (Iterator iter = getInternalEndpoints().iterator(); iter.hasNext();) {
+            InternalEndpoint endpoint = (InternalEndpoint) iter.next();
+            if (cns.equals(endpoint.getComponentNameSpace())) {
+                endpoints.add(endpoint);
+            }
+        }
+        for (Iterator iter = getExternalEndpoints().iterator(); iter.hasNext();) {
+            ExternalEndpoint endpoint = (ExternalEndpoint) iter.next();
+            if (cns.equals(endpoint.getComponentNameSpace())) {
+                endpoints.add(endpoint);
+            }
+        }
+        return asEndpointArray(endpoints);
+    }
+    
     /**
      * Returns a collection of Endpoint objects
      */

Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/servicedesc/EndpointSupport.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/servicedesc/EndpointSupport.java?view=diff&rev=468001&r1=468000&r2=468001
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/servicedesc/EndpointSupport.java
(original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/servicedesc/EndpointSupport.java
Thu Oct 26 06:47:21 2006
@@ -37,4 +37,18 @@
         return getKey(endpoint.getServiceName(), endpoint.getEndpointName());
     }
     
+    public static String getUniqueKey(ServiceEndpoint endpoint) {
+        if (endpoint instanceof InternalEndpoint) {
+            return "internal:" + getKey(endpoint);
+        } else if (endpoint instanceof ExternalEndpoint) {
+            return "external:" + getKey(endpoint);
+        } else if (endpoint instanceof DynamicEndpoint) {
+            return "dynamic:" + getKey(endpoint);
+        } else if (endpoint instanceof LinkedEndpoint) {
+            return "linked:" + getKey(endpoint);
+        } else {
+            return endpoint.getClass().getName() + ":" + getKey(endpoint);
+        }
+    }
+    
 }

Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/view/DotViewEndpointListener.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/view/DotViewEndpointListener.java?view=diff&rev=468001&r1=468000&r2=468001
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/view/DotViewEndpointListener.java
(original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/view/DotViewEndpointListener.java
Thu Oct 26 06:47:21 2006
@@ -115,12 +115,15 @@
         Collection endpointMBeans = registry.getEndpointRegistry().getEndpointMBeans();
         for (Iterator iter = endpointMBeans.iterator(); iter.hasNext();) {
             Endpoint endpoint = (Endpoint) iter.next();
-            String name = endpoint.getEndpointName();
+            String key = endpoint.getSubType().toLowerCase() + ":{" + 
+                                endpoint.getServiceName().getNamespaceURI() + "}" + 
+                                endpoint.getServiceName().getLocalPart() + ":" + 
+                                endpoint.getEndpointName(); 
             String componentName = encode(endpoint.getComponentName());
-            String id = encode(name);
+            String id = encode(key);
             writer.print(id);
             writer.print(" [ label=\"");
-            writer.print(name);
+            writer.print(formatEndpoint(key));
             writer.println("\" ];");
             
             componentEndpointLinks.add(componentName + " -> " + id);
@@ -128,6 +131,21 @@
         generateLinks(writer, componentEndpointLinks);
         
         writer.println("}");
+    }
+
+    protected String formatEndpoint(String key) {
+        int i1 = key.indexOf('{');
+        int i2 = key.indexOf('}');
+        int i3 = key.indexOf(':', i2);
+        String type = key.charAt(i1 - 1) == ':' ? key.substring(0, i1 - 1) : null;
+        String uri = key.substring(i1 + 1, i2);
+        String svc = key.substring(i2 + 1, i3);
+        String ep = key.substring(i3 + 1);
+        if (type != null) {
+            return type + "\\n" + uri + "\\n" + svc + "\\n" + ep;
+        } else {
+            return uri + "\\n" + svc + "\\n" + ep;
+        }
     }
 
     protected void generateLinks(PrintWriter writer, Collection lines, String style) {

Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/view/DotViewFlowListener.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/view/DotViewFlowListener.java?view=diff&rev=468001&r1=468000&r2=468001
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/view/DotViewFlowListener.java
(original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/view/DotViewFlowListener.java
Thu Oct 26 06:47:21 2006
@@ -55,6 +55,7 @@
 
     private Map flow;
     private Set flowLinks;
+    private boolean displayComponents;
     
     public DotViewFlowListener() {
         setFile("ServiceMixFlow.dot");
@@ -77,24 +78,31 @@
         Collection components = registry.getComponents();
         for (Iterator iter = components.iterator(); iter.hasNext();) {
             ComponentMBeanImpl component = (ComponentMBeanImpl) iter.next();
-            ServiceEndpoint[] ses = registry.getEndpointsForComponent(component.getComponentNameSpace());
-
+            ServiceEndpoint[] ses = registry.getEndpointRegistry().getAllEndpointsForComponent(component.getComponentNameSpace());
             String name = component.getName();
-            String id = encode(name);
-
-            writer.println("subgraph cluster_" + id + " {");
-            writer.println("  label=\"" + name + "\";");
-            writer.println("  node [fillcolor = green];");
-            writer.println("  " + id + " [label=\"" + name + "\"];");
-            writer.println("  node [fillcolor = red];");
-            
+            // If we want to display components, create
+            // a sub graph, grouping all the components
+            // endpoints
+            if (isDisplayComponents()) {
+                String id = encode(name);
+                writer.println("subgraph cluster_" + id + " {");
+                writer.println("  label=\"" + name + "\";");
+                writer.println("  node [fillcolor = green];");
+                writer.println("  " + id + " [label=\"" + name + "\"];");
+                writer.println("  node [fillcolor = red];");
+            }
             for (int i = 0; i < ses.length; i++) {
-                String epname = EndpointSupport.getKey(ses[i]);
-                String epid = encode(epname);
+                String key = EndpointSupport.getUniqueKey(ses[i]);
+                String epname = formatEndpoint(key);
+                if (!isDisplayComponents()) {
+                    epname += "\\n" + name;
+                }
+                String epid = encode(key);
                 writer.println("  " + epid + " [label=\"" + epname + "\"];");
             }
-            
-            writer.println("}");
+            if (isDisplayComponents()) {
+                writer.println("}");
+            }
         }
         writer.println();
         generateLinks(writer, brokerLinks);
@@ -104,9 +112,8 @@
         generateLinks(writer, flowLinks);
         
         writer.println("}");
-        
     }
-
+    
     public void exchangeSent(ExchangeEvent event) {
         MessageExchange me = event.getExchange();
         if (me.getEndpoint() != null &&
@@ -115,41 +122,49 @@
             String source = (String) me.getProperty(JbiConstants.SENDER_ENDPOINT);
             if (source == null) {
                 source = mei.getSourceId().getName();
+            } else {
+                ServiceEndpoint[] ses = getContainer().getRegistry().getEndpointRegistry().getAllEndpointsForComponent(mei.getSourceId());
+                for (int i = 0; i < ses.length; i++) {
+                    if (EndpointSupport.getKey(ses[i]).equals(source)) {
+                        source = EndpointSupport.getUniqueKey(ses[i]);
+                        break;
+                    }
+                }
             }
-            String dest = EndpointSupport.getKey(mei.getEndpoint());
-            Map componentFlow = (Map) flow.get(source);
+            String dest = EndpointSupport.getUniqueKey(mei.getEndpoint());
+            Map componentFlow = createSource(source);
             if (componentFlow.put(dest, Boolean.TRUE) == null) {
                 flowLinks.add(encode(source) + " -> " + encode(dest));
                 viewIsDirty(mei.getEndpoint());
             }
         }
-        
     }
     
-    protected void createSource(String name) {
+    protected Map createSource(String name) {
         synchronized (flow) {
             Map componentFlow = (Map) flow.get(name);
             if (componentFlow == null) {
                 componentFlow = new ConcurrentHashMap();
                 flow.put(name, componentFlow);
             }
+            return componentFlow;
         }
     }
 
     public void internalEndpointRegistered(EndpointEvent event) {
-        String key = EndpointSupport.getKey(event.getEndpoint());
+        String key = EndpointSupport.getUniqueKey(event.getEndpoint());
         createSource(key);
         super.internalEndpointRegistered(event);
     }
     
     public void externalEndpointRegistered(EndpointEvent event) {
-        String key = EndpointSupport.getKey(event.getEndpoint());
+        String key = EndpointSupport.getUniqueKey(event.getEndpoint());
         createSource(key);
         super.externalEndpointRegistered(event);
     }
     
     public void linkedEndpointRegistered(EndpointEvent event) {
-        String key = EndpointSupport.getKey(event.getEndpoint());
+        String key = EndpointSupport.getUniqueKey(event.getEndpoint());
         createSource(key);
         super.linkedEndpointRegistered(event);
     }
@@ -169,6 +184,14 @@
     }
 
     public void componentUninstalled(ComponentEvent event) {
+    }
+
+    public boolean isDisplayComponents() {
+        return displayComponents;
+    }
+
+    public void setDisplayComponents(boolean displayComponents) {
+        this.displayComponents = displayComponents;
     }
 
 }



Mime
View raw message