Example #1
0
  public boolean createEndpoint(String uri) throws Exception {
    if (context.hasEndpoint(uri) != null) {
      // endpoint already exists
      return false;
    }

    Endpoint endpoint = context.getEndpoint(uri);
    if (endpoint != null) {
      // ensure endpoint is registered, as the management strategy could have been configured to not
      // always
      // register new endpoints in JMX, so we need to check if its registered, and if not register
      // it manually
      ObjectName on =
          context
              .getManagementStrategy()
              .getManagementNamingStrategy()
              .getObjectNameForEndpoint(endpoint);
      if (on != null && !context.getManagementStrategy().getManagementAgent().isRegistered(on)) {
        // register endpoint as mbean
        Object me =
            context
                .getManagementStrategy()
                .getManagementObjectStrategy()
                .getManagedObjectForEndpoint(context, endpoint);
        context.getManagementStrategy().getManagementAgent().register(me, on);
      }
      return true;
    } else {
      return false;
    }
  }
Example #2
0
 public String getManagementStatisticsLevel() {
   if (context.getManagementStrategy().getManagementAgent() != null) {
     return context.getManagementStrategy().getManagementAgent().getStatisticsLevel().name();
   } else {
     return null;
   }
 }
Example #3
0
 @Override
 public void init(ManagementStrategy strategy) {
   super.init(strategy);
   boolean enabled =
       context.getManagementStrategy().getManagementAgent() != null
           && context.getManagementStrategy().getManagementAgent().getStatisticsLevel()
               != ManagementStatisticsLevel.Off;
   setStatisticsEnabled(enabled);
 }
Example #4
0
 public ManagedRoute(ModelCamelContext context, Route route) {
   this.route = route;
   this.context = context;
   this.description = route.toString();
   boolean enabled =
       context.getManagementStrategy().getStatisticsLevel() != ManagementStatisticsLevel.Off;
   setStatisticsEnabled(enabled);
 }
Example #5
0
  public String dumpRoutesStatsAsXml(boolean fullStats, boolean includeProcessors)
      throws Exception {
    StringBuilder sb = new StringBuilder();
    sb.append("<camelContextStat")
        .append(String.format(" id=\"%s\" state=\"%s\"", getCamelId(), getState()));
    // use substring as we only want the attributes
    String stat = dumpStatsAsXml(fullStats);
    sb.append(" exchangesInflight=\"").append(getInflightExchanges()).append("\"");
    sb.append(" ").append(stat.substring(7, stat.length() - 2)).append(">\n");

    MBeanServer server = getContext().getManagementStrategy().getManagementAgent().getMBeanServer();
    if (server != null) {
      // gather all the routes for this CamelContext, which requires JMX
      String prefix =
          getContext().getManagementStrategy().getManagementAgent().getIncludeHostName()
              ? "*/"
              : "";
      ObjectName query =
          ObjectName.getInstance(
              "org.apache.camel:context="
                  + prefix
                  + getContext().getManagementName()
                  + ",type=routes,*");
      Set<ObjectName> routes = server.queryNames(query, null);

      List<ManagedProcessorMBean> processors = new ArrayList<ManagedProcessorMBean>();
      if (includeProcessors) {
        // gather all the processors for this CamelContext, which requires JMX
        query =
            ObjectName.getInstance(
                "org.apache.camel:context="
                    + prefix
                    + getContext().getManagementName()
                    + ",type=processors,*");
        Set<ObjectName> names = server.queryNames(query, null);
        for (ObjectName on : names) {
          ManagedProcessorMBean processor =
              context
                  .getManagementStrategy()
                  .getManagementAgent()
                  .newProxyClient(on, ManagedProcessorMBean.class);
          processors.add(processor);
        }
      }
      Collections.sort(processors, new OrderProcessorMBeans());

      // loop the routes, and append the processor stats if needed
      sb.append("  <routeStats>\n");
      for (ObjectName on : routes) {
        ManagedRouteMBean route =
            context
                .getManagementStrategy()
                .getManagementAgent()
                .newProxyClient(on, ManagedRouteMBean.class);
        sb.append("    <routeStat")
            .append(String.format(" id=\"%s\" state=\"%s\"", route.getRouteId(), route.getState()));
        // use substring as we only want the attributes
        stat = route.dumpStatsAsXml(fullStats);
        sb.append(" exchangesInflight=\"").append(route.getExchangesInflight()).append("\"");
        sb.append(" ").append(stat.substring(7, stat.length() - 2)).append(">\n");

        // add processor details if needed
        if (includeProcessors) {
          sb.append("      <processorStats>\n");
          for (ManagedProcessorMBean processor : processors) {
            // the processor must belong to this route
            if (route.getRouteId().equals(processor.getRouteId())) {
              sb.append("        <processorStat")
                  .append(
                      String.format(
                          " id=\"%s\" index=\"%s\" state=\"%s\"",
                          processor.getProcessorId(), processor.getIndex(), processor.getState()));
              // use substring as we only want the attributes
              stat = processor.dumpStatsAsXml(fullStats);
              sb.append(" exchangesInflight=\"")
                  .append(processor.getExchangesInflight())
                  .append("\"");
              sb.append(" ").append(stat.substring(7)).append("\n");
            }
          }
          sb.append("      </processorStats>\n");
        }
        sb.append("    </routeStat>\n");
      }
      sb.append("  </routeStats>\n");
    }

    sb.append("</camelContextStat>");
    return sb.toString();
  }