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 */
017package org.apache.camel.spi;
018
019import org.apache.camel.Exchange;
020import 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 * @see Route
030 */
031public interface RoutePolicy {
032
033    /**
034     * Callback invoked when the {@link Route} is being initialized
035     *
036     * @param route     the route being initialized
037     */
038    void onInit(Route route);
039
040    /**
041     * Callback invoked when the {@link Route} is being removed from {@link org.apache.camel.CamelContext}
042     *
043     * @param route     the route being removed
044     */
045    void onRemove(Route route);
046
047    /**
048     * Callback invoked when the {@link Route} is being started
049     *
050     * @param route     the route being started
051     */
052    void onStart(Route route);
053
054    /**
055     * Callback invoked when the {@link Route} is being stopped
056     *
057     * @param route     the route being stopped
058     */
059    void onStop(Route route);
060
061    /**
062     * Callback invoked when the {@link Route} is being suspended
063     *
064     * @param route     the route being suspended
065     */
066    void onSuspend(Route route);
067
068    /**
069     * Callback invoked when the {@link Route} is being resumed
070     *
071     * @param route     the route being resumed
072     */
073    void onResume(Route route);
074
075    /**
076     * Callback invoked when an {@link Exchange} is started being routed on the given {@link Route}
077     *
078     * @param route     the route where the exchange started from
079     * @param exchange  the created exchange
080     */
081    void onExchangeBegin(Route route, Exchange exchange);
082
083    /**
084     * Callback invoked when an {@link Exchange} is done being routed, where it started from the given {@link Route}
085     * <p/>
086     * Notice this callback is invoked when the <b>Exchange</b> is done and the {@link Route} is the route where
087     * the {@link Exchange} was started. Most often its also the route where the exchange is done. However its
088     * possible to route an {@link Exchange} to other routes using endpoints such as
089     * <b>direct</b> or <b>seda</b>. Bottom line is that the {@link Route} parameter may not be the endpoint
090     * route and thus why we state its the starting route.
091     *
092     * @param route     the route where the exchange started from
093     * @param exchange  the created exchange
094     */
095    void onExchangeDone(Route route, Exchange exchange);
096}