Esempio n. 1
0
  private static Map<String, Integer> computeColumnWidths(
      final Iterable<CamelContext> camelContexts) throws Exception {
    if (camelContexts == null) {
      throw new IllegalArgumentException(
          "Unable to determine column widths from null Iterable<CamelContext>");
    } else {
      int maxNameLen = 0;
      int maxStatusLen = 0;
      int maxUptimeLen = 0;

      for (final CamelContext camelContext : camelContexts) {
        final String name = camelContext.getName();
        maxNameLen = java.lang.Math.max(maxNameLen, name == null ? 0 : name.length());

        final String status = camelContext.getStatus().toString();
        maxStatusLen = java.lang.Math.max(maxStatusLen, status == null ? 0 : status.length());

        final String uptime = camelContext.getUptime();
        maxUptimeLen = java.lang.Math.max(maxUptimeLen, uptime == null ? 0 : uptime.length());
      }

      final Map<String, Integer> retval = new Hashtable<String, Integer>(3);
      retval.put(NAME_COLUMN_LABEL, maxNameLen);
      retval.put(STATUS_COLUMN_LABEL, maxStatusLen);
      retval.put(UPTIME_COLUMN_LABEL, maxUptimeLen);

      return retval;
    }
  }
Esempio n. 2
0
  @Override
  public List<Map<String, String>> getCamelContexts() throws Exception {
    List<Map<String, String>> answer = new ArrayList<Map<String, String>>();

    List<CamelContext> camelContexts = getLocalCamelContexts();
    for (CamelContext camelContext : camelContexts) {
      Map<String, String> row = new LinkedHashMap<String, String>();
      row.put("name", camelContext.getName());
      row.put("state", camelContext.getStatus().name());
      row.put("uptime", camelContext.getUptime());
      if (camelContext.getManagedCamelContext() != null) {
        row.put("exchangesTotal", "" + camelContext.getManagedCamelContext().getExchangesTotal());
        row.put(
            "exchangesInflight", "" + camelContext.getManagedCamelContext().getExchangesInflight());
        row.put("exchangesFailed", "" + camelContext.getManagedCamelContext().getExchangesFailed());
      } else {
        row.put("exchangesTotal", "0");
        row.put("exchangesInflight", "0");
        row.put("exchangesFailed", "0");
      }
      answer.add(row);
    }

    return answer;
  }
Esempio n. 3
0
  @Override
  public Object execute(CamelController camelController, PrintStream out, PrintStream err)
      throws Exception {
    final List<CamelContext> camelContexts = camelController.getCamelContexts();

    final Map<String, Integer> columnWidths = computeColumnWidths(camelContexts);
    final String headerFormat = buildFormatString(columnWidths, true);
    final String rowFormat = buildFormatString(columnWidths, false);

    if (camelContexts.size() > 0) {
      out.println(
          String.format(
              headerFormat, CONTEXT_COLUMN_LABEL, STATUS_COLUMN_LABEL, UPTIME_COLUMN_LABEL));
      out.println(String.format(headerFormat, "-------", "------", "------"));
      for (final CamelContext camelContext : camelContexts) {
        out.println(
            String.format(
                rowFormat,
                camelContext.getName(),
                camelContext.getStatus(),
                camelContext.getUptime()));
      }
    }

    return null;
  }
Esempio n. 4
0
  protected Object doExecute() throws Exception {
    final List<CamelContext> camelContexts = camelController.getCamelContexts();

    final Map<String, Integer> columnWidths = computeColumnWidths(camelContexts);
    final String headerFormat = buildFormatString(columnWidths, true);
    final String rowFormat = buildFormatString(columnWidths, false);
    final PrintStream out = System.out;

    if (camelContexts.size() > 0) {
      out.println(
          String.format(headerFormat, NAME_COLUMN_LABEL, STATUS_COLUMN_LABEL, UPTIME_COLUMN_LABEL));
      for (final CamelContext camelContext : camelContexts) {
        out.println(
            String.format(
                rowFormat,
                camelContext.getName(),
                camelContext.getStatus(),
                camelContext.getUptime()));
      }
    }

    return null;
  }