Search in sources :

Example 1 with NodeIdFactory

use of org.apache.camel.spi.NodeIdFactory in project fabric8 by jboss-fuse.

the class Tracer method forceAutoAssigningIds.

private void forceAutoAssigningIds() {
    for (RouteContext routeContext : routeContexts) {
        CamelContext camelContext = routeContext.getCamelContext();
        NodeIdFactory factory = camelContext.getNodeIdFactory();
        if (factory != null) {
            for (ProcessorDefinition<?> child : processors) {
                // ensure also the children get ids assigned
                RouteDefinitionHelper.forceAssignIds(camelContext, child);
            }
        }
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) NodeIdFactory(org.apache.camel.spi.NodeIdFactory) RouteContext(org.apache.camel.spi.RouteContext)

Example 2 with NodeIdFactory

use of org.apache.camel.spi.NodeIdFactory in project camel by apache.

the class AbstractCamelContextFactoryBean method setupCustomServices.

private void setupCustomServices() {
    ModelJAXBContextFactory modelJAXBContextFactory = getBeanForType(ModelJAXBContextFactory.class);
    if (modelJAXBContextFactory != null) {
        LOG.info("Using custom ModelJAXBContextFactory: {}", modelJAXBContextFactory);
        getContext().setModelJAXBContextFactory(modelJAXBContextFactory);
    }
    ClassResolver classResolver = getBeanForType(ClassResolver.class);
    if (classResolver != null) {
        LOG.info("Using custom ClassResolver: {}", classResolver);
        getContext().setClassResolver(classResolver);
    }
    FactoryFinderResolver factoryFinderResolver = getBeanForType(FactoryFinderResolver.class);
    if (factoryFinderResolver != null) {
        LOG.info("Using custom FactoryFinderResolver: {}", factoryFinderResolver);
        getContext().setFactoryFinderResolver(factoryFinderResolver);
    }
    ExecutorServiceManager executorServiceStrategy = getBeanForType(ExecutorServiceManager.class);
    if (executorServiceStrategy != null) {
        LOG.info("Using custom ExecutorServiceStrategy: {}", executorServiceStrategy);
        getContext().setExecutorServiceManager(executorServiceStrategy);
    }
    ThreadPoolFactory threadPoolFactory = getBeanForType(ThreadPoolFactory.class);
    if (threadPoolFactory != null) {
        LOG.info("Using custom ThreadPoolFactory: {}", threadPoolFactory);
        getContext().getExecutorServiceManager().setThreadPoolFactory(threadPoolFactory);
    }
    ProcessorFactory processorFactory = getBeanForType(ProcessorFactory.class);
    if (processorFactory != null) {
        LOG.info("Using custom ProcessorFactory: {}", processorFactory);
        getContext().setProcessorFactory(processorFactory);
    }
    Debugger debugger = getBeanForType(Debugger.class);
    if (debugger != null) {
        LOG.info("Using custom Debugger: {}", debugger);
        getContext().setDebugger(debugger);
    }
    UuidGenerator uuidGenerator = getBeanForType(UuidGenerator.class);
    if (uuidGenerator != null) {
        LOG.info("Using custom UuidGenerator: {}", uuidGenerator);
        getContext().setUuidGenerator(uuidGenerator);
    }
    NodeIdFactory nodeIdFactory = getBeanForType(NodeIdFactory.class);
    if (nodeIdFactory != null) {
        LOG.info("Using custom NodeIdFactory: {}", nodeIdFactory);
        getContext().setNodeIdFactory(nodeIdFactory);
    }
    StreamCachingStrategy streamCachingStrategy = getBeanForType(StreamCachingStrategy.class);
    if (streamCachingStrategy != null) {
        LOG.info("Using custom StreamCachingStrategy: {}", streamCachingStrategy);
        getContext().setStreamCachingStrategy(streamCachingStrategy);
    }
    MessageHistoryFactory messageHistoryFactory = getBeanForType(MessageHistoryFactory.class);
    if (messageHistoryFactory != null) {
        LOG.info("Using custom MessageHistoryFactory: {}", messageHistoryFactory);
        getContext().setMessageHistoryFactory(messageHistoryFactory);
    }
}
Also used : Debugger(org.apache.camel.spi.Debugger) FactoryFinderResolver(org.apache.camel.spi.FactoryFinderResolver) MessageHistoryFactory(org.apache.camel.spi.MessageHistoryFactory) NodeIdFactory(org.apache.camel.spi.NodeIdFactory) UuidGenerator(org.apache.camel.spi.UuidGenerator) ExecutorServiceManager(org.apache.camel.spi.ExecutorServiceManager) ThreadPoolFactory(org.apache.camel.spi.ThreadPoolFactory) ModelJAXBContextFactory(org.apache.camel.spi.ModelJAXBContextFactory) ClassResolver(org.apache.camel.spi.ClassResolver) PackageScanClassResolver(org.apache.camel.spi.PackageScanClassResolver) StreamCachingStrategy(org.apache.camel.spi.StreamCachingStrategy) ProcessorFactory(org.apache.camel.spi.ProcessorFactory)

Example 3 with NodeIdFactory

use of org.apache.camel.spi.NodeIdFactory in project camel by apache.

the class CustomIdFactoryTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            // use our own id factory so we can generate the keys we like to use
            context.setNodeIdFactory(new NodeIdFactory() {

                public String createId(NamedNode definition) {
                    return "#" + definition.getShortName() + ++counter + "#";
                }
            });
            // add our debugger so we can debug camel routes when we send in messages
            context.addInterceptStrategy(new MyDebuggerCheckingId());
            // a little content based router so we got 2 paths to route at runtime
            from("direct:start").choice().when(body().contains("Hello")).to("mock:hello").otherwise().log("Hey").to("mock:other").end();
        }
    };
}
Also used : NodeIdFactory(org.apache.camel.spi.NodeIdFactory) RouteBuilder(org.apache.camel.builder.RouteBuilder) NamedNode(org.apache.camel.NamedNode)

