| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||
| CamelContext |
|
| 0.0;0 |
| 1 | /** |
|
| 2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
| 3 | * contributor license agreements. See the NOTICE file distributed with |
|
| 4 | * this work for additional information regarding copyright ownership. |
|
| 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
| 6 | * (the "License"); you may not use this file except in compliance with |
|
| 7 | * the License. You may obtain a copy of the License at |
|
| 8 | * |
|
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
| 10 | * |
|
| 11 | * Unless required by applicable law or agreed to in writing, software |
|
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
| 14 | * See the License for the specific language governing permissions and |
|
| 15 | * limitations under the License. |
|
| 16 | */ |
|
| 17 | package org.apache.camel; |
|
| 18 | ||
| 19 | import java.util.Collection; |
|
| 20 | import java.util.List; |
|
| 21 | import java.util.concurrent.Callable; |
|
| 22 | ||
| 23 | import org.apache.camel.builder.RouteBuilder; |
|
| 24 | import org.apache.camel.spi.ExchangeConverter; |
|
| 25 | import org.apache.camel.spi.Injector; |
|
| 26 | import org.apache.camel.spi.Language; |
|
| 27 | import org.apache.camel.spi.Registry; |
|
| 28 | ||
| 29 | /** |
|
| 30 | * Interface used to represent the context used to configure routes and the |
|
| 31 | * policies to use during message exchanges between endpoints. |
|
| 32 | * |
|
| 33 | * @version $Revision: 565270 $ |
|
| 34 | */ |
|
| 35 | public interface CamelContext extends Service { |
|
| 36 | ||
| 37 | // Component Management Methods |
|
| 38 | //----------------------------------------------------------------------- |
|
| 39 | ||
| 40 | /** |
|
| 41 | * Adds a component to the context. |
|
| 42 | */ |
|
| 43 | void addComponent(String componentName, Component component); |
|
| 44 | ||
| 45 | /** |
|
| 46 | * Gets a component from the context by name. |
|
| 47 | */ |
|
| 48 | Component getComponent(String componentName); |
|
| 49 | ||
| 50 | /** |
|
| 51 | * Gets a component from the context by name and specifying the expected type of component. |
|
| 52 | */ |
|
| 53 | <T extends Component> T getComponent(String name, Class<T> componentType); |
|
| 54 | ||
| 55 | /** |
|
| 56 | * Removes a previously added component. |
|
| 57 | * |
|
| 58 | * @param componentName |
|
| 59 | * @return the previously added component or null if it had not been previously added. |
|
| 60 | */ |
|
| 61 | Component removeComponent(String componentName); |
|
| 62 | ||
| 63 | /** |
|
| 64 | * Gets the a previously added component by name or lazily creates the component |
|
| 65 | * using the factory Callback. |
|
| 66 | * |
|
| 67 | * @param componentName the name of the component |
|
| 68 | * @param factory used to create a new component instance if the component was not previously added. |
|
| 69 | * @return |
|
| 70 | */ |
|
| 71 | Component getOrCreateComponent(String componentName, Callable<Component> factory); |
|
| 72 | ||
| 73 | // Endpoint Management Methods |
|
| 74 | //----------------------------------------------------------------------- |
|
| 75 | ||
| 76 | /** |
|
| 77 | * Resolves the given URI to an {@see Endpoint}. If the URI has a singleton endpoint |
|
| 78 | * registered, then the singleton is returned. Otherwise, a new {@see Endpoint} is created |
|
| 79 | * and if the endpoint is a singleton it is registered as a singleton endpoint. |
|
| 80 | */ |
|
| 81 | Endpoint getEndpoint(String uri); |
|
| 82 | ||
| 83 | /** |
|
| 84 | * Resolves the given URI to an {@see Endpoint} of the specified type. |
|
| 85 | * If the URI has a singleton endpoint registered, then the singleton is returned. |
|
| 86 | * Otherwise, a new {@see Endpoint} is created and if the endpoint is a |
|
| 87 | * singleton it is registered as a singleton endpoint. |
|
| 88 | */ |
|
| 89 | <T extends Endpoint> T getEndpoint(String name, Class<T> endpointType); |
|
| 90 | ||
| 91 | /** |
|
| 92 | * Returns the collection of all registered singleton endpoints. |
|
| 93 | */ |
|
| 94 | Collection<Endpoint> getSingletonEndpoints(); |
|
| 95 | ||
| 96 | /** |
|
| 97 | * Adds the endpoint to the context using the given URI. The endpoint will be registered as a singleton. |
|
| 98 | * |
|
| 99 | * @param uri the URI to be used to resolve this endpoint |
|
| 100 | * @param endpoint the endpoint to be added to the context |
|
| 101 | * @return the old endpoint that was previously registered to the context if there was |
|
| 102 | * already an endpoint for that URI |
|
| 103 | * @throws Exception if the new endpoint could not be started or the old endpoint could not be stopped |
|
| 104 | */ |
|
| 105 | Endpoint addSingletonEndpoint(String uri, Endpoint endpoint) throws Exception; |
|
| 106 | ||
| 107 | /** |
|
| 108 | * Removes the singleton endpoint with the given URI |
|
| 109 | * |
|
| 110 | * @param uri the URI to be used to remove |
|
| 111 | * @return the endpoint that was removed or null if there is no endpoint for this URI |
|
| 112 | * @throws Exception if endpoint could not be stopped |
|
| 113 | */ |
|
| 114 | Endpoint removeSingletonEndpoint(String uri) throws Exception; |
|
| 115 | ||
| 116 | ||
| 117 | // Route Management Methods |
|
| 118 | //----------------------------------------------------------------------- |
|
| 119 | ||
| 120 | /** |
|
| 121 | * Returns the current routes in this context |
|
| 122 | * |
|
| 123 | * @return the current routes in this context |
|
| 124 | */ |
|
| 125 | List<Route> getRoutes(); |
|
| 126 | ||
| 127 | /** |
|
| 128 | * Sets the routes for this context, replacing any current routes |
|
| 129 | * |
|
| 130 | * @param routes the new routes to use |
|
| 131 | */ |
|
| 132 | void setRoutes(List<Route> routes); |
|
| 133 | ||
| 134 | /** |
|
| 135 | * Adds a collection of routes to this context |
|
| 136 | * |
|
| 137 | * @param routes the routes to add |
|
| 138 | */ |
|
| 139 | void addRoutes(Collection<Route> routes) throws Exception; |
|
| 140 | ||
| 141 | /** |
|
| 142 | * Adds a collection of routes to this context using the given builder |
|
| 143 | * to build them |
|
| 144 | * |
|
| 145 | * @param builder the builder which will create the routes and add them to this context |
|
| 146 | * @throws Exception if the routes could not be created for whatever reason |
|
| 147 | */ |
|
| 148 | void addRoutes(RouteBuilder builder) throws Exception; |
|
| 149 | ||
| 150 | // Properties |
|
| 151 | //----------------------------------------------------------------------- |
|
| 152 | ||
| 153 | /** |
|
| 154 | * Returns the converter of exchanges from one type to another |
|
| 155 | * @return |
|
| 156 | */ |
|
| 157 | ExchangeConverter getExchangeConverter(); |
|
| 158 | ||
| 159 | /** |
|
| 160 | * Returns the type converter used to coerce types from one type to another |
|
| 161 | */ |
|
| 162 | TypeConverter getTypeConverter(); |
|
| 163 | ||
| 164 | /** |
|
| 165 | * Returns the registry used to lookup components by name and type such as the Spring ApplicationContext, |
|
| 166 | * JNDI or the OSGi Service Registry |
|
| 167 | */ |
|
| 168 | Registry getRegistry(); |
|
| 169 | ||
| 170 | /** |
|
| 171 | * Returns the injector used to instantiate objects by type |
|
| 172 | */ |
|
| 173 | Injector getInjector(); |
|
| 174 | ||
| 175 | /** |
|
| 176 | * Returns the lifecycle strategy used to handle lifecycle notification |
|
| 177 | */ |
|
| 178 | LifecycleStrategy getLifecycleStrategy(); |
|
| 179 | ||
| 180 | /** |
|
| 181 | * Resolves a language for creating expressions |
|
| 182 | */ |
|
| 183 | Language resolveLanguage(String language); |
|
| 184 | ||
| 185 | } |