001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.camel.spi;
018    
019    import org.apache.camel.Exchange;
020    import org.apache.camel.Route;
021    
022    /**
023     * Policy for a {@link Route} which allows controlling the route at runtime.
024     * <p/>
025     * For example using the {@link org.apache.camel.impl.ThrottlingInflightRoutePolicy} to throttle the {@link Route}
026     * at runtime where it suspends and resume the {@link org.apache.camel.Route#getConsumer()}.
027     * <p/>
028     * See also {@link Route} class javadoc about controlling the lifecycle of a {@link Route}
029     *
030     * @version
031     * @see Route
032     */
033    public interface RoutePolicy {
034    
035        /**
036         * Callback invoked when the {@link Route} is being initialized
037         *
038         * @param route     the route being initialized
039         */
040        void onInit(Route route);
041    
042        /**
043         * Callback invoked when the {@link Route} is being removed from {@link org.apache.camel.CamelContext}
044         *
045         * @param route     the route being removed
046         */
047        void onRemove(Route route);
048    
049        /**
050         * Callback invoked when the {@link Route} is being started
051         *
052         * @param route     the route being started
053         */
054        void onStart(Route route);
055    
056        /**
057         * Callback invoked when the {@link Route} is being stopped
058         *
059         * @param route     the route being stopped
060         */
061        void onStop(Route route);
062    
063        /**
064         * Callback invoked when the {@link Route} is being suspended
065         *
066         * @param route     the route being suspended
067         */
068        void onSuspend(Route route);
069    
070        /**
071         * Callback invoked when the {@link Route} is being resumed
072         *
073         * @param route     the route being resumed
074         */
075        void onResume(Route route);
076    
077        /**
078         * Callback invoked when an {@link Exchange} is started being routed on the given {@link Route}
079         *
080         * @param route     the route where the exchange started from
081         * @param exchange  the created exchange
082         */
083        void onExchangeBegin(Route route, Exchange exchange);
084    
085        /**
086         * Callback invoked when an {@link Exchange} is done being routed, where it started from the given {@link Route}
087         * <p/>
088         * Notice this callback is invoked when the <b>Exchange</b> is done and the {@link Route} is the route where
089         * the {@link Exchange} was started. Most often its also the route where the exchange is done. However its
090         * possible to route an {@link Exchange} to other routes using endpoints such as
091         * <b>direct</b> or <b>seda</b>. Bottom line is that the {@link Route} parameter may not be the endpoint
092         * route and thus why we state its the starting route.
093         *
094         * @param route     the route where the exchange started from
095         * @param exchange  the created exchange
096         */
097        void onExchangeDone(Route route, Exchange exchange);
098    }