Search in sources :

Example 16 with Route

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

the class RandomLoadBalanceJavaDSLBuilderTest method testNavigateRouteAsJavaDSLWithNavigate.

public void testNavigateRouteAsJavaDSLWithNavigate() throws Exception {
    // this one navigate using the runtime route using the Navigate<Processor>
    StringBuilder sb = new StringBuilder();
    Route route = context.getRoutes().get(0);
    // the start of the route
    sb.append("from(\"" + route.getEndpoint().getEndpointUri() + "\")");
    // navigate the route and add Java DSL to the sb
    Navigate<Processor> nav = route.navigate();
    navigateRoute(nav, sb);
    // output the Java DSL
    assertEquals("from(\"direct://start\").loadBalance().random().to(\"mock://x\").to(\"mock://y\").to(\"mock://z\")", sb.toString());
}
Also used : Processor(org.apache.camel.Processor) Route(org.apache.camel.Route)

Example 17 with Route

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

the class DefaultCamelContext method doSuspend.

@Override
protected void doSuspend() throws Exception {
    EventHelper.notifyCamelContextSuspending(this);
    log.info("Apache Camel " + getVersion() + " (CamelContext: " + getName() + ") is suspending");
    StopWatch watch = new StopWatch();
    // (so when we resume we only resume the routes which actually was suspended)
    for (Map.Entry<String, RouteService> entry : getRouteServices().entrySet()) {
        if (entry.getValue().getStatus().isStarted()) {
            suspendedRouteServices.put(entry.getKey(), entry.getValue());
        }
    }
    // assemble list of startup ordering so routes can be shutdown accordingly
    List<RouteStartupOrder> orders = new ArrayList<RouteStartupOrder>();
    for (Map.Entry<String, RouteService> entry : suspendedRouteServices.entrySet()) {
        Route route = entry.getValue().getRoutes().iterator().next();
        Integer order = entry.getValue().getRouteDefinition().getStartupOrder();
        if (order == null) {
            order = defaultRouteStartupOrder++;
        }
        orders.add(new DefaultRouteStartupOrder(order, route, entry.getValue()));
    }
    // suspend routes using the shutdown strategy so it can shutdown in correct order
    // routes which doesn't support suspension will be stopped instead
    getShutdownStrategy().suspend(this, orders);
    // mark the route services as suspended or stopped
    for (RouteService service : suspendedRouteServices.values()) {
        if (routeSupportsSuspension(service.getId())) {
            service.suspend();
        } else {
            service.stop();
        }
    }
    watch.stop();
    if (log.isInfoEnabled()) {
        log.info("Apache Camel " + getVersion() + " (CamelContext: " + getName() + ") is suspended in " + TimeUtils.printDuration(watch.taken()));
    }
    EventHelper.notifyCamelContextSuspended(this);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) RouteStartupOrder(org.apache.camel.spi.RouteStartupOrder) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ShutdownRoute(org.apache.camel.ShutdownRoute) Route(org.apache.camel.Route) StopWatch(org.apache.camel.util.StopWatch)

Example 18 with Route

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

the class DefaultManagementLifecycleStrategy method onRoutesRemove.

public void onRoutesRemove(Collection<Route> routes) {
    // the agent hasn't been started
    if (!initialized) {
        return;
    }
    for (Route route : routes) {
        Object mr = getManagementObjectStrategy().getManagedObjectForRoute(camelContext, route);
        // skip unmanaged routes
        if (!getManagementStrategy().isManaged(mr, null)) {
            LOG.trace("The route is not managed: {}", route);
            continue;
        }
        try {
            unmanageObject(mr);
        } catch (Exception e) {
            LOG.warn("Could not unregister Route MBean", e);
        }
        // remove from known routes ids, as the route has been removed
        knowRouteIds.remove(route.getId());
    }
    // after the routes has been removed, we should clear the wrapped processors as we no longer need them
    // as they were just a provisional map used during creation of routes
    removeWrappedProcessorsForRoutes(routes);
}
Also used : ManagedRoute(org.apache.camel.management.mbean.ManagedRoute) Route(org.apache.camel.Route) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute) MalformedObjectNameException(javax.management.MalformedObjectNameException) JMException(javax.management.JMException) VetoCamelContextStartException(org.apache.camel.VetoCamelContextStartException)

Example 19 with Route

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

the class DefaultManagementLifecycleStrategy method removeWrappedProcessorsForRoutes.

/**
     * Removes the wrapped processors for the given routes, as they are no longer in use.
     * <p/>
     * This is needed to avoid accumulating memory, if a lot of routes is being added and removed.
     *
     * @param routes the routes
     */
private void removeWrappedProcessorsForRoutes(Collection<Route> routes) {
    // loop the routes, and remove the route associated wrapped processors, as they are no longer in use
    for (Route route : routes) {
        String id = route.getId();
        Iterator<KeyValueHolder<ProcessorDefinition<?>, InstrumentationProcessor>> it = wrappedProcessors.values().iterator();
        while (it.hasNext()) {
            KeyValueHolder<ProcessorDefinition<?>, InstrumentationProcessor> holder = it.next();
            RouteDefinition def = ProcessorDefinitionHelper.getRoute(holder.getKey());
            if (def != null && id.equals(def.getId())) {
                it.remove();
            }
        }
    }
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition) ProcessorDefinition(org.apache.camel.model.ProcessorDefinition) KeyValueHolder(org.apache.camel.util.KeyValueHolder) ManagedRoute(org.apache.camel.management.mbean.ManagedRoute) Route(org.apache.camel.Route) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute)

Example 20 with Route

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

the class StreamResequencerTest method doTestStreamResequencerType.

protected void doTestStreamResequencerType() 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);
    Channel channel = unwrapChannel(consumerRoute.getProcessor());
    assertIsInstanceOf(DefaultErrorHandler.class, channel.getErrorHandler());
    assertIsInstanceOf(StreamResequencer.class, channel.getNextProcessor());
}
Also used : Channel(org.apache.camel.Channel) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute) Route(org.apache.camel.Route) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute)

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