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