Search in sources :

Example 1 with BacklogTracerEventMessage

use of org.apache.camel.api.management.mbean.BacklogTracerEventMessage in project camel by apache.

the class BacklogDebugger method stepBreakpoint.

public void stepBreakpoint(String nodeId) {
    // if we are already in single step mode, then infer stepping
    if (isSingleStepMode()) {
        logger.log("stepBreakpoint " + nodeId + " is already in single step mode, so stepping instead.");
        step();
    }
    logger.log("Step breakpoint " + nodeId);
    // we want to step current exchange to next
    BacklogTracerEventMessage msg = suspendedBreakpointMessages.get(nodeId);
    NodeBreakpoint breakpoint = breakpoints.get(nodeId);
    if (msg != null && breakpoint != null) {
        singleStepExchangeId = msg.getExchangeId();
        if (debugger.startSingleStepExchange(singleStepExchangeId, new StepBreakpoint())) {
            // now resume
            resumeBreakpoint(nodeId, true);
        }
    }
}
Also used : BacklogTracerEventMessage(org.apache.camel.api.management.mbean.BacklogTracerEventMessage)

Example 2 with BacklogTracerEventMessage

use of org.apache.camel.api.management.mbean.BacklogTracerEventMessage in project camel by apache.

the class BacklogDebugger method dumpTracedMessagesAsXml.

public String dumpTracedMessagesAsXml(String nodeId) {
    logger.log("Dump trace message from breakpoint " + nodeId);
    BacklogTracerEventMessage msg = suspendedBreakpointMessages.get(nodeId);
    if (msg != null) {
        return msg.toXml(0);
    } else {
        return null;
    }
}
Also used : BacklogTracerEventMessage(org.apache.camel.api.management.mbean.BacklogTracerEventMessage)

Example 3 with BacklogTracerEventMessage

use of org.apache.camel.api.management.mbean.BacklogTracerEventMessage in project camel by apache.

the class BacklogTracer method dumpTracedMessagesAsXml.

public String dumpTracedMessagesAsXml(String nodeId) {
    List<BacklogTracerEventMessage> events = dumpTracedMessages(nodeId);
    StringBuilder sb = new StringBuilder();
    sb.append("<").append(BacklogTracerEventMessage.ROOT_TAG).append("s>");
    for (BacklogTracerEventMessage event : events) {
        sb.append("\n").append(event.toXml(2));
    }
    sb.append("\n</").append(BacklogTracerEventMessage.ROOT_TAG).append("s>");
    return sb.toString();
}
Also used : BacklogTracerEventMessage(org.apache.camel.api.management.mbean.BacklogTracerEventMessage)

Example 4 with BacklogTracerEventMessage

use of org.apache.camel.api.management.mbean.BacklogTracerEventMessage in project camel by apache.

the class BacklogTracerFilterTest method testBacklogTracerFilter.

@SuppressWarnings("unchecked")
public void testBacklogTracerFilter() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    MBeanServer mbeanServer = getMBeanServer();
    ObjectName on = new ObjectName("org.apache.camel:context=camel-1,type=tracer,name=BacklogTracer");
    assertNotNull(on);
    mbeanServer.isRegistered(on);
    Boolean enabled = (Boolean) mbeanServer.getAttribute(on, "Enabled");
    assertEquals("Should not be enabled", Boolean.FALSE, enabled);
    Integer size = (Integer) mbeanServer.getAttribute(on, "BacklogSize");
    assertEquals("Should be 1000", 1000, size.intValue());
    // set the filter to match only if header foo exists
    mbeanServer.setAttribute(on, new Attribute("TraceFilter", "${header.foo} != null"));
    // enable it
    mbeanServer.setAttribute(on, new Attribute("Enabled", Boolean.TRUE));
    getMockEndpoint("mock:foo").expectedMessageCount(2);
    getMockEndpoint("mock:bar").expectedMessageCount(2);
    template.sendBody("direct:start", "Hello World");
    template.sendBodyAndHeader("direct:start", "Bye World", "foo", 123);
    assertMockEndpointsSatisfied();
    List<Exchange> exchanges = getMockEndpoint("mock:foo").getReceivedExchanges();
    List<BacklogTracerEventMessage> events = (List<BacklogTracerEventMessage>) mbeanServer.invoke(on, "dumpAllTracedMessages", null, null);
    assertNotNull(events);
    assertEquals(3, events.size());
    BacklogTracerEventMessage event = events.get(0);
    assertEquals(null, event.getToNode());
    assertEquals("    <message exchangeId=\"" + exchanges.get(1).getExchangeId() + "\">\n" + "      <headers>\n" + "        <header key=\"foo\" type=\"java.lang.Integer\">123</header>\n" + "      </headers>\n" + "      <body type=\"java.lang.String\">Bye World</body>\n" + "    </message>", event.getMessageAsXml());
    BacklogTracerEventMessage event1 = events.get(1);
    assertEquals("foo", event1.getToNode());
    assertEquals("    <message exchangeId=\"" + exchanges.get(1).getExchangeId() + "\">\n" + "      <headers>\n" + "        <header key=\"foo\" type=\"java.lang.Integer\">123</header>\n" + "      </headers>\n" + "      <body type=\"java.lang.String\">Bye World</body>\n" + "    </message>", event1.getMessageAsXml());
    BacklogTracerEventMessage event2 = events.get(2);
    assertEquals("bar", event2.getToNode());
    assertEquals("    <message exchangeId=\"" + exchanges.get(1).getExchangeId() + "\">\n" + "      <headers>\n" + "        <header key=\"foo\" type=\"java.lang.Integer\">123</header>\n" + "      </headers>\n" + "      <body type=\"java.lang.String\">Bye World</body>\n" + "    </message>", event2.getMessageAsXml());
}
Also used : Exchange(org.apache.camel.Exchange) BacklogTracerEventMessage(org.apache.camel.api.management.mbean.BacklogTracerEventMessage) Attribute(javax.management.Attribute) List(java.util.List) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 5 with BacklogTracerEventMessage

