private String findFreeName(Object mc, ManagementNameStrategy strategy, String name) throws MalformedObjectNameException { // we cannot find a free name for fixed named strategies if (strategy.isFixedName()) { return null; } // okay try to find a free name boolean done = false; String newName = null; while (!done) { // compute the next name newName = strategy.getNextName(); ObjectName on = getManagementStrategy().getManagementNamingStrategy().getObjectNameForCamelContext(newName, name); done = !getManagementStrategy().isManaged(mc, on); if (LOG.isTraceEnabled()) { LOG.trace("Using name: {} in ObjectName[{}] exists? {}", new Object[]{name, on, done}); } } return newName; }
public void setup() throws Exception { context = new DefaultCamelContext(); context.setNameStrategy(new ExplicitCamelContextNameStrategy("myCamelContextName")); final ManagementStrategy managementStrategy = context.getManagementStrategy(); final ManagementAgent managementAgent = managementStrategy.getManagementAgent(); managementAgent.setMBeanServerDefaultDomain("org.apache.camel"); final ManagementNameStrategy managementNameStrategy = context.getManagementNameStrategy(); managementNameStrategy.setNamePattern("CustomName-#name#"); // Add a simple test route context.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .routeId("first-route") .log(LoggingLevel.INFO, "First Route", "${body}") .to("mock:result"); from("direct:startOther") .routeId("other-route") .log(LoggingLevel.INFO, "Other Route", "${body}") .to("mock:resultOther"); } }); }
public ManagementNameStrategy getManagementNameStrategy() { return managementNameStrategy; }
public void setManagementNameStrategy(ManagementNameStrategy managementNameStrategy) { this.managementNameStrategy = managementNameStrategy; }
@Override public ManagementNameStrategy getManagementNameStrategy() { return context.getManagementNameStrategy(); }
@Override public void setManagementNameStrategy(ManagementNameStrategy nameStrategy) { context.setManagementNameStrategy(nameStrategy); }
/** * Gets the current management name strategy * * @return management name strategy */ ManagementNameStrategy getManagementNameStrategy();
/** * Sets a custom management name strategy * * @param nameStrategy name strategy */ void setManagementNameStrategy(ManagementNameStrategy nameStrategy);