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 a Service failed to start cleanly
084     *
085     * @param context camel context
086     * @param service the service
087     * @param cause   the cause exception
088     * @return the created event
089     */
090    CamelEvent createServiceStartupFailureEvent(CamelContext context, Object service, Throwable cause);
091
092    /**
093     * Creates an {@link CamelEvent} for a Service failed to stop cleanly
094     *
095     * @param context camel context
096     * @param service the service
097     * @param cause   the cause exception
098     * @return the created event
099     */
100    CamelEvent createServiceStopFailureEvent(CamelContext context, Object service, Throwable cause);
101
102    /**
103     * Creates an {@link CamelEvent} for {@link Route} has been started successfully.
104     *
105     * @param route the route
106     * @return the created event
107     */
108    CamelEvent createRouteStartedEvent(Route route);
109
110    /**
111     * Creates an {@link CamelEvent} for {@link Route} has been stopped successfully.
112     *
113     * @param route the route
114     * @return the created event
115     */
116    CamelEvent createRouteStoppedEvent(Route route);
117
118    /**
119     * Creates an {@link CamelEvent} for {@link Route} has been added successfully.
120     *
121     * @param route the route
122     * @return the created event
123     */
124    CamelEvent createRouteAddedEvent(Route route);
125
126    /**
127     * Creates an {@link CamelEvent} for {@link Route} has been removed successfully.
128     *
129     * @param route the route
130     * @return the created event
131     */
132    CamelEvent createRouteRemovedEvent(Route route);
133
134    /**
135     * Creates an {@link CamelEvent} when an {@link org.apache.camel.Exchange} has been created
136     *
137     * @param exchange the exchange
138     * @return the created event
139     */
140    CamelEvent createExchangeCreatedEvent(Exchange exchange);
141
142    /**
143     * Creates an {@link CamelEvent} when an {@link org.apache.camel.Exchange} has been completed successfully
144     *
145     * @param exchange the exchange
146     * @return the created event
147     */
148    CamelEvent createExchangeCompletedEvent(Exchange exchange);
149
150    /**
151     * Creates an {@link CamelEvent} when an {@link org.apache.camel.Exchange} has failed
152     *
153     * @param exchange the exchange
154     * @return the created event
155     */
156    CamelEvent createExchangeFailedEvent(Exchange exchange);
157
158    /**
159     * Creates an {@link CamelEvent} when an {@link org.apache.camel.Exchange} has failed
160     * but is being handled by the Camel error handlers such as an dead letter channel, or a doTry .. doCatch block.
161     * <p/>
162     * This event is triggered <b>before</b> sending the failure handler, where as
163     * <tt>createExchangeFailureHandledEvent</tt> if the event <b>after</b>.
164     *
165     * @param exchange          the exchange
166     * @param failureHandler    the failure handler such as moving the message to a dead letter queue
167     * @param deadLetterChannel whether it was a dead letter channel or not handling the failure
168     * @param deadLetterUri     the dead letter uri, if its a dead letter channel
169     * @return the created event
170     */
171    CamelEvent createExchangeFailureHandlingEvent(Exchange exchange, Processor failureHandler,
172                                                   boolean deadLetterChannel, String deadLetterUri);
173
174    /**
175     * Creates an {@link CamelEvent} when an {@link org.apache.camel.Exchange} has failed
176     * but was handled by the Camel error handlers such as an dead letter channel, or a doTry .. doCatch block.
177     * <p/>
178     * This event is triggered <b>after</b> the exchange was sent to failure handler, where as
179     * <tt>createExchangeFailureHandlingEvent</tt> if the event <b>before</b>.
180     *
181     * @param exchange          the exchange
182     * @param failureHandler    the failure handler such as moving the message to a dead letter queue
183     * @param deadLetterChannel whether it was a dead letter channel or not handling the failure
184     * @param deadLetterUri     the dead letter uri, if its a dead letter channel
185     * @return the created event
186     */
187    CamelEvent createExchangeFailureHandledEvent(Exchange exchange, Processor failureHandler,
188                                                  boolean deadLetterChannel, String deadLetterUri);
189
190    /**
191     * Creates an {@link CamelEvent} when an {@link org.apache.camel.Exchange} is about to be redelivered
192     *
193     * @param exchange the exchange
194     * @param attempt  the current redelivery attempt (starts from 1)
195     * @return the created event
196     */
197    CamelEvent createExchangeRedeliveryEvent(Exchange exchange, int attempt);
198
199    /**
200     * Creates an {@link CamelEvent} when an {@link org.apache.camel.Exchange} is about to be sent to the endpoint (eg before).
201     *
202     * @param exchange  the exchange
203     * @param endpoint  the destination
204     * @return the created event
205     */
206    CamelEvent createExchangeSendingEvent(Exchange exchange, Endpoint endpoint);
207
208    /**
209     * Creates an {@link CamelEvent} when an {@link org.apache.camel.Exchange} has completely been sent to the endpoint (eg after).
210     *
211     * @param exchange  the exchange
212     * @param endpoint  the destination
213     * @param timeTaken time in millis taken
214     * @return the created event
215     */
216    CamelEvent createExchangeSentEvent(Exchange exchange, Endpoint endpoint, long timeTaken);
217
218    /**
219     * Creates an {@link CamelEvent} when a step has been started
220     *
221     * @param exchange the exchange
222     * @param stepId   the step id
223     * @return the created event
224     */
225    CamelEvent createStepStartedEvent(Exchange exchange, String stepId);
226
227    /**
228     * Creates an {@link CamelEvent} when a step has been completed successfully
229     *
230     * @param exchange the exchange
231     * @param stepId   the step id
232     * @return the created event
233     */
234    CamelEvent createStepCompletedEvent(Exchange exchange, String stepId);
235
236    /**
237     * Creates an {@link CamelEvent} when a step has failed
238     *
239     * @param exchange the exchange
240     * @param stepId   the step id
241     * @return the created event
242     */
243    CamelEvent createStepFailedEvent(Exchange exchange, String stepId);
244
245    /**
246     * Creates an {@link CamelEvent} for Camel is suspending.
247     *
248     * @param context camel context
249     * @return the created event
250     */
251    CamelEvent createCamelContextSuspendingEvent(CamelContext context);
252
253    /**
254     * Creates an {@link CamelEvent} for Camel has been suspended successfully.
255     *
256     * @param context camel context
257     * @return the created event
258     */
259    CamelEvent createCamelContextSuspendedEvent(CamelContext context);
260
261    /**
262     * Creates an {@link CamelEvent} for Camel is resuming.
263     *
264     * @param context camel context
265     * @return the created event
266     */
267    CamelEvent createCamelContextResumingEvent(CamelContext context);
268
269    /**
270     * Creates an {@link CamelEvent} for Camel has been resumed successfully.
271     *
272     * @param context camel context
273     * @return the created event
274     */
275    CamelEvent createCamelContextResumedEvent(CamelContext context);
276
277    /**
278     * Creates an {@link CamelEvent} for Camel failing to resume
279     *
280     * @param context camel context
281     * @param cause   the cause exception
282     * @return the created event
283     */
284    CamelEvent createCamelContextResumeFailureEvent(CamelContext context, Throwable cause);
285
286}