Exemplo n.º 1
0
 @Override
 protected CamelContext createCamelContext() throws Exception {
   CamelContext context = super.createCamelContext();
   // to force a different management name than the camel id
   context.getManagementNameStrategy().setNamePattern("19-#name#");
   return context;
 }
 @Override
 protected CamelContext createCamelContext() throws Exception {
   CamelContext context = super.createCamelContext();
   context.getManagementNameStrategy().setNamePattern("cool");
   return context;
 }
  public void onContextStart(CamelContext context) throws VetoCamelContextStartException {
    Object mc = getManagementObjectStrategy().getManagedObjectForCamelContext(context);

    String name = context.getName();
    String managementName = context.getManagementNameStrategy().getName();

    try {
      boolean done = false;
      while (!done) {
        ObjectName on =
            getManagementStrategy()
                .getManagementNamingStrategy()
                .getObjectNameForCamelContext(managementName, name);
        boolean exists = getManagementStrategy().isManaged(mc, on);
        if (!exists) {
          done = true;
        } else {
          // okay there exists already a CamelContext with this name, we can try to fix it by
          // finding a free name
          boolean fixed = false;
          // if we use the default name strategy we can find a free name to use
          String newName = findFreeName(mc, context.getManagementNameStrategy(), name);
          if (newName != null) {
            // use this as the fixed name
            fixed = true;
            done = true;
            managementName = newName;
          }
          // we could not fix it so veto starting camel
          if (!fixed) {
            throw new VetoCamelContextStartException(
                "CamelContext ("
                    + context.getName()
                    + ") with ObjectName["
                    + on
                    + "] is already registered."
                    + " Make sure to use unique names on CamelContext when using multiple CamelContexts in the same MBeanServer.",
                context);
          } else {
            LOG.warn(
                "This CamelContext("
                    + context.getName()
                    + ") will be registered using the name: "
                    + managementName
                    + " due to clash with an existing name already registered in MBeanServer.");
          }
        }
      }
    } catch (VetoCamelContextStartException e) {
      // rethrow veto
      throw e;
    } catch (Exception e) {
      // must rethrow to allow CamelContext fallback to non JMX agent to allow
      // Camel to continue to run
      throw ObjectHelper.wrapRuntimeCamelException(e);
    }

    // set the name we are going to use
    if (context instanceof DefaultCamelContext) {
      ((DefaultCamelContext) context).setManagementName(managementName);
    }

    try {
      manageObject(mc);
    } catch (Exception e) {
      // must rethrow to allow CamelContext fallback to non JMX agent to allow
      // Camel to continue to run
      throw ObjectHelper.wrapRuntimeCamelException(e);
    }

    // yes we made it and are initialized
    initialized = true;

    if (mc instanceof ManagedCamelContext) {
      camelContextMBean = (ManagedCamelContext) mc;
    }

    // register any pre registered now that we are initialized
    enlistPreRegisteredServices();
  }