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 *
028 * @version $Revision: 885243 $
029 */
030 public interface RoutePolicy {
031
032 /**
033 * Callback invokes when an {@link Exchange} is started being routed on the given {@link Route}
034 *
035 * @param route the route where the exchange started from
036 * @param exchange the created exchange
037 */
038 void onExchangeBegin(Route route, Exchange exchange);
039
040 /**
041 * Callback invokes when an {@link Exchange} is done being routed, where it started from the given {@link Route}
042 * <p/>
043 * Notice this callback is invoked when the <b>Exchange</b> is done and the {@link Route} is the route where
044 * the {@link Exchange} was started. Most often its also the route where the exchange is done. However its
045 * possible to route an {@link Exchange} to other routes using endpoints such as
046 * <b>direct</b> or <b>seda</b>. Bottom line is that the {@link Route} parameter may not be the endpoint
047 * route and thus why we state its the starting route.
048 *
049 * @param route the route where the exchange started from
050 * @param exchange the created exchange
051 */
052 void onExchangeDone(Route route, Exchange exchange);
053 }