private static CamelContextNameStrategy nameStrategy(Annotated annotated) { if (annotated.isAnnotationPresent(ContextName.class)) { return new ExplicitCamelContextNameStrategy(annotated.getAnnotation(ContextName.class).value()); } else if (annotated.isAnnotationPresent(Named.class)) { // TODO: support stereotype with empty @Named annotation String name = annotated.getAnnotation(Named.class).value(); if (name.isEmpty()) { if (annotated instanceof AnnotatedField) { name = ((AnnotatedField) annotated).getJavaMember().getName(); } else if (annotated instanceof AnnotatedMethod) { name = ((AnnotatedMethod) annotated).getJavaMember().getName(); if (name.startsWith("get")) { name = decapitalize(name.substring(3)); } } else { name = decapitalize(getRawType(annotated.getBaseType()).getSimpleName()); } } return new ExplicitCamelContextNameStrategy(name); } else { // Use a specific naming strategy for Camel CDI as the default one increments the suffix for each CDI proxy created return new CdiCamelContextNameStrategy(); } } }
@Override public void start(StartContext startContext) throws StartException { try { Module appModule = Module.getCallerModuleLoader().loadModule("swarm.application"); ModuleClassLoaderAssociationHandler.associate(appModule.getClassLoader()); try { for (Map.Entry<String, RouteBuilder> entry : fraction.getRouteBuilders().entrySet()) { String name = entry.getKey(); RouteBuilder builder = entry.getValue(); ModelCamelContext camelctx = builder.getContext(); if (name != null) { camelctx.setNameStrategy(new ExplicitCamelContextNameStrategy(name)); } builder.addRoutesToCamelContext(camelctx); systemContexts.add(camelctx); } } finally { ModuleClassLoaderAssociationHandler.disassociate(); } for (CamelContext camelctx : systemContexts) { camelctx.start(); } } catch (Exception ex) { throw new StartException(ex); } }
@Override public void start(StartContext startContext) throws StartException { try { Module appModule = Module.getCallerModuleLoader().loadModule("thorntail.application"); ModuleClassLoaderAssociationHandler.associate(appModule.getClassLoader()); try { for (Map.Entry<String, RouteBuilder> entry : fraction.getRouteBuilders().entrySet()) { String name = entry.getKey(); RouteBuilder builder = entry.getValue(); ModelCamelContext camelctx = builder.getContext(); if (name != null) { camelctx.setNameStrategy(new ExplicitCamelContextNameStrategy(name)); } builder.addRoutesToCamelContext(camelctx); systemContexts.add(camelctx); } } finally { ModuleClassLoaderAssociationHandler.disassociate(); } for (CamelContext camelctx : systemContexts) { camelctx.start(); } } catch (Exception ex) { throw new StartException(ex); } }
protected void setupCamelContext(final BundleContext bundleContext, final String camelContextId) throws Exception { // Set up CamelContext if (camelContextId != null) { context.setNameStrategy(new ExplicitCamelContextNameStrategy(camelContextId)); } // Add routes for (RoutesBuilder route : getRouteBuilders()) { context.addRoutes(configure(context, route, log)); } // ensure we publish this CamelContext to the OSGi service registry context.getManagementStrategy().addEventNotifier(new OsgiCamelContextPublisher(bundleContext)); }