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 java.util.List; 020import java.util.Map; 021 022import org.apache.camel.CamelContext; 023import org.apache.camel.Endpoint; 024import org.apache.camel.EndpointAware; 025import org.apache.camel.Processor; 026import org.apache.camel.RuntimeConfiguration; 027import org.apache.camel.model.FromDefinition; 028import org.apache.camel.model.ProcessorDefinition; 029import org.apache.camel.model.RouteDefinition; 030 031/** 032 * The context used to activate new routing rules 033 * 034 * @version 035 */ 036public interface RouteContext extends RuntimeConfiguration, EndpointAware { 037 038 /** 039 * Gets the from type 040 * 041 * @return the from type 042 */ 043 FromDefinition getFrom(); 044 045 /** 046 * Get the route type 047 * 048 * @return the route type 049 */ 050 RouteDefinition getRoute(); 051 052 /** 053 * Gets the camel context 054 * 055 * @return the camel context 056 */ 057 CamelContext getCamelContext(); 058 059 /** 060 * Resolves an endpoint from the URI 061 * 062 * @param uri the URI 063 * @return the resolved endpoint 064 */ 065 Endpoint resolveEndpoint(String uri); 066 067 /** 068 * Resolves an endpoint from either a URI or a named reference 069 * 070 * @param uri the URI or 071 * @param ref the named reference 072 * @return the resolved endpoint 073 */ 074 Endpoint resolveEndpoint(String uri, String ref); 075 076 /** 077 * lookup an object by name and type 078 * 079 * @param name the name to lookup 080 * @param type the expected type 081 * @return the found object 082 */ 083 <T> T lookup(String name, Class<T> type); 084 085 /** 086 * lookup an object by name and type or throws {@link org.apache.camel.NoSuchBeanException} if not found. 087 * 088 * @param name the name to lookup 089 * @param type the expected type 090 * @return the found object 091 */ 092 <T> T mandatoryLookup(String name, Class<T> type); 093 094 /** 095 * lookup objects by type 096 * 097 * @param type the expected type 098 * @return the found objects with the name as the key in the map. Returns an empty map if none found. 099 */ 100 <T> Map<String, T> lookupByType(Class<T> type); 101 102 /** 103 * For completing the route creation, creating a single event driven route 104 * for the current from endpoint with any processors required 105 */ 106 void commit(); 107 108 /** 109 * Adds an event driven processor 110 * 111 * @param processor the processor 112 */ 113 void addEventDrivenProcessor(Processor processor); 114 115 /** 116 * This method retrieves the InterceptStrategy instances this route context. 117 * 118 * @return the strategy 119 */ 120 List<InterceptStrategy> getInterceptStrategies(); 121 122 /** 123 * This method sets the InterceptStrategy instances on this route context. 124 * 125 * @param interceptStrategies the strategies 126 */ 127 void setInterceptStrategies(List<InterceptStrategy> interceptStrategies); 128 129 /** 130 * Adds a InterceptStrategy to this route context 131 * 132 * @param interceptStrategy the strategy 133 */ 134 void addInterceptStrategy(InterceptStrategy interceptStrategy); 135 136 /** 137 * Sets a special intercept strategy for management. 138 * <p/> 139 * Is by default used to correlate managed performance counters with processors 140 * when the runtime route is being constructed 141 * 142 * @param interceptStrategy the managed intercept strategy 143 */ 144 void setManagedInterceptStrategy(InterceptStrategy interceptStrategy); 145 146 /** 147 * Gets the special managed intercept strategy if any 148 * 149 * @return the managed intercept strategy, or <tt>null</tt> if not managed 150 */ 151 InterceptStrategy getManagedInterceptStrategy(); 152 153 /** 154 * If this flag is true, {@link ProcessorDefinition#addRoutes(RouteContext, java.util.Collection)} 155 * will not add processor to addEventDrivenProcessor to the RouteContext and it 156 * will prevent from adding an EventDrivenRoute. 157 * 158 * @param value the flag 159 */ 160 void setIsRouteAdded(boolean value); 161 162 /** 163 * Returns the isRouteAdded flag 164 * 165 * @return the flag 166 */ 167 boolean isRouteAdded(); 168 169 /** 170 * Gets the route policy List 171 * 172 * @return the route policy list if any 173 */ 174 List<RoutePolicy> getRoutePolicyList(); 175 176 /** 177 * Sets a custom route policy List 178 * 179 * @param routePolicyList the custom route policy list 180 */ 181 void setRoutePolicyList(List<RoutePolicy> routePolicyList); 182 183 /** 184 * A private counter that increments, is used to as book keeping 185 * when building a route based on the model 186 * <p/> 187 * We need this special book keeping be able to assign the correct 188 * {@link org.apache.camel.model.ProcessorDefinition} to the {@link org.apache.camel.Channel} 189 * 190 * @param node the current node 191 * @return the current count 192 */ 193 int getAndIncrement(ProcessorDefinition<?> node); 194 195}