Search in sources :

Example 21 with Route

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

the class HazelcastRoutePolicy method startAllStoppedConsumers.

private synchronized void startAllStoppedConsumers() {
    try {
        for (Route route : suspendedRoutes) {
            LOGGER.debug("Starting consumer for {} ({})", route.getId(), route.getConsumer());
            startConsumer(route.getConsumer());
        }
        suspendedRoutes.clear();
    } catch (Exception e) {
        handleException(e);
    }
}
Also used : Route(org.apache.camel.Route)

Example 22 with Route

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

the class CollectionOfCustomRoutesTest method xtestGuice.

public void xtestGuice() throws Exception {
    Injector injector = Guice.createInjector(new MyModule());
    CamelContext camelContext = injector.getInstance(CamelContext.class);
    List<Route> list = camelContext.getRoutes();
    assertEquals("size of " + list, 2, list.size());
    GuiceTest.assertCamelContextRunningThenCloseInjector(injector);
}
Also used : CamelContext(org.apache.camel.CamelContext) Injector(com.google.inject.Injector) Route(org.apache.camel.Route)

Example 23 with Route

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

the class AbstractTransactionTest method getConditionalExceptionProcessor.

protected ConditionalExceptionProcessor getConditionalExceptionProcessor() {
    Route route = context.getRoutes().get(0);
    assertNotNull(route);
    return getConditionalExceptionProcessor(route);
}
Also used : Route(org.apache.camel.Route) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute)

Example 24 with Route

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

the class ScheduledJob method execute.

public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
    SchedulerContext schedulerContext;
    try {
        schedulerContext = jobExecutionContext.getScheduler().getContext();
    } catch (SchedulerException e) {
        throw new JobExecutionException("Failed to obtain scheduler context for job " + jobExecutionContext.getJobDetail().getName());
    }
    ScheduledJobState state = (ScheduledJobState) schedulerContext.get(jobExecutionContext.getJobDetail().getName());
    Action storedAction = state.getAction();
    Route storedRoute = state.getRoute();
    List<RoutePolicy> policyList = storedRoute.getRouteContext().getRoutePolicyList();
    for (RoutePolicy policy : policyList) {
        try {
            if (policy instanceof ScheduledRoutePolicy) {
                ((ScheduledRoutePolicy) policy).onJobExecute(storedAction, storedRoute);
            }
        } catch (Exception e) {
            throw new JobExecutionException("Failed to execute Scheduled Job for route " + storedRoute.getId() + " with trigger name: " + jobExecutionContext.getTrigger().getFullName(), e);
        }
    }
}
Also used : SchedulerException(org.quartz.SchedulerException) JobExecutionException(org.quartz.JobExecutionException) SchedulerContext(org.quartz.SchedulerContext) RoutePolicy(org.apache.camel.spi.RoutePolicy) Route(org.apache.camel.Route) JobExecutionException(org.quartz.JobExecutionException) SchedulerException(org.quartz.SchedulerException)

Example 25 with Route

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

the class CamelJob method lookupQuartzEndpoint.

private QuartzEndpoint lookupQuartzEndpoint(CamelContext camelContext, String endpointUri, Trigger trigger) throws JobExecutionException {
    String targetTriggerName = trigger.getName();
    String targetTriggerGroup = trigger.getGroup();
    LOG.debug("Looking up existing QuartzEndpoint with trigger {}.{}", targetTriggerName, targetTriggerGroup);
    try {
        // as we prefer to use the existing endpoint from the routes
        for (Route route : camelContext.getRoutes()) {
            Endpoint endpoint = route.getEndpoint();
            if (endpoint instanceof DelegateEndpoint) {
                endpoint = ((DelegateEndpoint) endpoint).getEndpoint();
            }
            if (endpoint instanceof QuartzEndpoint) {
                QuartzEndpoint quartzEndpoint = (QuartzEndpoint) endpoint;
                String triggerName = quartzEndpoint.getTrigger().getName();
                String triggerGroup = quartzEndpoint.getTrigger().getGroup();
                LOG.trace("Checking route trigger {}.{}", triggerName, triggerGroup);
                if (triggerName.equals(targetTriggerName) && triggerGroup.equals(targetTriggerGroup)) {
                    return (QuartzEndpoint) endpoint;
                }
            }
        }
    } catch (Exception e) {
        throw new JobExecutionException("Error lookup up existing QuartzEndpoint with trigger: " + trigger, e);
    }
    // fallback and lookup existing from registry (eg maybe a @Consume POJO with a quartz endpoint, and thus not from a route)
    if (camelContext.hasEndpoint(endpointUri) != null) {
        return camelContext.getEndpoint(endpointUri, QuartzEndpoint.class);
    } else {
        LOG.warn("Cannot find existing QuartzEndpoint with uri: {}. Creating new endpoint instance.", endpointUri);
        return camelContext.getEndpoint(endpointUri, QuartzEndpoint.class);
    }
}
Also used : JobExecutionException(org.quartz.JobExecutionException) Endpoint(org.apache.camel.Endpoint) DelegateEndpoint(org.apache.camel.DelegateEndpoint) DelegateEndpoint(org.apache.camel.DelegateEndpoint) Route(org.apache.camel.Route) JobExecutionException(org.quartz.JobExecutionException) SchedulerException(org.quartz.SchedulerException)

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