Search in sources :

Example 41 with Route

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

the class CamelContextFactoryBeanTest method testXMLRouteLoading.

public void testXMLRouteLoading() throws Exception {
    applicationContext = new ClassPathXmlApplicationContext("org/apache/camel/spring/camelContextFactoryBean.xml");
    CamelContext context = applicationContext.getBean("camel2", CamelContext.class);
    assertNotNull("No context found!", context);
    List<Route> routes = context.getRoutes();
    LOG.debug("Found routes: " + routes);
    assertNotNull("Should have found some routes", routes);
    assertEquals("One Route should be found", 1, routes.size());
    for (Route route : routes) {
        Endpoint key = route.getEndpoint();
        EventDrivenConsumerRoute consumerRoute = assertIsInstanceOf(EventDrivenConsumerRoute.class, route);
        Processor processor = consumerRoute.getProcessor();
        assertNotNull(processor);
        assertEndpointUri(key, "seda://test.c");
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) SpringCamelContext(org.apache.camel.spring.SpringCamelContext) Processor(org.apache.camel.Processor) Endpoint(org.apache.camel.Endpoint) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute) Route(org.apache.camel.Route) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute)

Example 42 with Route

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

the class AbstractLocalCamelController method getCamelContextInformation.

@Override
public Map<String, Object> getCamelContextInformation(String name) throws Exception {
    Map<String, Object> answer = new LinkedHashMap<String, Object>();
    CamelContext context = getLocalCamelContext(name);
    if (context != null) {
        answer.put("name", context.getName());
        answer.put("managementName", context.getManagementName());
        answer.put("version", context.getVersion());
        answer.put("status", context.getStatus().name());
        answer.put("uptime", context.getUptime());
        answer.put("suspended", context.getStatus().isSuspended());
        if (context.getManagementStrategy().getManagementAgent() != null) {
            String level = context.getManagementStrategy().getManagementAgent().getStatisticsLevel().name();
            answer.put("managementStatisticsLevel", level);
        }
        answer.put("allowUseOriginalMessage", context.isAllowUseOriginalMessage());
        answer.put("messageHistory", context.isMessageHistory());
        answer.put("tracing", context.isTracing());
        answer.put("shutdownTimeout", context.getShutdownStrategy().getTimeUnit().toSeconds(context.getShutdownStrategy().getTimeout()));
        answer.put("classResolver", context.getClassResolver().toString());
        answer.put("packageScanClassResolver", context.getPackageScanClassResolver().toString());
        answer.put("applicationContextClassLoader", context.getApplicationContextClassLoader().toString());
        for (Map.Entry<String, String> entry : context.getProperties().entrySet()) {
            answer.put("property." + entry.getKey(), entry.getValue());
        }
        long activeRoutes = 0;
        long inactiveRoutes = 0;
        List<Route> routeList = context.getRoutes();
        for (Route route : routeList) {
            if (context.getRouteStatus(route.getId()).isStarted()) {
                activeRoutes++;
            } else {
                inactiveRoutes++;
            }
        }
        answer.put("startedRoutes", activeRoutes);
        answer.put("totalRoutes", activeRoutes + inactiveRoutes);
        // add type converter details
        answer.put("typeConverter.numberOfTypeConverters", context.getTypeConverterRegistry().size());
        answer.put("typeConverter.statisticsEnabled", context.getTypeConverterRegistry().getStatistics().isStatisticsEnabled());
        answer.put("typeConverter.noopCounter", context.getTypeConverterRegistry().getStatistics().getNoopCounter());
        answer.put("typeConverter.attemptCounter", context.getTypeConverterRegistry().getStatistics().getAttemptCounter());
        answer.put("typeConverter.hitCounter", context.getTypeConverterRegistry().getStatistics().getHitCounter());
        answer.put("typeConverter.missCounter", context.getTypeConverterRegistry().getStatistics().getMissCounter());
        answer.put("typeConverter.failedCounter", context.getTypeConverterRegistry().getStatistics().getFailedCounter());
        // add async processor await manager details
        answer.put("asyncProcessorAwaitManager.size", context.getAsyncProcessorAwaitManager().size());
        answer.put("asyncProcessorAwaitManager.statisticsEnabled", context.getAsyncProcessorAwaitManager().getStatistics().isStatisticsEnabled());
        answer.put("asyncProcessorAwaitManager.threadsBlocked", context.getAsyncProcessorAwaitManager().getStatistics().getThreadsBlocked());
        answer.put("asyncProcessorAwaitManager.threadsInterrupted", context.getAsyncProcessorAwaitManager().getStatistics().getThreadsInterrupted());
        answer.put("asyncProcessorAwaitManager.totalDuration", context.getAsyncProcessorAwaitManager().getStatistics().getTotalDuration());
        answer.put("asyncProcessorAwaitManager.minDuration", context.getAsyncProcessorAwaitManager().getStatistics().getMinDuration());
        answer.put("asyncProcessorAwaitManager.maxDuration", context.getAsyncProcessorAwaitManager().getStatistics().getMaxDuration());
        answer.put("asyncProcessorAwaitManager.meanDuration", context.getAsyncProcessorAwaitManager().getStatistics().getMeanDuration());
        // add stream caching details if enabled
        if (context.getStreamCachingStrategy().isEnabled()) {
            answer.put("streamCachingEnabled", true);
            answer.put("streamCaching.spoolDirectory", context.getStreamCachingStrategy().getSpoolDirectory());
            answer.put("streamCaching.spoolChiper", context.getStreamCachingStrategy().getSpoolChiper());
            answer.put("streamCaching.spoolThreshold", context.getStreamCachingStrategy().getSpoolThreshold());
            answer.put("streamCaching.spoolUsedHeapMemoryThreshold", context.getStreamCachingStrategy().getSpoolUsedHeapMemoryThreshold());
            answer.put("streamCaching.spoolUsedHeapMemoryLimit", context.getStreamCachingStrategy().getSpoolUsedHeapMemoryLimit());
            answer.put("streamCaching.anySpoolRules", context.getStreamCachingStrategy().isAnySpoolRules());
            answer.put("streamCaching.bufferSize", context.getStreamCachingStrategy().getBufferSize());
            answer.put("streamCaching.removeSpoolDirectoryWhenStopping", context.getStreamCachingStrategy().isRemoveSpoolDirectoryWhenStopping());
            answer.put("streamCaching.statisticsEnabled", context.getStreamCachingStrategy().getStatistics().isStatisticsEnabled());
            if (context.getStreamCachingStrategy().getStatistics().isStatisticsEnabled()) {
                answer.put("streamCaching.cacheMemoryCounter", context.getStreamCachingStrategy().getStatistics().getCacheMemoryCounter());
                answer.put("streamCaching.cacheMemorySize", context.getStreamCachingStrategy().getStatistics().getCacheMemorySize());
                answer.put("streamCaching.cacheMemoryAverageSize", context.getStreamCachingStrategy().getStatistics().getCacheMemoryAverageSize());
                answer.put("streamCaching.cacheSpoolCounter", context.getStreamCachingStrategy().getStatistics().getCacheSpoolCounter());
                answer.put("streamCaching.cacheSpoolSize", context.getStreamCachingStrategy().getStatistics().getCacheSpoolSize());
                answer.put("streamCaching.cacheSpoolAverageSize", context.getStreamCachingStrategy().getStatistics().getCacheSpoolAverageSize());
            }
        } else {
            answer.put("streamCachingEnabled", false);
        }
    }
    return answer;
}
Also used : CamelContext(org.apache.camel.CamelContext) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Route(org.apache.camel.Route) LinkedHashMap(java.util.LinkedHashMap)

