Skip to content

Conversation

@orpiske
Copy link
Contributor

@orpiske orpiske commented Jan 27, 2026

Summary

  • Refactored 15 files in camel-console module to reduce cognitive complexity
  • Applied guard clause pattern to flatten nested if-statements
  • Extracted helper methods for repeated logic
  • Used switch expressions instead of if-else chains

Changes

  • BrowseDevConsole: extracted option parsing and message processing helpers
  • ReceiveDevConsole: extracted JMX endpoint lookup logic
  • BeanDevConsole: extracted bean processing and property handling
  • ConsumerDevConsole: extracted timer consumer and scheduled poll consumer helpers
  • ProcessorDevConsole: extracted processor info and code snippet generation
  • RouteDevConsole: extracted route command execution
  • SendDevConsole: extracted endpoint lookup patterns
  • RouteGroupDevConsole: extracted group command execution
  • RestDevConsole: extracted rest service rendering
  • RouteDumpDevConsole: extracted route dump format handling
  • ReloadDevConsole: extracted reload strategy handling
  • TraceDevConsole: extracted tracer status and dump handling
  • DebugDevConsole: extracted debugger command execution and stepping logic
  • ProducerDevConsole: extracted producer MBean querying
  • MessageHistoryDevConsole: extracted trace message processing

Test plan

  • Full module verification passed: mvn verify in core/camel-console
  • All existing tests continue to pass

@github-actions
Copy link
Contributor

🌟 Thank you for your contribution to the Apache Camel project! 🌟

🤖 CI automation will test this PR automatically.

🐫 Apache Camel Committers, please review the following items:

  • First-time contributors require MANUAL approval for the GitHub Actions to run

  • You can use the command /component-test (camel-)component-name1 (camel-)component-name2.. to request a test from the test bot.

  • You can label PRs using build-all, build-dependents, skip-tests and test-dependents to fine-tune the checks executed by this PR.

  • Build and test logs are available in the Summary page. Only Apache Camel committers have access to the summary.

  • ⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

Comment on lines -171 to -211
if (endpoint instanceof BrowsableEndpoint be
&& (filter == null || PatternHelper.matchPattern(endpoint.getEndpointUri(), filter))) {
if (dump) {
List<Exchange> list = freshSize ? be.getExchanges(Integer.MAX_VALUE, null) : be.getExchanges(max, null);
int queueSize = list != null ? list.size() : 0;
int begin = 0;
if (list != null && pos > 0) {
begin = Math.max(0, list.size() - pos);
list = list.subList(begin, list.size());
}
if (list != null) {
JsonObject jo = new JsonObject();
jo.put("endpointUri", endpoint.getEndpointUri());
jo.put("queueSize", queueSize);
jo.put("limit", max);
jo.put("position", begin);
if (!list.isEmpty()) {
long ts = list.get(0).getMessage().getHeader(Exchange.MESSAGE_TIMESTAMP, 0L, long.class);
if (ts > 0) {
jo.put("firstTimestamp", ts);
}
if (list.size() > 1) {
ts = list.get(list.size() - 1).getMessage().getHeader(Exchange.MESSAGE_TIMESTAMP, 0L,
long.class);
if (ts > 0) {
jo.put("lastTimestamp", ts);
}
}
}
arr.add(jo);
JsonArray arr2 = new JsonArray();
for (Exchange e : list) {
arr2.add(MessageHelper.dumpAsJSonObject(e.getMessage(), false, false, includeBody, true, true, true,
maxChars));
}
if (!arr2.isEmpty()) {
jo.put("messages", arr2);
}
}
} else {
BrowsableEndpoint.BrowseStatus status = be.getBrowseStatus(Integer.MAX_VALUE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is exchanging sonar warnign about cyclomatic complexity to too many break or continue statement

Comment on lines +49 to 69
if (mcc == null) {
return sb.toString();
}

for (Route route : getCamelContext().getRoutes()) {
String id = route.getId();
ManagedConsumerMBean mc = mcc.getManagedConsumer(id);
if (mc == null) {
continue;
}

if (!sb.isEmpty()) {
sb.append("\n");
}

appendBasicConsumerInfoText(sb, id, mc);
appendScheduledPollConsumerText(sb, mcc);
appendTimerConsumerText(sb, mc, route);
}

return sb.toString();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to keep happy-path first, avoid continue and reduce amount of code:

        if (mcc != null) {
            for (Route route : getCamelContext().getRoutes()) {
                String id = route.getId();
                ManagedConsumerMBean mc = mcc.getManagedConsumer(id);
                if (mc != null) {
                    if (!sb.isEmpty()) {
                        sb.append("\n");
                    }
                    
                    appendBasicConsumerInfoText(sb, id, mc);
                    appendScheduledPollConsumerText(sb, mcc);
                    appendTimerConsumerText(sb, mc, route);
                }
            }
        }

Comment on lines +109 to +125
if (!"TimerConsumer".equals(mc.getServiceType())) {
return;
}

try {
MBeanServer ms = ManagementFactory.getPlatformMBeanServer();
ObjectName on = getCamelContext().getManagementStrategy().getManagementObjectNameStrategy()
.getObjectNameForConsumer(getCamelContext(), route.getConsumer());

if (!ms.isRegistered(on)) {
return;
}

appendTimerAttributesText(sb, ms, on);
} catch (Exception e) {
// ignore
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to avoid negation, reduce amount of code and reduce amount of return:

        if ("TimerConsumer".equals(mc.getServiceType())) {
            try {
                MBeanServer ms = ManagementFactory.getPlatformMBeanServer();
                ObjectName on = getCamelContext().getManagementStrategy().getManagementObjectNameStrategy()
                        .getObjectNameForConsumer(getCamelContext(), route.getConsumer());

                if (ms.isRegistered(on)) {
                    appendTimerAttributesText(sb, ms, on);
                }
            } catch (Exception e) {
                // ignore
            }
        }

@orpiske orpiske force-pushed the ci-camel-4-platform-simplify-camel-console branch from eba549e to bc43dee Compare January 28, 2026 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants