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 org.apache.camel.CamelContext;
020import org.apache.camel.Endpoint;
021import org.apache.camel.Exchange;
022import org.apache.camel.Processor;
023import org.apache.camel.Route;
024
025/**
026 * Factory to create {@link CamelEvent events} that are emitted when such an event occur.
027 * <p/>
028 * For example when an {@link Exchange} is being created and then later when its done.
029 */
030public interface EventFactory {
031
032    /**
033     * Creates an {@link CamelEvent} for Camel is starting.
034     *
035     * @param context camel context
036     * @return the created event
037     */
038    CamelEvent createCamelContextStartingEvent(CamelContext context);
039
040    /**
041     * Creates an {@link CamelEvent} for Camel has been started successfully.
042     *
043     * @param context camel context
044     * @return the created event
045     */
046    CamelEvent createCamelContextStartedEvent(CamelContext context);
047
048    /**
049     * Creates an {@link CamelEvent} for Camel failing to start
050     *
051     * @param context camel context
052     * @param cause   the cause exception
053     * @return the created event
054     */
055    CamelEvent createCamelContextStartupFailureEvent(CamelContext context, Throwable cause);
056
057    /**
058     * Creates an {@link CamelEvent} for Camel failing to stop cleanly
059     *
060     * @param context camel context
061     * @param cause   the cause exception
062     * @return the created event
063     */
064    CamelEvent createCamelContextStopFailureEvent(CamelContext context, Throwable cause);
065
066    /**
067     * Creates an {@link CamelEvent} for Camel is stopping.
068     *
069     * @param context camel context
070     * @return the created event
071     */
072    CamelEvent createCamelContextStoppingEvent(CamelContext context);
073
074    /**
075     * Creates an {@link CamelEvent} for Camel has been stopped successfully.
076     *
077     * @param context camel context
078     * @return the created event
079     */
080    CamelEvent createCamelContextStoppedEvent(CamelContext context);
081
082    /**
083     * Creates an {@link CamelEvent} for Camel routes starting.
084     *
085     * @param context camel context
086     * @return the created event
087     */
088    CamelEvent createCamelContextRoutesStartingEvent(CamelContext context);
089
090    /**
091     * Creates an {@link CamelEvent} for Camel routes started.
092     *
093     * @param context camel context
094     * @return the created event
095     */
096    CamelEvent createCamelContextRoutesStartedEvent(CamelContext context);
097
098    /**
099     * Creates an {@link CamelEvent} for Camel routes stopping.
100     *
101     * @param context camel context
102     * @return the created event
103     */
104    CamelEvent createCamelContextRoutesStoppingEvent(CamelContext context);
105
106    /**
107     * Creates an {@link CamelEvent} for Camel routes stopped.
108     *
109     * @param context camel context
110     * @return the created event
111     */
112    CamelEvent createCamelContextRoutesStoppedEvent(CamelContext context);
113
114    /**
115     * Creates an {@link CamelEvent} for a Service failed to start cleanly
116     *
117     * @param context camel context
118     * @param service the service
119     * @param cause   the cause exception
120     * @return the created event
121     */
122    CamelEvent createServiceStartupFailureEvent(CamelContext context, Object service, Throwable cause);
123
124    /**
125     * Creates an {@link CamelEvent} for a Service failed to stop cleanly
126     *
127     * @param context camel context
128     * @param service the service
129     * @param cause   the cause exception
130     * @return the created event
131     */
132    CamelEvent createServiceStopFailureEvent(CamelContext context, Object service, Throwable cause);
133
134    /**
135     * Creates an {@link CamelEvent} for {@link Route} has been started successfully.
136     *
137     * @param route the route
138     * @return the created event
139     */
140    CamelEvent createRouteStartedEvent(Route route);
141
142    /**
143     * Creates an {@link CamelEvent} for {@link Route} has been stopped successfully.
144     *
145     * @param route the route
146     * @return the created event
147     */
148    CamelEvent createRouteStoppedEvent(Route route);
149
150    /**
151     * Creates an {@link CamelEvent} for {@link Route} has been added successfully.
152     *
153     * @param route the route
154     * @return the created event
155     */
156    CamelEvent createRouteAddedEvent(Route route);
157
158    /**
159     * Creates an {@link CamelEvent} for {@link Route} has been removed successfully.
160     *
161     * @param route the route
162     * @return the created event
163     */
164    CamelEvent createRouteRemovedEvent(Route route);
165
166    /**
167     * Creates an {@link CamelEvent} when an {@link org.apache.camel.Exchange} has been created
168     *
169     * @param exchange the exchange
170     * @return the created event
171     */
172    CamelEvent createExchangeCreatedEvent(Exchange exchange);
173
174    /**
175     * Creates an {@link CamelEvent} when an {@link org.apache.camel.Exchange} has been completed successfully
176     *
177     * @param exchange the exchange
178     * @return the created event
179     */
180    CamelEvent createExchangeCompletedEvent(Exchange exchange);
181
182    /**
183     * Creates an {@link CamelEvent} when an {@link org.apache.camel.Exchange} has failed
184     *
185     * @param exchange the exchange
186     * @return the created event
187     */
188    CamelEvent createExchangeFailedEvent(Exchange exchange);
189
190    /**
191     * Creates an {@link CamelEvent} when an {@link org.apache.camel.Exchange} has failed
192     * but is being handled by the Camel error handlers such as an dead letter channel, or a doTry .. doCatch block.
193     * <p/>
194     * This event is triggered <b>before</b> sending the failure handler, where as
195     * <tt>createExchangeFailureHandledEvent</tt> if the event <b>after</b>.
196     *
197     * @param exchange          the exchange
198     * @param failureHandler    the failure handler such as moving the message to a dead letter queue
199     * @param deadLetterChannel whether it was a dead letter channel or not handling the failure
200     * @param deadLetterUri     the dead letter uri, if its a dead letter channel
201     * @return the created event
202     */
203    CamelEvent createExchangeFailureHandlingEvent(Exchange exchange, Processor failureHandler,
204                                                   boolean deadLetterChannel, String deadLetterUri);
205
206    /**
207     * Creates an {@link CamelEvent} when an {@link org.apache.camel.Exchange} has failed
208     * but was handled by the Camel error handlers such as an dead letter channel, or a doTry .. doCatch block.
209     * <p/>
210     * This event is triggered <b>after</b> the exchange was sent to failure handler, where as
211     * <tt>createExchangeFailureHandlingEvent</tt> if the event <b>before</b>.
212     *
213     * @param exchange          the exchange
214     * @param failureHandler    the failure handler such as moving the message to a dead letter queue
215     * @param deadLetterChannel whether it was a dead letter channel or not handling the failure
216     * @param deadLetterUri     the dead letter uri, if its a dead letter channel
217     * @return the created event
218     */
219    CamelEvent createExchangeFailureHandledEvent(Exchange exchange, Processor failureHandler,
220                                                  boolean deadLetterChannel, String deadLetterUri);
221
222    /**
223     * Creates an {@link CamelEvent} when an {@link org.apache.camel.Exchange} is about to be redelivered
224     *
225     * @param exchange the exchange
226     * @param attempt  the current redelivery attempt (starts from 1)
227     * @return the created event
228     */
229    CamelEvent createExchangeRedeliveryEvent(Exchange exchange, int attempt);
230
231    /**
232     * Creates an {@link CamelEvent} when an {@link org.apache.camel.Exchange} is about to be sent to the endpoint (eg before).
233     *
234     * @param exchange  the exchange
235     * @param endpoint  the destination
236     * @return the created event
237     */
238    CamelEvent createExchangeSendingEvent(Exchange exchange, Endpoint endpoint);
239
240    /**
241     * Creates an {@link CamelEvent} when an {@link org.apache.camel.Exchange} has completely been sent to the endpoint (eg after).
242     *
243     * @param exchange  the exchange
244     * @param endpoint  the destination
245     * @param timeTaken time in millis taken
246     * @return the created event
247     */
248    CamelEvent createExchangeSentEvent(Exchange exchange, Endpoint endpoint, long timeTaken);
249
250    /**
251     * Creates an {@link CamelEvent} when a step has been started
252     *
253     * @param exchange the exchange
254     * @param stepId   the step id
255     * @return the created event
256     */
257    CamelEvent createStepStartedEvent(Exchange exchange, String stepId);
258
259    /**
260     * Creates an {@link CamelEvent} when a step has been completed successfully
261     *
262     * @param exchange the exchange
263     * @param stepId   the step id
264     * @return the created event
265     */
266    CamelEvent createStepCompletedEvent(Exchange exchange, String stepId);
267
268    /**
269     * Creates an {@link CamelEvent} when a step has failed
270     *
271     * @param exchange the exchange
272     * @param stepId   the step id
273     * @return the created event
274     */
275    CamelEvent createStepFailedEvent(Exchange exchange, String stepId);
276
277    /**
278     * Creates an {@link CamelEvent} for Camel is suspending.
279     *
280     * @param context camel context
281     * @return the created event
282     */
283    CamelEvent createCamelContextSuspendingEvent(CamelContext context);
284
285    /**
286     * Creates an {@link CamelEvent} for Camel has been suspended successfully.
287     *
288     * @param context camel context
289     * @return the created event
290     */
291    CamelEvent createCamelContextSuspendedEvent(CamelContext context);
292
293    /**
294     * Creates an {@link CamelEvent} for Camel is resuming.
295     *
296     * @param context camel context
297     * @return the created event
298     */
299    CamelEvent createCamelContextResumingEvent(CamelContext context);
300
301    /**
302     * Creates an {@link CamelEvent} for Camel has been resumed successfully.
303     *
304     * @param context camel context
305     * @return the created event
306     */
307    CamelEvent createCamelContextResumedEvent(CamelContext context);
308
309    /**
310     * Creates an {@link CamelEvent} for Camel failing to resume
311     *
312     * @param context camel context
313     * @param cause   the cause exception
314     * @return the created event
315     */
316    CamelEvent createCamelContextResumeFailureEvent(CamelContext context, Throwable cause);
317
318}