Example 43 with Route

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

the class AbstractLocalCamelController method getRoutes.

public List<Map<String, String>> getRoutes(String camelContextName, String filter) throws Exception {
    List<Map<String, String>> answer = new ArrayList<Map<String, String>>();
    if (camelContextName != null) {
        CamelContext context = this.getLocalCamelContext(camelContextName);
        if (context != null) {
            for (Route route : context.getRoutes()) {
                if (filter == null || route.getId().matches(filter)) {
                    Map<String, String> row = new LinkedHashMap<String, String>();
                    row.put("camelContextName", context.getName());
                    row.put("routeId", route.getId());
                    row.put("state", getRouteState(route));
                    row.put("uptime", route.getUptime());
                    ManagedRouteMBean mr = context.getManagedRoute(route.getId(), ManagedRouteMBean.class);
                    if (mr != null) {
                        row.put("exchangesTotal", "" + mr.getExchangesTotal());
                        row.put("exchangesInflight", "" + mr.getExchangesInflight());
                        row.put("exchangesFailed", "" + mr.getExchangesFailed());
                    } else {
                        row.put("exchangesTotal", "0");
                        row.put("exchangesInflight", "0");
                        row.put("exchangesFailed", "0");
                    }
                    answer.add(row);
                }
            }
        }
    } else {
        List<Map<String, String>> camelContexts = this.getCamelContexts();
        for (Map<String, String> row : camelContexts) {
            List<Map<String, String>> routes = getRoutes(row.get("name"), filter);
            answer.addAll(routes);
        }
    }
    // sort the list
    Collections.sort(answer, new Comparator<Map<String, String>>() {

        @Override
        public int compare(Map<String, String> o1, Map<String, String> o2) {
            // group by camel context first, then by route name
            String c1 = o1.get("camelContextName");
            String c2 = o2.get("camelContextName");
            int answer = c1.compareTo(c2);
            if (answer == 0) {
                // okay from same camel context, then sort by route id
                answer = o1.get("routeId").compareTo(o2.get("routeId"));
            }
            return answer;
        }
    });
    return answer;
}
Also used : CamelContext(org.apache.camel.CamelContext) ManagedRouteMBean(org.apache.camel.api.management.mbean.ManagedRouteMBean) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Route(org.apache.camel.Route) LinkedHashMap(java.util.LinkedHashMap)

Example 44 with Route

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

the class SpringXmlRouteBuilderTest method getRoutesFromContext.

protected List<Route> getRoutesFromContext(String classpathConfigFile) {
    applicationContext = new ClassPathXmlApplicationContext(classpathConfigFile);
    SpringCamelContext context = applicationContext.getBeansOfType(SpringCamelContext.class).values().iterator().next();
    assertNotNull("No Camel Context in file: " + classpathConfigFile, context);
    List<Route> routes = context.getRoutes();
    assertNotNull("No routes available for context: " + context.getName() + " in file: " + classpathConfigFile, routes);
    return routes;
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SpringCamelContext(org.apache.camel.spring.SpringCamelContext) Route(org.apache.camel.Route)

Example 45 with Route

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

the class CuratorLeaderRoutePolicy method startAllStoppedRoutes.

private void startAllStoppedRoutes() {
    try {
        lock.lock();
        if (!suspendedRoutes.isEmpty()) {
            if (log.isDebugEnabled()) {
                log.debug("{} route(s) have been stopped previously by policy, restarting.", suspendedRoutes.size());
            }
            for (Route suspended : suspendedRoutes) {
                log.debug("Starting route {}.", suspended.getId());
                startRoute(suspended);
            }
            suspendedRoutes.clear();
        }
    } catch (Exception e) {
        handleException(e);
    } finally {
        lock.unlock();
    }
}
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