servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r394610 - in /incubator/servicemix/trunk: servicemix-core/src/main/java/org/apache/servicemix/jbi/view/ servicemix-eip/src/test/java/org/apache/servicemix/eip/ servicemix-eip/src/test/resources/org/apache/servicemix/eip/
Date Mon, 17 Apr 2006 05:36:51 GMT
Author: gnodet
Date: Sun Apr 16 22:36:49 2006
New Revision: 394610

URL: http://svn.apache.org/viewcvs?rev=394610&view=rev
Log:
Add a visualization listener drawing message exchange flows.

Added:
    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/view/DotViewEndpointListener.java
    incubator/servicemix/trunk/servicemix-eip/src/test/java/org/apache/servicemix/eip/SpringConfigurationTest.java
    incubator/servicemix/trunk/servicemix-eip/src/test/resources/org/apache/servicemix/eip/spring.xml

Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/view/DotViewEndpointListener.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/view/DotViewEndpointListener.java?rev=394610&r1=394609&r2=394610&view=diff
==============================================================================
--- 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
Sun Apr 16 22:36:49 2006
@@ -130,12 +130,19 @@
         writer.println("}");
     }
 
-    protected void generateLinks(PrintWriter writer, List lines) {
+    protected void generateLinks(PrintWriter writer, Collection lines, String style) {
         for (Iterator iter = lines.iterator(); iter.hasNext();) {
             writer.print(iter.next().toString());
+            if (style != null) {
+                writer.print(" [" + style + "]");
+            }
             writer.println(";");
         }
         writer.println();
+    }
+
+    protected void generateLinks(PrintWriter writer, Collection lines) {
+        generateLinks(writer, lines, null);
     }
 
     /**

Added: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/view/DotViewFlowListener.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/view/DotViewFlowListener.java?rev=394610&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/view/DotViewFlowListener.java
(added)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/view/DotViewFlowListener.java
Sun Apr 16 22:36:49 2006
@@ -0,0 +1,174 @@
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed 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.view;
+
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.servicedesc.ServiceEndpoint;
+
+import org.apache.servicemix.JbiConstants;
+import org.apache.servicemix.jbi.event.ComponentEvent;
+import org.apache.servicemix.jbi.event.ComponentListener;
+import org.apache.servicemix.jbi.event.EndpointEvent;
+import org.apache.servicemix.jbi.event.ExchangeEvent;
+import org.apache.servicemix.jbi.event.ExchangeListener;
+import org.apache.servicemix.jbi.framework.ComponentMBeanImpl;
+import org.apache.servicemix.jbi.framework.Registry;
+import org.apache.servicemix.jbi.messaging.MessageExchangeImpl;
+import org.apache.servicemix.jbi.servicedesc.EndpointSupport;
+
+import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap;
+import edu.emory.mathcs.backport.java.util.concurrent.CopyOnWriteArraySet;
+
+/**
+ * Creates a <a href="http://www.graphviz.org/">DOT</a> file showing the JBI
MessageExchange
+ * flow within the JBI Container.
+
+ * @org.apache.xbean.XBean 
+ * description="Generates DOT visualisations of the exchanges flow inside ServiceMix"
+ * 
+ * @version $Revision: 391707 $
+ */
+public class DotViewFlowListener extends DotViewEndpointListener 
+    implements ExchangeListener, ComponentListener {
+
+    private Map flow;
+    private Set flowLinks;
+    
+    public DotViewFlowListener() {
+        setFile("ServiceMixFlow.dot");
+        flow = new ConcurrentHashMap();
+        flowLinks = new CopyOnWriteArraySet();
+    }
+
+    // Implementation methods
+    // -------------------------------------------------------------------------
+
+    protected void generateFile(PrintWriter writer) throws Exception {
+        writer.println("digraph \"Apache ServiceMix\" {");
+        writer.println();
+        writer.println("label = \"Apache ServiceMix flow\";");
+        writer.println("node [style = \"rounded,filled\", fillcolor = yellow, fontname=\"Helvetica-Oblique\"];");
+        writer.println();
+
+        List brokerLinks = new ArrayList();
+        Registry registry = getContainer().getRegistry();
+        Collection components = registry.getComponents();
+        for (Iterator iter = components.iterator(); iter.hasNext();) {
+            ComponentMBeanImpl component = (ComponentMBeanImpl) iter.next();
+            ServiceEndpoint[] ses = registry.getEndpointsForComponent(component.getComponentNameSpace());
+
+            String name = component.getName();
+            String id = encode(name);
+
+            writer.println("subgraph cluster_" + id + " {");
+            writer.println("  label=\"" + name + "\";");
+            writer.println("  node [fillcolor = yellow];");
+            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);
+                writer.println("  " + epid + " [label=\"" + epname + "\"];");
+            }
+            
+            writer.println("}");
+        }
+        writer.println();
+        generateLinks(writer, brokerLinks);
+
+        writer.println();
+
+        generateLinks(writer, flowLinks);
+        
+        writer.println("}");
+        
+    }
+
+    public void exchangeSent(ExchangeEvent event) {
+        MessageExchange me = event.getExchange();
+        if (me.getEndpoint() != null &&
+            me instanceof MessageExchangeImpl) {
+            MessageExchangeImpl mei = (MessageExchangeImpl) me;
+            String source = (String) me.getProperty(JbiConstants.SENDER_ENDPOINT);
+            if (source == null) {
+                source = mei.getSourceId().getName();
+            }
+            String dest = EndpointSupport.getKey(mei.getEndpoint());
+            Map componentFlow = (Map) flow.get(source);
+            if (componentFlow.put(dest, Boolean.TRUE) == null) {
+                flowLinks.add(encode(source) + " -> " + encode(dest));
+                viewIsDirty(mei.getEndpoint());
+            }
+        }
+        
+    }
+    
+    protected void createSource(String name) {
+        synchronized (flow) {
+            Map componentFlow = (Map) flow.get(name);
+            if (componentFlow == null) {
+                componentFlow = new ConcurrentHashMap();
+                flow.put(name, componentFlow);
+            }
+        }
+    }
+
+    public void internalEndpointRegistered(EndpointEvent event) {
+        String key = EndpointSupport.getKey(event.getEndpoint());
+        createSource(key);
+        super.internalEndpointRegistered(event);
+    }
+    
+    public void externalEndpointRegistered(EndpointEvent event) {
+        String key = EndpointSupport.getKey(event.getEndpoint());
+        createSource(key);
+        super.externalEndpointRegistered(event);
+    }
+    
+    public void linkedEndpointRegistered(EndpointEvent event) {
+        String key = EndpointSupport.getKey(event.getEndpoint());
+        createSource(key);
+        super.linkedEndpointRegistered(event);
+    }
+    
+    public void componentInstalled(ComponentEvent event) {
+        createSource(event.getComponent().getName());
+    }
+
+    public void componentStarted(ComponentEvent event) {
+        createSource(event.getComponent().getName());
+    }
+
+    public void componentStopped(ComponentEvent event) {
+    }
+
+    public void componentShutDown(ComponentEvent event) {
+    }
+
+    public void componentUninstalled(ComponentEvent event) {
+    }
+
+}

