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 java.util.Collection;
020 import java.util.concurrent.ThreadPoolExecutor;
021
022 import org.apache.camel.CamelContext;
023 import org.apache.camel.Component;
024 import org.apache.camel.Endpoint;
025 import org.apache.camel.ErrorHandlerFactory;
026 import org.apache.camel.Processor;
027 import org.apache.camel.Route;
028 import org.apache.camel.Service;
029 import org.apache.camel.VetoCamelContextStartException;
030
031 /**
032 * Strategy for lifecycle notifications.
033 */
034 public interface LifecycleStrategy {
035
036 /**
037 * Notification on starting a {@link CamelContext}.
038 *
039 * @param context the camel context
040 * @throws VetoCamelContextStartException can be thrown to veto starting {@link CamelContext}.
041 * Any other runtime exceptions will be logged at <tt>WARN</tt> level by Camel will continue starting itself.
042 */
043 void onContextStart(CamelContext context) throws VetoCamelContextStartException;
044
045 /**
046 * Notification on stopping a {@link CamelContext}.
047 *
048 * @param context the camel context
049 */
050 void onContextStop(CamelContext context);
051
052 /**
053 * Notification on adding an {@link org.apache.camel.Component}.
054 *
055 * @param name the unique name of this component
056 * @param component the added component
057 */
058 void onComponentAdd(String name, Component component);
059
060 /**
061 * Notification on removing an {@link org.apache.camel.Component}.
062 *
063 * @param name the unique name of this component
064 * @param component the removed component
065 */
066 void onComponentRemove(String name, Component component);
067
068 /**
069 * Notification on adding an {@link Endpoint}.
070 *
071 * @param endpoint the added endpoint
072 */
073 void onEndpointAdd(Endpoint endpoint);
074
075 /**
076 * Notification on removing an {@link Endpoint}.
077 *
078 * @param endpoint the removed endpoint
079 */
080 void onEndpointRemove(Endpoint endpoint);
081
082 /**
083 * Notification on adding a {@link Service}.
084 *
085 * @param context the camel context
086 * @param service the added service
087 * @param route the route the service belongs to if any possible to determine
088 */
089 void onServiceAdd(CamelContext context, Service service, Route route);
090
091 /**
092 * Notification on removing a {@link Service}.
093 *
094 * @param context the camel context
095 * @param service the removed service
096 * @param route the route the service belongs to if any possible to determine
097 */
098 void onServiceRemove(CamelContext context, Service service, Route route);
099
100 /**
101 * Notification on adding {@link Route}(s).
102 *
103 * @param routes the added routes
104 */
105 void onRoutesAdd(Collection<Route> routes);
106
107 /**
108 * Notification on removing {@link Route}(s).
109 *
110 * @param routes the removed routes
111 */
112 void onRoutesRemove(Collection<Route> routes);
113
114 /**
115 * Notification on adding {@link RouteContext}(s).
116 *
117 * @param routeContext the added route context
118 */
119 void onRouteContextCreate(RouteContext routeContext);
120
121 /**
122 * Notification on adding error handler.
123 *
124 * @param routeContext the added route context
125 * @param errorHandler the error handler
126 * @param errorHandlerBuilder the error handler builder
127 */
128 void onErrorHandlerAdd(RouteContext routeContext, Processor errorHandler, ErrorHandlerFactory errorHandlerBuilder);
129
130 /**
131 * Notification on removing error handler.
132 *
133 * @param routeContext the removed route context
134 * @param errorHandler the error handler
135 * @param errorHandlerBuilder the error handler builder
136 */
137 void onErrorHandlerRemove(RouteContext routeContext, Processor errorHandler, ErrorHandlerFactory errorHandlerBuilder);
138
139 /**
140 * Notification on adding a thread pool.
141 *
142 * @param camelContext the camel context
143 * @param threadPool the thread pool
144 * @param id id of the thread pool (can be null in special cases)
145 * @param sourceId id of the source creating the thread pool (can be null in special cases)
146 * @param routeId id of the route for the source (is null if no source)
147 * @param threadPoolProfileId id of the thread pool profile, if used for creating this thread pool (can be null)
148 */
149 void onThreadPoolAdd(CamelContext camelContext, ThreadPoolExecutor threadPool, String id,
150 String sourceId, String routeId, String threadPoolProfileId);
151
152 /**
153 * Notification on removing a thread pool.
154 *
155 * @param camelContext the camel context
156 * @param threadPool the thread pool
157 */
158 void onThreadPoolRemove(CamelContext camelContext, ThreadPoolExecutor threadPool);
159
160 }