Search in sources :

Example 76 with Route

use of org.apache.camel.Route in project camel by apache.

the class ResequencerTest method testBatchResequencerTypeWithoutJmx.

public void testBatchResequencerTypeWithoutJmx() throws Exception {
    List<Route> list = getRouteList(createRouteBuilder());
    assertEquals("Number of routes created: " + list, 1, list.size());
    Route route = list.get(0);
    EventDrivenConsumerRoute consumerRoute = assertIsInstanceOf(EventDrivenConsumerRoute.class, route);
    DefaultChannel channel = assertIsInstanceOf(DefaultChannel.class, unwrapChannel(consumerRoute.getProcessor()));
    assertIsInstanceOf(DefaultErrorHandler.class, channel.getErrorHandler());
    assertFalse("Should not have stream caching", channel.hasInterceptorStrategy(StreamCaching.class));
    assertIsInstanceOf(Resequencer.class, channel.getNextProcessor());
}
Also used : DefaultChannel(org.apache.camel.processor.interceptor.DefaultChannel) StreamCaching(org.apache.camel.processor.interceptor.StreamCaching) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute) Route(org.apache.camel.Route) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute)

Example 77 with Route

use of org.apache.camel.Route in project camel by apache.

the class TemporalRule method getOverdueAction.

public Processor getOverdueAction() throws Exception {
    if (overdueAction == null && overdueProcessors != null) {
        RouteDefinition route = new RouteDefinition();
        RouteContext routeContext = new DefaultRouteContext(first.getBuilder().getProcessBuilder().getContext(), route, null, new ArrayList<Route>());
        overdueAction = overdueProcessors.createOutputsProcessor(routeContext);
    }
    return overdueAction;
}
Also used : DefaultRouteContext(org.apache.camel.impl.DefaultRouteContext) RouteDefinition(org.apache.camel.model.RouteDefinition) Route(org.apache.camel.Route) DefaultRouteContext(org.apache.camel.impl.DefaultRouteContext) RouteContext(org.apache.camel.spi.RouteContext)

Example 78 with Route

use of org.apache.camel.Route in project camel by apache.

the class DefaultRouteContext method commit.

public void commit() {
    // now lets turn all of the event driven consumer processors into a single route
    if (!eventDrivenProcessors.isEmpty()) {
        Processor target = Pipeline.newInstance(getCamelContext(), eventDrivenProcessors);
        // force creating the route id so its known ahead of the route is started
        String routeId = route.idOrCreate(getCamelContext().getNodeIdFactory());
        // and wrap it in a unit of work so the UoW is on the top, so the entire route will be in the same UoW
        CamelInternalProcessor internal = new CamelInternalProcessor(target);
        internal.addAdvice(new CamelInternalProcessor.UnitOfWorkProcessorAdvice(this));
        // and then optionally add route policy processor if a custom policy is set
        List<RoutePolicy> routePolicyList = getRoutePolicyList();
        if (routePolicyList != null && !routePolicyList.isEmpty()) {
            for (RoutePolicy policy : routePolicyList) {
                // this ensures Camel can control the lifecycle of the policy
                if (!camelContext.hasService(policy)) {
                    try {
                        camelContext.addService(policy);
                    } catch (Exception e) {
                        throw ObjectHelper.wrapRuntimeCamelException(e);
                    }
                }
            }
            internal.addAdvice(new CamelInternalProcessor.RoutePolicyAdvice(routePolicyList));
        }
        // wrap in route inflight processor to track number of inflight exchanges for the route
        internal.addAdvice(new CamelInternalProcessor.RouteInflightRepositoryAdvice(camelContext.getInflightRepository(), routeId));
        // wrap in JMX instrumentation processor that is used for performance stats
        internal.addAdvice(new CamelInternalProcessor.InstrumentationAdvice("route"));
        // wrap in route lifecycle
        internal.addAdvice(new CamelInternalProcessor.RouteLifecycleAdvice());
        // wrap in REST binding
        if (route.getRestBindingDefinition() != null) {
            try {
                internal.addAdvice(route.getRestBindingDefinition().createRestBindingAdvice(this));
            } catch (Exception e) {
                throw ObjectHelper.wrapRuntimeCamelException(e);
            }
        }
        // wrap in contract
        if (route.getInputType() != null || route.getOutputType() != null) {
            Contract contract = new Contract();
            if (route.getInputType() != null) {
                contract.setInputType(route.getInputType().getUrn());
                contract.setValidateInput(route.getInputType().isValidate());
            }
            if (route.getOutputType() != null) {
                contract.setOutputType(route.getOutputType().getUrn());
                contract.setValidateOutput(route.getOutputType().isValidate());
            }
            internal.addAdvice(new ContractAdvice(contract));
        }
        // and create the route that wraps the UoW
        Route edcr = new EventDrivenConsumerRoute(this, getEndpoint(), internal);
        edcr.getProperties().put(Route.ID_PROPERTY, routeId);
        edcr.getProperties().put(Route.PARENT_PROPERTY, Integer.toHexString(route.hashCode()));
        edcr.getProperties().put(Route.DESCRIPTION_PROPERTY, route.getDescriptionText());
        if (route.getGroup() != null) {
            edcr.getProperties().put(Route.GROUP_PROPERTY, route.getGroup());
        }
        String rest = "false";
        if (route.isRest() != null && route.isRest()) {
            rest = "true";
        }
        edcr.getProperties().put(Route.REST_PROPERTY, rest);
        // after the route is created then set the route on the policy processor so we get hold of it
        CamelInternalProcessor.RoutePolicyAdvice task = internal.getAdvice(CamelInternalProcessor.RoutePolicyAdvice.class);
        if (task != null) {
            task.setRoute(edcr);
        }
        CamelInternalProcessor.RouteLifecycleAdvice task2 = internal.getAdvice(CamelInternalProcessor.RouteLifecycleAdvice.class);
        if (task2 != null) {
            task2.setRoute(edcr);
        }
        // invoke init on route policy
        if (routePolicyList != null && !routePolicyList.isEmpty()) {
            for (RoutePolicy policy : routePolicyList) {
                policy.onInit(edcr);
            }
        }
        routes.add(edcr);
    }
}
Also used : CamelInternalProcessor(org.apache.camel.processor.CamelInternalProcessor) Processor(org.apache.camel.Processor) RoutePolicy(org.apache.camel.spi.RoutePolicy) NoSuchEndpointException(org.apache.camel.NoSuchEndpointException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) CamelInternalProcessor(org.apache.camel.processor.CamelInternalProcessor) ContractAdvice(org.apache.camel.processor.ContractAdvice) Contract(org.apache.camel.spi.Contract) Route(org.apache.camel.Route) ShutdownRoute(org.apache.camel.ShutdownRoute)

