Route adding process for camel

Source: Internet
Author: User

The camel route adding method is generally implemented by calling the addroutes (routesbuilder builder) method of camelcontext. Let's take a look at how this method adds a route:

Public void addroutes (routesbuilder builder) throws exception {// call the addroutestocamelcontext method of routebuilder and pass camelcontext as a parameter to builder. addroutestocamelcontext (this );}

The following is the source code of the addroutestocamelcontext method:

public void addRoutesToCamelContext(CamelContext context) throws Exception {    configureRoutes((ModelCamelContext)context);    populateRoutes();}

Here we call two methods. Let's first look at the assumeroutes method. The work of this method is to configure the route:

public RoutesDefinition configureRoutes(ModelCamelContext context) throws Exception {    setContext(context);    checkInitialized();    routeCollection.setCamelContext(context);    return routeCollection;}

The most important of this is the checkinitialized method. The others are very simple. Let's take a look at the checkinitialized method:

protected void checkInitialized() throws Exception {    if (initialized.compareAndSet(false, true)) {        ModelCamelContext camelContext = getContext();        if (camelContext.getErrorHandlerBuilder() != null) {            setErrorHandlerBuilder(camelContext.getErrorHandlerBuilder());        }        configure();        for (RouteDefinition route : getRouteCollection().getRoutes()) {            route.markPrepared();        }    }}

This method is first checked for initialization. If it is the first execution, it is certainly not initialized. If it will execute the configure () method, this method is implemented when we create a routebuilder object. In this method, the configuration and creation of routedefinition are completed. After the configure () method is executed, all route entries are traversed and marked as pre-processed.

Next let's take a look at the populateroutes () method. In this method, we will add the routing definition to the camelcontext:

Protected void populateroutes () throws exception {modelcamelcontext camelcontext = getcontext (); If (camelcontext = NULL) {Throw new illegalargumentexception ("camelcontext has not been injected! ");} Getroutecollection (). setcamelcontext (camelcontext); // remove all route definitions and add them to camelcontext. addroutedefinitions (getroutecollection (). getroutes ());}

The following is the addroutedefinitions source code of camelcontext:

Public synchronized void addroutedefinitions (collection <routedefinition> routedefinitions) throws exception {// traverse all route definitions for (routedefinition: routedefinitions) {// if the route definition already exists, remove the original definition removeroutedefinition (routedefinition);} // Add all the route definitions to this in the route definition set. routedefinitions. addall (routedefinitions); // determines whether to start the route if (shouldstartroutes () {startroutedefinitions (routedefinitions );}}

In the shouldstartroutes method, true is returned if camelcontext is started and not during startup. Therefore, after camelcontext is started, adding a new route definition will automatically start the route definition.

After creating the route and drop configurations, the following is the most important process: the execution process of the route definition, that is, the START process of the route definition ......

Route adding process for camel

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.