/** * Returns the pattern name */ public static String getPatternName(OptionalIdentifiedDefinition camelNode) { // we should grab the annotation instead XmlRootElement root = camelNode.getClass().getAnnotation(XmlRootElement.class); if (root != null) { return root.name(); } String simpleName = Strings.stripSuffix(camelNode.getClass().getSimpleName(), "Definition"); return Introspector.decapitalize(simpleName); }
public static String getDescription(OptionalIdentifiedDefinition definition) { return definition.getDescriptionText(); }
public OptionalIdentifiedDefinition<?> getToOrRoute() { return toOrRoute; }
/** * To route from this REST service to a Camel endpoint, or an inlined route */ public void setToOrRoute(OptionalIdentifiedDefinition<?> toOrRoute) { this.toOrRoute = toOrRoute; }
/** * Invoked when a new thread pool is created. * This implementation will invoke the {@link LifecycleStrategy#onThreadPoolAdd(org.apache.camel.CamelContext, * java.util.concurrent.ThreadPoolExecutor, String, String, String, String) LifecycleStrategy.onThreadPoolAdd} method, * which for example will enlist the thread pool in JMX management. * * @param executorService the thread pool * @param source the source to use the thread pool * @param threadPoolProfileId profile id, if the thread pool was created from a thread pool profile */ private void onThreadPoolCreated(ExecutorService executorService, Object source, String threadPoolProfileId) { // add to internal list of thread pools executorServices.add(executorService); String id; String sourceId = null; String routeId = null; // extract id from source if (source instanceof NamedNode) { id = ((OptionalIdentifiedDefinition<?>) source).idOrCreate(this.camelContext.getNodeIdFactory()); // and let source be the short name of the pattern sourceId = ((NamedNode) source).getShortName(); } else if (source instanceof String) { id = (String) source; } else if (source != null) { if (source instanceof StaticService) { // the source is static service so its name would be unique id = source.getClass().getSimpleName(); } else { // fallback and use the simple class name with hashcode for the id so its unique for this given source id = source.getClass().getSimpleName() + "(" + ObjectHelper.getIdentityHashCode(source) + ")"; } } else { // no source, so fallback and use the simple class name from thread pool and its hashcode identity so its unique id = executorService.getClass().getSimpleName() + "(" + ObjectHelper.getIdentityHashCode(executorService) + ")"; } // id is mandatory ObjectHelper.notEmpty(id, "id for thread pool " + executorService); // extract route id if possible if (source instanceof ProcessorDefinition) { RouteDefinition route = ProcessorDefinitionHelper.getRoute((ProcessorDefinition<?>) source); if (route != null) { routeId = route.idOrCreate(this.camelContext.getNodeIdFactory()); } } // let lifecycle strategy be notified as well which can let it be managed in JMX as well ThreadPoolExecutor threadPool = null; if (executorService instanceof ThreadPoolExecutor) { threadPool = (ThreadPoolExecutor) executorService; } else if (executorService instanceof SizedScheduledExecutorService) { threadPool = ((SizedScheduledExecutorService) executorService).getScheduledThreadPoolExecutor(); } if (threadPool != null) { for (LifecycleStrategy lifecycle : camelContext.getLifecycleStrategies()) { lifecycle.onThreadPoolAdd(camelContext, threadPool, id, sourceId, routeId, threadPoolProfileId); } } // now call strategy to allow custom logic onNewExecutorService(executorService); }
private static <T extends OptionalIdentifiedDefinition<T>> boolean hasId(T type) { return isNotEmpty(type.getId()); }