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.EventObject;
020
021 import org.apache.camel.CamelContext;
022 import org.apache.camel.Endpoint;
023 import org.apache.camel.Exchange;
024 import org.apache.camel.Processor;
025 import 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 */
034 public 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} when an {@link org.apache.camel.Exchange} has been created
124 *
125 * @param exchange the exchange
126 * @return the created event
127 */
128 EventObject createExchangeCreatedEvent(Exchange exchange);
129
130 /**
131 * Creates an {@link EventObject} when an {@link org.apache.camel.Exchange} has been completed successfully
132 *
133 * @param exchange the exchange
134 * @return the created event
135 */
136 EventObject createExchangeCompletedEvent(Exchange exchange);
137
138 /**
139 * Creates an {@link EventObject} when an {@link org.apache.camel.Exchange} has failed
140 *
141 * @param exchange the exchange
142 * @return the created event
143 */
144 EventObject createExchangeFailedEvent(Exchange exchange);
145
146 /**
147 * Creates an {@link EventObject} when an {@link org.apache.camel.Exchange} has failed
148 * but was handled by the Camel error handlers such as an dead letter channel.
149 *
150 * @param exchange the exchange
151 * @param failureHandler the failure handler such as moving the message to a dead letter queue
152 * @param deadLetterChannel whether it was a dead letter channel or not handling the failure
153 * @return the created event
154 */
155 EventObject createExchangeFailureHandledEvent(Exchange exchange, Processor failureHandler, boolean deadLetterChannel);
156
157 /**
158 * Creates an {@link EventObject} when an {@link org.apache.camel.Exchange} is about to be redelivered
159 *
160 * @param exchange the exchange
161 * @param attempt the current redelivery attempt (starts from 1)
162 * @return the created event
163 */
164 EventObject createExchangeRedeliveryEvent(Exchange exchange, int attempt);
165
166 /**
167 * Creates an {@link EventObject} when an {@link org.apache.camel.Exchange} is about to be sent to the endpoint (eg before).
168 *
169 * @param exchange the exchange
170 * @param endpoint the destination
171 * @return the created event
172 */
173 EventObject createExchangeSendingEvent(Exchange exchange, Endpoint endpoint);
174
175 /**
176 * Creates an {@link EventObject} when an {@link org.apache.camel.Exchange} has completely been sent to the endpoint (eg after).
177 *
178 * @param exchange the exchange
179 * @param endpoint the destination
180 * @param timeTaken time in millis taken
181 * @return the created event
182 */
183 EventObject createExchangeSentEvent(Exchange exchange, Endpoint endpoint, long timeTaken);
184
185 /**
186 * Creates an {@link EventObject} for Camel is suspending.
187 *
188 * @param context camel context
189 * @return the created event
190 */
191 EventObject createCamelContextSuspendingEvent(CamelContext context);
192
193 /**
194 * Creates an {@link EventObject} for Camel has been suspended successfully.
195 *
196 * @param context camel context
197 * @return the created event
198 */
199 EventObject createCamelContextSuspendedEvent(CamelContext context);
200
201 /**
202 * Creates an {@link EventObject} for Camel is resuming.
203 *
204 * @param context camel context
205 * @return the created event
206 */
207 EventObject createCamelContextResumingEvent(CamelContext context);
208
209 /**
210 * Creates an {@link EventObject} for Camel has been resumed successfully.
211 *
212 * @param context camel context
213 * @return the created event
214 */
215 EventObject createCamelContextResumedEvent(CamelContext context);
216
217 /**
218 * Creates an {@link EventObject} for Camel failing to resume
219 *
220 * @param context camel context
221 * @param cause the cause exception
222 * @return the created event
223 */
224 EventObject createCamelContextResumeFailureEvent(CamelContext context, Throwable cause);
225
226 }