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