Example 4 with NodeIdFactory

use of org.apache.camel.spi.NodeIdFactory in project fabric8 by jboss-fuse.

the class CamelAutoTestService method onConfigured.

@Override
protected void onConfigured() throws Exception {
    LOG.debug("onConfigured. mockOutputs: " + mockOutputs + " mockInputs: " + mockInputs + " messageFolder: " + messageFolder);
    FabricService fabricService = this.fabricService.getOptional();
    // lets find the camel contexts to test in this container
    MBeanServer mbeanServerValue = mbeanServer;
    if (mbeanServerValue != null && fabricService != null) {
        Profile overlayProfile = fabricService.getCurrentContainer().getOverlayProfile();
        Profile effectiveProfile = Profiles.getEffectiveProfile(fabricService, overlayProfile);
        Set<String> configurationFileNames = effectiveProfile.getConfigurationFileNames();
        for (CamelContext camelContext : camelContexts.values()) {
            String camelContextID = camelContext.getName();
            // check we only add testing stuff to each context once
            if (camelContext instanceof ModelCamelContext) {
                final ModelCamelContext modelCamelContext = (ModelCamelContext) camelContext;
                List<RouteDefinition> routeDefinitions = modelCamelContext.getRouteDefinitions();
                if (camelContextsConfigured.add(camelContextID)) {
                    NodeIdFactory nodeIdFactory = camelContext.getNodeIdFactory();
                    if (mockInputs || mockOutputs) {
                        for (RouteDefinition routeDefinition : routeDefinitions) {
                            String routeId = routeDefinition.idOrCreate(nodeIdFactory);
                            modelCamelContext.stopRoute(routeId);
                            final String routeKey = camelContextID + "." + routeId;
                            LOG.info("Mocking Camel route: " + routeKey);
                            routeDefinition.adviceWith(modelCamelContext, new AdviceWithRouteBuilder() {

                                @Override
                                public void configure() throws Exception {
                                    if (mockOutputs) {
                                        modelCamelContext.addRegisterEndpointCallback(strategy);
                                    }
                                }
                            });
                        // the advised route is automatic restarted
                        }
                    }
                    String path = messageFolder;
                    if (Strings.isNotBlank(path)) {
                        path += "/";
                    }
                    path += camelContextID;
                    ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
                    try {
                        for (RouteDefinition routeDefinition : routeDefinitions) {
                            String routeId = routeDefinition.idOrCreate(nodeIdFactory);
                            String routePath = path + "/" + routeId + "/";
                            List<FromDefinition> inputs = routeDefinition.getInputs();
                            for (FromDefinition input : inputs) {
                                Endpoint endpoint = input.getEndpoint();
                                if (endpoint == null) {
                                    String uri = input.getUri();
                                    if (Strings.isNullOrBlank(uri)) {
                                        String ref = input.getRef();
                                        if (Strings.isNotBlank(ref)) {
                                            uri = "ref:" + ref;
                                        }
                                    }
                                    if (Strings.isNotBlank(uri)) {
                                        endpoint = camelContext.getEndpoint(uri);
                                    }
                                }
                                if (endpoint == null) {
                                    LOG.warn("Cannot find endpoint, uri or ref of input " + input + " on route " + routeId + " camelContext: " + camelContextID);
                                } else {
                                    for (String configFile : configurationFileNames) {
                                        if (configFile.startsWith(routePath)) {
                                            LOG.info("Sending file: " + configFile + " to " + endpoint);
                                            byte[] data = effectiveProfile.getFileConfiguration(configFile);
                                            if (data != null) {
                                                // lest send this message to this endpoint
                                                producerTemplate.sendBody(endpoint, data);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } finally {
                        producerTemplate.stop();
                    }
                }
            }
        }
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) ModelCamelContext(org.apache.camel.model.ModelCamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) FromDefinition(org.apache.camel.model.FromDefinition) Profile(io.fabric8.api.Profile) ModelCamelContext(org.apache.camel.model.ModelCamelContext) AdviceWithRouteBuilder(org.apache.camel.builder.AdviceWithRouteBuilder) NodeIdFactory(org.apache.camel.spi.NodeIdFactory) RouteDefinition(org.apache.camel.model.RouteDefinition) Endpoint(org.apache.camel.Endpoint) FabricService(io.fabric8.api.FabricService) MBeanServer(javax.management.MBeanServer)

Aggregations

NodeIdFactory (org.apache.camel.spi.NodeIdFactory)4 CamelContext (org.apache.camel.CamelContext)2 FabricService (io.fabric8.api.FabricService)1 Profile (io.fabric8.api.Profile)1 MBeanServer (javax.management.MBeanServer)1 Endpoint (org.apache.camel.Endpoint)1 NamedNode (org.apache.camel.NamedNode)1 ProducerTemplate (org.apache.camel.ProducerTemplate)1 AdviceWithRouteBuilder (org.apache.camel.builder.AdviceWithRouteBuilder)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 FromDefinition (org.apache.camel.model.FromDefinition)1 ModelCamelContext (org.apache.camel.model.ModelCamelContext)1 RouteDefinition (org.apache.camel.model.RouteDefinition)1 ClassResolver (org.apache.camel.spi.ClassResolver)1 Debugger (org.apache.camel.spi.Debugger)1 ExecutorServiceManager (org.apache.camel.spi.ExecutorServiceManager)1 FactoryFinderResolver (org.apache.camel.spi.FactoryFinderResolver)1 MessageHistoryFactory (org.apache.camel.spi.MessageHistoryFactory)1 ModelJAXBContextFactory (org.apache.camel.spi.ModelJAXBContextFactory)1 PackageScanClassResolver (org.apache.camel.spi.PackageScanClassResolver)1