Search in sources :

Example 1 with RouteNode

use of org.apache.camel.RouteNode in project camel by apache.

the class DefaultTraceFormatter method extractBreadCrumb.

/**
     * Creates the breadcrumb based on whether this was a trace of
     * an exchange coming out of or into a processing step. For example, 
     * <br/><tt>transform(body) -> ID-mojo/39713-1225468755256/2-0</tt>
     * <br/>or
     * <br/><tt>ID-mojo/39713-1225468755256/2-0 -> transform(body)</tt>
     */
protected String extractBreadCrumb(TraceInterceptor interceptor, ProcessorDefinition<?> currentNode, Exchange exchange) {
    String id = "";
    String result;
    if (!showBreadCrumb && !showExchangeId && !showShortExchangeId && !showNode) {
        return "";
    }
    // compute breadcrumb id
    if (showBreadCrumb) {
        id = getBreadCrumbID(exchange).toString();
    } else if (showExchangeId || showShortExchangeId) {
        id = getBreadCrumbID(exchange).toString();
        if (showShortExchangeId) {
            // only output last part of id
            id = id.substring(id.lastIndexOf('-') + 1);
        }
    }
    // compute from, to and route
    String from = "";
    String to = "";
    String route = "";
    if (showNode || showRouteId) {
        if (exchange.getUnitOfWork() != null) {
            TracedRouteNodes traced = exchange.getUnitOfWork().getTracedRouteNodes();
            RouteNode traceFrom = traced.getSecondLastNode();
            if (traceFrom != null) {
                from = getNodeMessage(traceFrom, exchange);
            } else if (exchange.getFromEndpoint() != null) {
                from = "from(" + exchange.getFromEndpoint().getEndpointUri() + ")";
            }
            RouteNode traceTo = traced.getLastNode();
            if (traceTo != null) {
                to = getNodeMessage(traceTo, exchange);
                // information which route it belongs to
                if (traceTo.isAbstract() && traceTo.getProcessorDefinition() == null) {
                    traceTo = traced.getSecondLastNode();
                }
                if (traceTo != null) {
                    route = extractRoute(traceTo.getProcessorDefinition());
                }
            }
        }
    }
    // assemble result with and without the to/from
    if (showNode) {
        if (showRouteId && route != null) {
            result = id.trim() + " >>> (" + route + ") " + from + " --> " + to.trim() + " <<< ";
        } else {
            result = id.trim() + " >>> " + from + " --> " + to.trim() + " <<< ";
        }
        if (interceptor.shouldTraceOutExchanges() && exchange.hasOut()) {
            result += " (OUT) ";
        }
    } else {
        result = id;
    }
    if (breadCrumbLength > 0) {
        // we want to ensure text coming after this is aligned for readability
        return String.format("%1$-" + breadCrumbLength + "." + breadCrumbLength + "s", result.trim());
    } else {
        return result.trim();
    }
}
Also used : RouteNode(org.apache.camel.RouteNode) TracedRouteNodes(org.apache.camel.spi.TracedRouteNodes)

Example 2 with RouteNode

use of org.apache.camel.RouteNode in project camel by apache.

the class DefaultTracedRouteNodes method pushBlock.

public void pushBlock() {
    // push a new block and add the last node as starting point
    RouteNode last = getLastNode();
    routeNodes.push(new ArrayList<RouteNode>());
    if (last != null) {
        addTraced(last);
    }
}
Also used : RouteNode(org.apache.camel.RouteNode)

Example 3 with RouteNode

use of org.apache.camel.RouteNode in project camel by apache.

the class DefaultTraceEventMessage method extractFromNode.

private static String extractFromNode(Exchange exchange) {
    if (exchange.getUnitOfWork() != null) {
        TracedRouteNodes traced = exchange.getUnitOfWork().getTracedRouteNodes();
        RouteNode last = traced.getSecondLastNode();
        return last != null ? last.getLabel(exchange) : null;
    }
    return null;
}
Also used : RouteNode(org.apache.camel.RouteNode) TracedRouteNodes(org.apache.camel.spi.TracedRouteNodes)

Example 4 with RouteNode

use of org.apache.camel.RouteNode in project camel by apache.

the class DefaultTraceEventMessage method extractToNode.

private static String extractToNode(Exchange exchange) {
    if (exchange.getUnitOfWork() != null) {
        TracedRouteNodes traced = exchange.getUnitOfWork().getTracedRouteNodes();
        RouteNode last = traced.getLastNode();
        return last != null ? last.getLabel(exchange) : null;
    }
    return null;
}
Also used : RouteNode(org.apache.camel.RouteNode) TracedRouteNodes(org.apache.camel.spi.TracedRouteNodes)

Aggregations

RouteNode (org.apache.camel.RouteNode)4 TracedRouteNodes (org.apache.camel.spi.TracedRouteNodes)3