use of org.apache.camel.api.management.mbean.BacklogTracerEventMessage in project camel by apache.

the class BacklogTracerIdOnAllNodesTest method testBacklogTracerEventMessage.

@SuppressWarnings("unchecked")
public void testBacklogTracerEventMessage() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    MBeanServer mbeanServer = getMBeanServer();
    ObjectName on = new ObjectName("org.apache.camel:context=camel-1,type=tracer,name=BacklogTracer");
    assertNotNull(on);
    mbeanServer.isRegistered(on);
    Boolean enabled = (Boolean) mbeanServer.getAttribute(on, "Enabled");
    assertEquals("Should not be enabled", Boolean.FALSE, enabled);
    Integer size = (Integer) mbeanServer.getAttribute(on, "BacklogSize");
    assertEquals("Should be 1000", 1000, size.intValue());
    // enable it
    mbeanServer.setAttribute(on, new Attribute("Enabled", Boolean.TRUE));
    getMockEndpoint("mock:camel").expectedBodiesReceived("Hello Camel");
    getMockEndpoint("mock:other").expectedBodiesReceived("Hello World");
    getMockEndpoint("mock:end").expectedMessageCount(2);
    template.sendBody("direct:start", "Hello Camel");
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
    List<Exchange> fooExchanges = getMockEndpoint("mock:foo").getReceivedExchanges();
    List<Exchange> camelExchanges = getMockEndpoint("mock:camel").getReceivedExchanges();
    RouteDefinition route = context.getRouteDefinitions().get(0);
    assertNotNull(route);
    ChoiceDefinition choice = (ChoiceDefinition) route.getOutputs().get(0);
    assertEquals("choice1", choice.getId());
    WhenDefinition when = (WhenDefinition) choice.getOutputs().get(0);
    assertEquals("when1", when.getId());
    LogDefinition log1 = (LogDefinition) when.getOutputs().get(0);
    assertEquals("log1", log1.getId());
    ToDefinition to1 = (ToDefinition) when.getOutputs().get(1);
    assertEquals("camel", to1.getId());
    OtherwiseDefinition other = (OtherwiseDefinition) choice.getOutputs().get(1);
    assertEquals("otherwise1", other.getId());
    LogDefinition log2 = (LogDefinition) other.getOutputs().get(0);
    assertEquals("log2", log2.getId());
    ToDefinition to2 = (ToDefinition) other.getOutputs().get(1);
    assertEquals("to1", to2.getId());
    ToDefinition to3 = (ToDefinition) other.getOutputs().get(2);
    assertEquals("foo", to3.getId());
    ToDefinition to4 = (ToDefinition) route.getOutputs().get(1);
    assertEquals("end", to4.getId());
    List<BacklogTracerEventMessage> events = (List<BacklogTracerEventMessage>) mbeanServer.invoke(on, "dumpTracedMessages", new Object[] { "to1" }, new String[] { "java.lang.String" });
    assertNotNull(events);
    assertEquals(1, events.size());
    BacklogTracerEventMessage event1 = events.get(0);
    assertEquals("to1", event1.getToNode());
    assertEquals("    <message exchangeId=\"" + fooExchanges.get(0).getExchangeId() + "\">\n" + "      <body type=\"java.lang.String\">Hello World</body>\n" + "    </message>", event1.getMessageAsXml());
    events = (List<BacklogTracerEventMessage>) mbeanServer.invoke(on, "dumpTracedMessages", new Object[] { "camel" }, new String[] { "java.lang.String" });
    assertNotNull(events);
    assertEquals(1, events.size());
    event1 = events.get(0);
    assertEquals("camel", event1.getToNode());
    assertEquals("    <message exchangeId=\"" + camelExchanges.get(0).getExchangeId() + "\">\n" + "      <body type=\"java.lang.String\">Hello Camel</body>\n" + "    </message>", event1.getMessageAsXml());
}
Also used : ToDefinition(org.apache.camel.model.ToDefinition) BacklogTracerEventMessage(org.apache.camel.api.management.mbean.BacklogTracerEventMessage) Attribute(javax.management.Attribute) OtherwiseDefinition(org.apache.camel.model.OtherwiseDefinition) ObjectName(javax.management.ObjectName) Exchange(org.apache.camel.Exchange) RouteDefinition(org.apache.camel.model.RouteDefinition) ChoiceDefinition(org.apache.camel.model.ChoiceDefinition) List(java.util.List) LogDefinition(org.apache.camel.model.LogDefinition) WhenDefinition(org.apache.camel.model.WhenDefinition) MBeanServer(javax.management.MBeanServer)

Aggregations

BacklogTracerEventMessage (org.apache.camel.api.management.mbean.BacklogTracerEventMessage)14 List (java.util.List)10 Attribute (javax.management.Attribute)10 MBeanServer (javax.management.MBeanServer)10 ObjectName (javax.management.ObjectName)10 Exchange (org.apache.camel.Exchange)6 NodeList (org.w3c.dom.NodeList)5 ChoiceDefinition (org.apache.camel.model.ChoiceDefinition)1 LogDefinition (org.apache.camel.model.LogDefinition)1 OtherwiseDefinition (org.apache.camel.model.OtherwiseDefinition)1 RouteDefinition (org.apache.camel.model.RouteDefinition)1 ToDefinition (org.apache.camel.model.ToDefinition)1 WhenDefinition (org.apache.camel.model.WhenDefinition)1