Modified: incubator/servicemix/trunk/servicemix-eip/src/test/java/org/apache/servicemix/eip/SpringConfigurationTest.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-eip/src/test/java/org/apache/servicemix/eip/SpringConfigurationTest.java?rev=394610&r1=394609&r2=394610&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-eip/src/test/java/org/apache/servicemix/eip/SpringConfigurationTest.java
(original)
+++ incubator/servicemix/trunk/servicemix-eip/src/test/java/org/apache/servicemix/eip/SpringConfigurationTest.java
Sun Apr 16 22:36:49 2006
@@ -20,6 +20,7 @@
 
 import org.apache.servicemix.client.DefaultServiceMixClient;
 import org.apache.servicemix.client.ServiceMixClient;
+import org.apache.servicemix.jbi.container.ActivationSpec;
 import org.apache.servicemix.jbi.jaxp.StringSource;
 import org.apache.servicemix.tck.Receiver;
 import org.apache.servicemix.tck.SpringTestSupport;
@@ -29,7 +30,9 @@
 public class SpringConfigurationTest extends SpringTestSupport {
 
     public void testConfig() throws Exception {
-        ServiceMixClient client = new DefaultServiceMixClient(jbi);
+        ActivationSpec as = new ActivationSpec();
+        as.setComponentName("client");
+        ServiceMixClient client = new DefaultServiceMixClient(jbi, as);
         InOnly me = client.createInOnlyExchange();
         me.setService(new QName("http://test", "wireTap"));
         me.getInMessage().setContent(new StringSource("<test><echo/><world/></test>"));

Modified: incubator/servicemix/trunk/servicemix-eip/src/test/resources/org/apache/servicemix/eip/spring.xml
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-eip/src/test/resources/org/apache/servicemix/eip/spring.xml?rev=394610&r1=394609&r2=394610&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-eip/src/test/resources/org/apache/servicemix/eip/spring.xml
(original)
+++ incubator/servicemix/trunk/servicemix-eip/src/test/resources/org/apache/servicemix/eip/spring.xml
Sun Apr 16 22:36:49 2006
@@ -3,11 +3,16 @@
   xmlns:eip="http://servicemix.apache.org/eip/1.0" xmlns:test="http://test">
 
   <!-- the JBI container -->
-  <sm:container id="jbi" embedded="true">
+  <sm:container id="jbi" embedded="true">
+    
+    <sm:listeners>
+      <bean class="org.apache.servicemix.jbi.view.DotViewFlowListener" />
+    </sm:listeners>
+    
     <sm:activationSpecs>
 
       <!-- output using a POJO -->
-      <sm:activationSpec>
+      <sm:activationSpec id="servicemix-eip">
         <sm:component>
           <eip:component>
             <eip:endpoints>



Mime
View raw message