Search in sources :

Example 51 with Route

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

the class DefaultManagementLifecycleStrategy method onRoutesAdd.

public void onRoutesAdd(Collection<Route> routes) {
    for (Route route : routes) {
        // enabled, then enlist the route as a known route
        if (getCamelContext().getStatus().isStarting() || getManagementStrategy().getManagementAgent().getRegisterAlways() || getManagementStrategy().getManagementAgent().getRegisterNewRoutes()) {
            // register as known route id
            knowRouteIds.add(route.getId());
        }
        if (!shouldRegister(route, route)) {
            // avoid registering if not needed, skip to next route
            continue;
        }
        Object mr = getManagementObjectStrategy().getManagedObjectForRoute(camelContext, route);
        // skip already managed routes, for example if the route has been restarted
        if (getManagementStrategy().isManaged(mr, null)) {
            LOG.trace("The route is already managed: {}", route);
            continue;
        }
        // and set me as the counter
        if (route instanceof EventDrivenConsumerRoute) {
            EventDrivenConsumerRoute edcr = (EventDrivenConsumerRoute) route;
            Processor processor = edcr.getProcessor();
            if (processor instanceof CamelInternalProcessor && mr instanceof ManagedRoute) {
                CamelInternalProcessor internal = (CamelInternalProcessor) processor;
                ManagedRoute routeMBean = (ManagedRoute) mr;
                CamelInternalProcessor.InstrumentationAdvice task = internal.getAdvice(CamelInternalProcessor.InstrumentationAdvice.class);
                if (task != null) {
                    // we need to wrap the counter with the camel context so we get stats updated on the context as well
                    if (camelContextMBean != null) {
                        CompositePerformanceCounter wrapper = new CompositePerformanceCounter(routeMBean, camelContextMBean);
                        task.setCounter(wrapper);
                    } else {
                        task.setCounter(routeMBean);
                    }
                }
            }
        }
        try {
            manageObject(mr);
        } catch (JMException e) {
            LOG.warn("Could not register Route MBean", e);
        } catch (Exception e) {
            LOG.warn("Could not create Route MBean", e);
        }
    }
}
Also used : CamelInternalProcessor(org.apache.camel.processor.CamelInternalProcessor) CamelInternalProcessor(org.apache.camel.processor.CamelInternalProcessor) Processor(org.apache.camel.Processor) ManagedRoute(org.apache.camel.management.mbean.ManagedRoute) JMException(javax.management.JMException) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute) 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 52 with Route

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

the class StartStopAndShutdownRouteTest method testStartStopAndShutdownRoute.

public void testStartStopAndShutdownRoute() throws Exception {
    // there should still be 2 services on the route
    Route myRoute = context.getRoute("foo");
    int services = myRoute.getServices().size();
    assertTrue(services > 0);
    // stop the route
    context.stopRoute("foo");
    // there should still be the same number of services on the route
    assertEquals(services, myRoute.getServices().size());
    // shutting down the route, by stop and remove
    context.stopRoute("foo");
    context.removeRoute("foo");
    // and now no more services as the route is shutdown
    assertEquals(0, myRoute.getServices().size());
}
Also used : Route(org.apache.camel.Route)

Example 53 with Route

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

the class RoutePolicySupportTest method testLifecycleCallbacks.

@Test
public void testLifecycleCallbacks() throws Exception {
    Route route = context.getRoute("foo");
    assertEquals(ServiceStatus.Stopped, context.getRouteStatus("foo"));
    policy.startRoute(route);
    assertEquals(ServiceStatus.Started, context.getRouteStatus("foo"));
    policy.suspendRoute(route);
    assertEquals(ServiceStatus.Suspended, context.getRouteStatus("foo"));
    policy.resumeRoute(route);
    assertEquals(ServiceStatus.Started, context.getRouteStatus("foo"));
    policy.stopRoute(route);
    assertEquals(ServiceStatus.Stopped, context.getRouteStatus("foo"));
}
Also used : Route(org.apache.camel.Route) Test(org.junit.Test)

Example 54 with Route

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

the class RouteSedaStopStartTest method testStopStart.

public void testStopStart() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("A");
    template.sendBody("seda:foo", "A");
    assertMockEndpointsSatisfied();
    log.info("Stopping");
    // now suspend and dont expect a message to be routed
    resetMocks();
    mock.expectedMessageCount(0);
    context.stopRoute("foo");
    assertEquals("Stopped", context.getRouteStatus("foo").name());
    Route route = context.getRoute("foo");
    if (route instanceof StatefulService) {
        assertEquals("Stopped", ((StatefulService) route).getStatus().name());
    }
    template.sendBody("seda:foo", "B");
    mock.assertIsSatisfied(1000);
    log.info("Starting");
    // now resume and expect the previous message to be routed
    resetMocks();
    mock.expectedBodiesReceived("B");
    context.startRoute("foo");
    assertMockEndpointsSatisfied();
    assertEquals("Started", context.getRouteStatus("foo").name());
    route = context.getRoute("foo");
    if (route instanceof StatefulService) {
        assertEquals("Started", ((StatefulService) route).getStatus().name());
    }
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Route(org.apache.camel.Route) StatefulService(org.apache.camel.StatefulService)

Example 55 with Route

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

the class ConsulRoutePolicy method startAllStoppedConsumers.

private void startAllStoppedConsumers() {
    synchronized (lock) {
        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)

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