Example 79 with Route

use of org.apache.camel.Route in project camel by apache.

the class DefaultRouteStartupOrder method getInputs.

public List<Consumer> getInputs() {
    List<Consumer> answer = new ArrayList<Consumer>();
    Map<Route, Consumer> inputs = routeService.getInputs();
    for (Consumer consumer : inputs.values()) {
        answer.add(consumer);
    }
    return answer;
}
Also used : Consumer(org.apache.camel.Consumer) ArrayList(java.util.ArrayList) Route(org.apache.camel.Route)

Example 80 with Route

use of org.apache.camel.Route in project camel by apache.

the class RouteService method doStart.

protected void doStart() throws Exception {
    warmUp();
    for (Route route : routes) {
        try (MDCHelper mdcHelper = new MDCHelper(route.getId())) {
            // start the route itself
            ServiceHelper.startService(route);
            // invoke callbacks on route policy
            if (route.getRouteContext().getRoutePolicyList() != null) {
                for (RoutePolicy routePolicy : route.getRouteContext().getRoutePolicyList()) {
                    routePolicy.onStart(route);
                }
            }
            // fire event
            EventHelper.notifyRouteStarted(camelContext, route);
        }
    }
}
Also used : RoutePolicy(org.apache.camel.spi.RoutePolicy) Route(org.apache.camel.Route)

Aggregations

Route (org.apache.camel.Route)90 EventDrivenConsumerRoute (org.apache.camel.impl.EventDrivenConsumerRoute)27 Endpoint (org.apache.camel.Endpoint)24 Channel (org.apache.camel.Channel)17 DeadLetterChannel (org.apache.camel.processor.DeadLetterChannel)15 Processor (org.apache.camel.Processor)13 ArrayList (java.util.ArrayList)12 SendProcessor (org.apache.camel.processor.SendProcessor)11 CamelContext (org.apache.camel.CamelContext)10 ShutdownRoute (org.apache.camel.ShutdownRoute)8 FilterProcessor (org.apache.camel.processor.FilterProcessor)7 RoutePolicy (org.apache.camel.spi.RoutePolicy)6 HashMap (java.util.HashMap)5 Service (org.apache.camel.Service)5 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)4 DelegateProcessor (org.apache.camel.DelegateProcessor)4 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)4 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)4