| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
package org.apache.camel.view; |
| 18 |
|
|
| 19 |
|
import java.io.FileWriter; |
| 20 |
|
import java.io.IOException; |
| 21 |
|
import java.io.PrintWriter; |
| 22 |
|
import java.util.List; |
| 23 |
|
|
| 24 |
|
import org.apache.camel.CamelContext; |
| 25 |
|
import org.apache.camel.Endpoint; |
| 26 |
|
import org.apache.camel.Processor; |
| 27 |
|
import org.apache.camel.Route; |
| 28 |
|
import org.apache.camel.impl.EventDrivenConsumerRoute; |
| 29 |
|
import org.apache.commons.logging.Log; |
| 30 |
|
import org.apache.commons.logging.LogFactory; |
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
0 |
public class RouteDotGenerator { |
| 39 |
0 |
private static final transient Log LOG = LogFactory.getLog(RouteDotGenerator.class); |
| 40 |
0 |
private String file = "CamelRoutes.dot"; |
| 41 |
|
|
| 42 |
|
public String getFile() { |
| 43 |
0 |
return file; |
| 44 |
|
} |
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
public void setFile(String file) { |
| 50 |
0 |
this.file = file; |
| 51 |
0 |
} |
| 52 |
|
|
| 53 |
|
public void drawRoutes(CamelContext context) throws IOException { |
| 54 |
0 |
PrintWriter writer = new PrintWriter(new FileWriter(file)); |
| 55 |
0 |
generateFile(writer, context); |
| 56 |
0 |
} |
| 57 |
|
|
| 58 |
|
protected void generateFile(PrintWriter writer, CamelContext context) { |
| 59 |
0 |
writer.println("digraph \"Camel Routes\" {"); |
| 60 |
0 |
writer.println(); |
| 61 |
0 |
writer.println("label=\"Camel Container: " + context + "\"];"); |
| 62 |
0 |
writer.println(); |
| 63 |
0 |
writer.println("node [style = \"rounded,filled\", fillcolor = yellow, " |
| 64 |
|
+ "fontname=\"Helvetica-Oblique\"];"); |
| 65 |
0 |
writer.println(); |
| 66 |
0 |
printRoutes(writer, context.getRoutes()); |
| 67 |
0 |
} |
| 68 |
|
|
| 69 |
|
protected void printRoutes(PrintWriter writer, List<Route> routes) { |
| 70 |
0 |
for (Route r : routes) { |
| 71 |
0 |
Endpoint end = r.getEndpoint(); |
| 72 |
0 |
writer.print(end.getEndpointUri()); |
| 73 |
0 |
writer.print(" -> "); |
| 74 |
0 |
writer.print(r); |
| 75 |
0 |
writer.print(" -> "); |
| 76 |
0 |
if (r instanceof EventDrivenConsumerRoute) { |
| 77 |
0 |
EventDrivenConsumerRoute consumerRoute = (EventDrivenConsumerRoute)r; |
| 78 |
0 |
Processor p = consumerRoute.getProcessor(); |
| 79 |
0 |
writer.println(p); |
| 80 |
|
} |
| 81 |
0 |
} |
| 82 |
0 |
} |
| 83 |
|
} |