apupier commented on code in PR #21086:
URL: https://github.com/apache/camel/pull/21086#discussion_r2732524341
##########
core/camel-console/src/main/java/org/apache/camel/impl/console/ConsumerDevConsole.java:
##########
@@ -46,185 +46,232 @@ protected String doCallText(Map<String, Object> options) {
StringBuilder sb = new StringBuilder();
ManagedCamelContext mcc =
getCamelContext().getCamelContextExtension().getContextPlugin(ManagedCamelContext.class);
- if (mcc != null) {
- for (Route route : getCamelContext().getRoutes()) {
- String id = route.getId();
- ManagedConsumerMBean mc = mcc.getManagedConsumer(id);
- if (mc != null) {
- Integer inflight = mc.getInflightExchanges();
- if (inflight == null) {
- inflight = 0;
- }
-
- if (!sb.isEmpty()) {
- sb.append("\n");
- }
- sb.append(String.format("%n Id: %s", id));
- sb.append(String.format("%n Uri: %s",
mc.getEndpointUri()));
- sb.append(String.format("%n State: %s", mc.getState()));
- sb.append(String.format("%n Class: %s",
mc.getServiceType()));
- sb.append(String.format("%n Remote: %b",
mc.isRemoteEndpoint()));
- sb.append(String.format("%n Hosted: %b",
mc.isHostedService()));
- sb.append(String.format("%n Inflight: %d", inflight));
- if (mcc instanceof ManagedSchedulePollConsumerMBean mpc) {
- sb.append(String.format("%n Polling: %s",
mpc.isPolling()));
- sb.append(String.format("%n First Poll Done: %s",
mpc.isFirstPollDone()));
- sb.append(String.format("%n Scheduler Started: %s",
mpc.isSchedulerStarted()));
- sb.append(String.format("%n Scheduler Class: %s",
mpc.getSchedulerClassName()));
- sb.append(String.format("%n Repeat Count: %s",
mpc.getRepeatCount()));
- sb.append(String.format("%n Fixed Delay: %s",
mpc.isUseFixedDelay()));
- sb.append(String.format("%n Greedy: %s",
mpc.isGreedy()));
- sb.append(String.format("%n Running Logging Level:
%s", mpc.getRunningLoggingLevel()));
- sb.append(String.format("%n Send Empty Message When
Idle: %s", mpc.isSendEmptyMessageWhenIdle()));
- sb.append(String.format("%n Counter (total: %d
success: %d error: %d)",
- mpc.getCounter(), mpc.getSuccessCounter(),
mpc.getErrorCounter()));
- sb.append(String.format("%n Delay (initial: %d
delay: %d unit: %s)",
- mpc.getInitialDelay(), mpc.getDelay(),
mpc.getTimeUnit()));
- sb.append(String.format(
- "\n Backoff(counter: %d multiplier: %d
errorThreshold: %d, idleThreshold: %d )",
- mpc.getBackoffCounter(),
mpc.getBackoffMultiplier(), mpc.getBackoffErrorThreshold(),
- mpc.getBackoffIdleThreshold()));
- }
- if ("TimerConsumer".equals(mc.getServiceType())) {
- // need to use JMX to gather details for camel-timer
consumer
- try {
- MBeanServer ms =
ManagementFactory.getPlatformMBeanServer();
- ObjectName on =
getCamelContext().getManagementStrategy().getManagementObjectNameStrategy()
-
.getObjectNameForConsumer(getCamelContext(),
- route.getConsumer());
- if (ms.isRegistered(on)) {
- String timerName = (String)
ms.getAttribute(on, "TimerName");
- Long counter = (Long) ms.getAttribute(on,
"Counter");
- Boolean polling = (Boolean)
ms.getAttribute(on, "Polling");
- Boolean fixedRate = (Boolean)
ms.getAttribute(on, "FixedRate");
- Long delay = (Long) ms.getAttribute(on,
"Delay");
- Long period = (Long) ms.getAttribute(on,
"Period");
- Long repeatCount = (Long) ms.getAttribute(on,
"RepeatCount");
- String runLoggingLevel = (String)
ms.getAttribute(on, "RunLoggingLevel");
-
- sb.append(String.format("%n Timer Name:
%s", timerName));
- sb.append(String.format("%n Polling: %s",
polling));
- sb.append(String.format("%n Fixed Rate:
%s", fixedRate));
- if (delay != null) {
- sb.append(String.format("%n Delay: %s",
delay));
- }
- if (period != null) {
- sb.append(String.format("%n Period:
%s", period));
- }
- if (repeatCount != null) {
- sb.append(String.format("%n Repeat
Count: %s", repeatCount));
- }
- sb.append(String.format("%n Running Logging
Level: %s", runLoggingLevel));
- sb.append(String.format("%n Counter (total:
%s)", counter));
-
- }
- } catch (Exception e) {
- // ignore
- }
- }
- }
+ 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();
Review Comment:
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);
}
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]