This is an automated email from the ASF dual-hosted git repository. orpiske pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
commit e977bf5dff055c3ed535a68f7aa0f94c9c028d66 Author: Otavio Rodolfo Piske <[email protected]> AuthorDate: Thu Apr 11 13:34:44 2024 +0200 (chores) camel-core-console: extract independent code snippets from large code blocks --- .../camel/impl/console/ConsumerDevConsole.java | 53 ++++++++++++---------- .../apache/camel/impl/console/RouteDevConsole.java | 53 ++++++++++++---------- .../camel/impl/console/ThreadDevConsole.java | 41 +++++++++-------- .../apache/camel/impl/console/TopDevConsole.java | 50 ++++++++++++-------- .../camel/impl/console/TransformerConsole.java | 13 ++++-- .../camel/impl/console/VariablesDevConsole.java | 31 +++++++------ 6 files changed, 138 insertions(+), 103 deletions(-) diff --git a/core/camel-console/src/main/java/org/apache/camel/impl/console/ConsumerDevConsole.java b/core/camel-console/src/main/java/org/apache/camel/impl/console/ConsumerDevConsole.java index 1fa40f79cb8..420346bc035 100644 --- a/core/camel-console/src/main/java/org/apache/camel/impl/console/ConsumerDevConsole.java +++ b/core/camel-console/src/main/java/org/apache/camel/impl/console/ConsumerDevConsole.java @@ -212,30 +212,7 @@ public class ConsumerDevConsole extends AbstractDevConsole { } if (mr != null) { - JsonObject stats = new JsonObject(); - stats.put("idleSince", mr.getIdleSince()); - stats.put("exchangesTotal", mr.getExchangesTotal()); - stats.put("exchangesFailed", mr.getExchangesFailed()); - stats.put("exchangesInflight", mr.getExchangesInflight()); - stats.put("meanProcessingTime", mr.getMeanProcessingTime()); - stats.put("maxProcessingTime", mr.getMaxProcessingTime()); - stats.put("minProcessingTime", mr.getMinProcessingTime()); - if (mr.getExchangesTotal() > 0) { - stats.put("lastProcessingTime", mr.getLastProcessingTime()); - stats.put("deltaProcessingTime", mr.getDeltaProcessingTime()); - } - Date last = mr.getLastExchangeCreatedTimestamp(); - if (last != null) { - stats.put("lastCreatedExchangeTimestamp", last.getTime()); - } - last = mr.getLastExchangeCompletedTimestamp(); - if (last != null) { - stats.put("lastCompletedExchangeTimestamp", last.getTime()); - } - last = mr.getLastExchangeFailureTimestamp(); - if (last != null) { - stats.put("lastFailedExchangeTimestamp", last.getTime()); - } + final JsonObject stats = toJsonObject(mr); jo.put("statistics", stats); } @@ -247,4 +224,32 @@ public class ConsumerDevConsole extends AbstractDevConsole { return root; } + private static JsonObject toJsonObject(ManagedRouteMBean mr) { + JsonObject stats = new JsonObject(); + stats.put("idleSince", mr.getIdleSince()); + stats.put("exchangesTotal", mr.getExchangesTotal()); + stats.put("exchangesFailed", mr.getExchangesFailed()); + stats.put("exchangesInflight", mr.getExchangesInflight()); + stats.put("meanProcessingTime", mr.getMeanProcessingTime()); + stats.put("maxProcessingTime", mr.getMaxProcessingTime()); + stats.put("minProcessingTime", mr.getMinProcessingTime()); + if (mr.getExchangesTotal() > 0) { + stats.put("lastProcessingTime", mr.getLastProcessingTime()); + stats.put("deltaProcessingTime", mr.getDeltaProcessingTime()); + } + Date last = mr.getLastExchangeCreatedTimestamp(); + if (last != null) { + stats.put("lastCreatedExchangeTimestamp", last.getTime()); + } + last = mr.getLastExchangeCompletedTimestamp(); + if (last != null) { + stats.put("lastCompletedExchangeTimestamp", last.getTime()); + } + last = mr.getLastExchangeFailureTimestamp(); + if (last != null) { + stats.put("lastFailedExchangeTimestamp", last.getTime()); + } + return stats; + } + } diff --git a/core/camel-console/src/main/java/org/apache/camel/impl/console/RouteDevConsole.java b/core/camel-console/src/main/java/org/apache/camel/impl/console/RouteDevConsole.java index 3f53ba6a20d..a593926d4b4 100644 --- a/core/camel-console/src/main/java/org/apache/camel/impl/console/RouteDevConsole.java +++ b/core/camel-console/src/main/java/org/apache/camel/impl/console/RouteDevConsole.java @@ -339,34 +339,39 @@ public class RouteDevConsole extends AbstractDevConsole { } jo.put("processor", mp.getProcessorName()); jo.put("level", mp.getLevel()); - JsonObject stats = new JsonObject(); - stats.put("idleSince", mp.getIdleSince()); - stats.put("exchangesTotal", mp.getExchangesTotal()); - stats.put("exchangesFailed", mp.getExchangesFailed()); - stats.put("exchangesInflight", mp.getExchangesInflight()); - stats.put("meanProcessingTime", mp.getMeanProcessingTime()); - stats.put("maxProcessingTime", mp.getMaxProcessingTime()); - stats.put("minProcessingTime", mp.getMinProcessingTime()); - if (mp.getExchangesTotal() > 0) { - stats.put("lastProcessingTime", mp.getLastProcessingTime()); - stats.put("deltaProcessingTime", mp.getDeltaProcessingTime()); - } - Date last = mp.getLastExchangeCreatedTimestamp(); - if (last != null) { - stats.put("lastCreatedExchangeTimestamp", last.getTime()); - } - last = mp.getLastExchangeCompletedTimestamp(); - if (last != null) { - stats.put("lastCompletedExchangeTimestamp", last.getTime()); - } - last = mp.getLastExchangeFailureTimestamp(); - if (last != null) { - stats.put("lastFailedExchangeTimestamp", last.getTime()); - } + final JsonObject stats = getStatsObject(mp); jo.put("statistics", stats); } } + private static JsonObject getStatsObject(ManagedProcessorMBean mp) { + JsonObject stats = new JsonObject(); + stats.put("idleSince", mp.getIdleSince()); + stats.put("exchangesTotal", mp.getExchangesTotal()); + stats.put("exchangesFailed", mp.getExchangesFailed()); + stats.put("exchangesInflight", mp.getExchangesInflight()); + stats.put("meanProcessingTime", mp.getMeanProcessingTime()); + stats.put("maxProcessingTime", mp.getMaxProcessingTime()); + stats.put("minProcessingTime", mp.getMinProcessingTime()); + if (mp.getExchangesTotal() > 0) { + stats.put("lastProcessingTime", mp.getLastProcessingTime()); + stats.put("deltaProcessingTime", mp.getDeltaProcessingTime()); + } + Date last = mp.getLastExchangeCreatedTimestamp(); + if (last != null) { + stats.put("lastCreatedExchangeTimestamp", last.getTime()); + } + last = mp.getLastExchangeCompletedTimestamp(); + if (last != null) { + stats.put("lastCompletedExchangeTimestamp", last.getTime()); + } + last = mp.getLastExchangeFailureTimestamp(); + if (last != null) { + stats.put("lastFailedExchangeTimestamp", last.getTime()); + } + return stats; + } + protected void doCall(Map<String, Object> options, Function<ManagedRouteMBean, Object> task) { String path = (String) options.get(Exchange.HTTP_PATH); String subPath = path != null ? StringHelper.after(path, "/") : null; diff --git a/core/camel-console/src/main/java/org/apache/camel/impl/console/ThreadDevConsole.java b/core/camel-console/src/main/java/org/apache/camel/impl/console/ThreadDevConsole.java index 8f7680392f3..042ecb53a02 100644 --- a/core/camel-console/src/main/java/org/apache/camel/impl/console/ThreadDevConsole.java +++ b/core/camel-console/src/main/java/org/apache/camel/impl/console/ThreadDevConsole.java @@ -88,24 +88,7 @@ public class ThreadDevConsole extends AbstractDevConsole { for (long id : ids) { ThreadInfo ti = st ? tb.getThreadInfo(id, Integer.MAX_VALUE) : tb.getThreadInfo(id); if (ti != null) { - JsonObject jo = new JsonObject(); - jo.put("id", ti.getThreadId()); - jo.put("name", ti.getThreadName()); - jo.put("state", ti.getThreadState().name()); - jo.put("blockedCount", ti.getBlockedCount()); - jo.put("blockedTime", ti.getBlockedTime()); - jo.put("waitedCount", ti.getWaitedCount()); - jo.put("waitedTime", ti.getWaitedTime()); - if (ti.getLockName() != null) { - jo.put("lockName", ti.getLockName()); - } - if (st) { - JsonArray arr2 = new JsonArray(); - jo.put("stackTrace", arr2); - for (StackTraceElement e : ti.getStackTrace()) { - arr2.add(e.toString()); - } - } + final JsonObject jo = toJsonObject(ti, st); arr.add(jo); } } @@ -114,4 +97,26 @@ public class ThreadDevConsole extends AbstractDevConsole { return root; } + private static JsonObject toJsonObject(ThreadInfo ti, boolean st) { + JsonObject jo = new JsonObject(); + jo.put("id", ti.getThreadId()); + jo.put("name", ti.getThreadName()); + jo.put("state", ti.getThreadState().name()); + jo.put("blockedCount", ti.getBlockedCount()); + jo.put("blockedTime", ti.getBlockedTime()); + jo.put("waitedCount", ti.getWaitedCount()); + jo.put("waitedTime", ti.getWaitedTime()); + if (ti.getLockName() != null) { + jo.put("lockName", ti.getLockName()); + } + if (st) { + JsonArray arr2 = new JsonArray(); + jo.put("stackTrace", arr2); + for (StackTraceElement e : ti.getStackTrace()) { + arr2.add(e.toString()); + } + } + return jo; + } + } diff --git a/core/camel-console/src/main/java/org/apache/camel/impl/console/TopDevConsole.java b/core/camel-console/src/main/java/org/apache/camel/impl/console/TopDevConsole.java index f17264715b3..6bf8d32d321 100644 --- a/core/camel-console/src/main/java/org/apache/camel/impl/console/TopDevConsole.java +++ b/core/camel-console/src/main/java/org/apache/camel/impl/console/TopDevConsole.java @@ -183,16 +183,7 @@ public class TopDevConsole extends AbstractDevConsole { } jo.put("state", mrb.getState()); jo.put("uptime", mrb.getUptime()); - JsonObject stats = new JsonObject(); - stats.put("exchangesTotal", mrb.getExchangesTotal()); - stats.put("exchangesFailed", mrb.getExchangesFailed()); - stats.put("exchangesInflight", mrb.getExchangesInflight()); - stats.put("meanProcessingTime", mrb.getMeanProcessingTime()); - stats.put("maxProcessingTime", mrb.getMaxProcessingTime()); - stats.put("minProcessingTime", mrb.getMinProcessingTime()); - stats.put("lastProcessingTime", mrb.getLastProcessingTime()); - stats.put("deltaProcessingTime", mrb.getDeltaProcessingTime()); - stats.put("totalProcessingTime", mrb.getTotalProcessingTime()); + final JsonObject stats = getStatsObject(mrb); jo.put("statistics", stats); return null; }; @@ -244,16 +235,7 @@ public class TopDevConsole extends AbstractDevConsole { } } - JsonObject stats = new JsonObject(); - stats.put("exchangesTotal", mpb.getExchangesTotal()); - stats.put("exchangesFailed", mpb.getExchangesFailed()); - stats.put("exchangesInflight", mpb.getExchangesInflight()); - stats.put("meanProcessingTime", mpb.getMeanProcessingTime()); - stats.put("maxProcessingTime", mpb.getMaxProcessingTime()); - stats.put("minProcessingTime", mpb.getMinProcessingTime()); - stats.put("lastProcessingTime", mpb.getLastProcessingTime()); - stats.put("deltaProcessingTime", mpb.getDeltaProcessingTime()); - stats.put("totalProcessingTime", mpb.getTotalProcessingTime()); + final JsonObject stats = getStatsObject(mpb); jo.put("statistics", stats); return null; }; @@ -265,6 +247,34 @@ public class TopDevConsole extends AbstractDevConsole { return root; } + private static JsonObject getStatsObject(ManagedProcessorMBean mpb) { + JsonObject stats = new JsonObject(); + stats.put("exchangesTotal", mpb.getExchangesTotal()); + stats.put("exchangesFailed", mpb.getExchangesFailed()); + stats.put("exchangesInflight", mpb.getExchangesInflight()); + stats.put("meanProcessingTime", mpb.getMeanProcessingTime()); + stats.put("maxProcessingTime", mpb.getMaxProcessingTime()); + stats.put("minProcessingTime", mpb.getMinProcessingTime()); + stats.put("lastProcessingTime", mpb.getLastProcessingTime()); + stats.put("deltaProcessingTime", mpb.getDeltaProcessingTime()); + stats.put("totalProcessingTime", mpb.getTotalProcessingTime()); + return stats; + } + + private static JsonObject getStatsObject(ManagedRouteMBean mrb) { + JsonObject stats = new JsonObject(); + stats.put("exchangesTotal", mrb.getExchangesTotal()); + stats.put("exchangesFailed", mrb.getExchangesFailed()); + stats.put("exchangesInflight", mrb.getExchangesInflight()); + stats.put("meanProcessingTime", mrb.getMeanProcessingTime()); + stats.put("maxProcessingTime", mrb.getMaxProcessingTime()); + stats.put("minProcessingTime", mrb.getMinProcessingTime()); + stats.put("lastProcessingTime", mrb.getLastProcessingTime()); + stats.put("deltaProcessingTime", mrb.getDeltaProcessingTime()); + stats.put("totalProcessingTime", mrb.getTotalProcessingTime()); + return stats; + } + private void topRoutes( String filter, int max, ManagedCamelContext mcc, Function<ManagedRouteMBean, Object> task) { diff --git a/core/camel-console/src/main/java/org/apache/camel/impl/console/TransformerConsole.java b/core/camel-console/src/main/java/org/apache/camel/impl/console/TransformerConsole.java index d400f81fc5d..a3c0aec50c1 100644 --- a/core/camel-console/src/main/java/org/apache/camel/impl/console/TransformerConsole.java +++ b/core/camel-console/src/main/java/org/apache/camel/impl/console/TransformerConsole.java @@ -64,6 +64,14 @@ public class TransformerConsole extends AbstractDevConsole { root.put("dynamicSize", reg.dynamicSize()); root.put("staticSize", reg.staticSize()); root.put("maximumCacheSize", reg.getMaximumCacheSize()); + final JsonArray arr = toJsonArray(reg); + if (!arr.isEmpty()) { + root.put("transformers", arr); + } + return root; + } + + private static JsonArray toJsonArray(TransformerRegistry<?> reg) { JsonArray arr = new JsonArray(); for (Map.Entry<?, Transformer> entry : reg.entrySet()) { Transformer t = entry.getValue(); @@ -79,9 +87,6 @@ public class TransformerConsole extends AbstractDevConsole { } arr.add(jo); } - if (!arr.isEmpty()) { - root.put("transformers", arr); - } - return root; + return arr; } } diff --git a/core/camel-console/src/main/java/org/apache/camel/impl/console/VariablesDevConsole.java b/core/camel-console/src/main/java/org/apache/camel/impl/console/VariablesDevConsole.java index 26f0599ade0..95260395237 100644 --- a/core/camel-console/src/main/java/org/apache/camel/impl/console/VariablesDevConsole.java +++ b/core/camel-console/src/main/java/org/apache/camel/impl/console/VariablesDevConsole.java @@ -59,19 +59,7 @@ public class VariablesDevConsole extends AbstractDevConsole { Set<BrowsableVariableRepository> repos = getCamelContext().getRegistry().findByType(BrowsableVariableRepository.class); for (BrowsableVariableRepository repo : repos) { - List<JsonObject> arr = new ArrayList<>(); - for (Map.Entry<String, Object> entry : repo.getVariables().entrySet()) { - String k = entry.getKey(); - Object v = entry.getValue(); - String t = v != null ? v.getClass().getName() : null; - JsonObject e = new JsonObject(); - e.put("key", k); - e.put("value", v); - if (t != null) { - e.put("className", t); - } - arr.add(e); - } + final List<JsonObject> arr = toJsonObjects(repo); if (!arr.isEmpty()) { root.put(repo.getId(), arr); } @@ -79,4 +67,21 @@ public class VariablesDevConsole extends AbstractDevConsole { return root; } + + private static List<JsonObject> toJsonObjects(BrowsableVariableRepository repo) { + List<JsonObject> arr = new ArrayList<>(); + for (Map.Entry<String, Object> entry : repo.getVariables().entrySet()) { + String k = entry.getKey(); + Object v = entry.getValue(); + String t = v != null ? v.getClass().getName() : null; + JsonObject e = new JsonObject(); + e.put("key", k); + e.put("value", v); + if (t != null) { + e.put("className", t); + } + arr.add(e); + } + return arr; + } }
