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.Exchange;
023    import org.apache.camel.Processor;
024    import org.apache.camel.Route;
025    
026    /**
027     * Factory to create {@link java.util.EventObject} events} that are emitted when such an event occur.
028     * <p/>
029     * For example when an {@link Exchange} is being created and then later when its done.
030     *
031     * @version $Revision: 813876 $
032     */
033    public interface EventFactory {
034    
035        /**
036         * Creates an {@link EventObject} for Camel is starting.
037         *
038         * @param context camel context
039         * @return the created event
040         */
041        EventObject createCamelContextStartingEvent(CamelContext context);
042    
043        /**
044         * Creates an {@link EventObject} for Camel has been started successfully.
045         *
046         * @param context camel context
047         * @return the created event
048         */
049        EventObject createCamelContextStartedEvent(CamelContext context);
050    
051        /**
052         * Creates an {@link EventObject} for Camel failing to start
053         *
054         * @param context camel context
055         * @param cause the cause exception
056         * @return the created event
057         */
058        EventObject createCamelContextStartupFailureEvent(CamelContext context, Exception cause);
059    
060        /**
061         * Creates an {@link EventObject} for Camel failing to stop cleanly
062         *
063         * @param context camel context
064         * @param cause the cause exception
065         * @return the created event
066         */
067        EventObject createCamelContextStopFailureEvent(CamelContext context, Exception cause);
068    
069        /**
070         * Creates an {@link EventObject} for Camel is stopping.
071         *
072         * @param context camel context
073         * @return the created event
074         */
075        EventObject createCamelContextStoppingEvent(CamelContext context);
076    
077        /**
078         * Creates an {@link EventObject} for Camel has been stopped successfully.
079         *
080         * @param context camel context
081         * @return the created event
082         */
083        EventObject createCamelContextStoppedEvent(CamelContext context);
084    
085        /**
086         * Creates an {@link EventObject} for a Service failed to start cleanly
087         *
088         * @param context camel context
089         * @param service the service
090         * @param cause the cause exception
091         * @return the created event
092         */
093        EventObject createServiceStartupFailureEvent(CamelContext context, Object service, Exception cause);
094    
095        /**
096         * Creates an {@link EventObject} for a Service failed to stop cleanly
097         *
098         * @param context camel context
099         * @param service the service
100         * @param cause the cause exception
101         * @return the created event
102         */
103        EventObject createServiceStopFailureEvent(CamelContext context, Object service, Exception cause);
104    
105        /**
106         * Creates an {@link EventObject} for {@link Route} has been started successfully.
107         *
108         * @param route the route
109         * @return the created event
110         */
111        EventObject createRouteStartedEvent(Route route);
112    
113        /**
114         * Creates an {@link EventObject} for {@link Route} has been stopped successfully.
115         *
116         * @param route the route
117         * @return the created event
118         */
119        EventObject createRouteStoppedEvent(Route route);
120    
121        /**
122         * Creates an {@link EventObject} when an {@link org.apache.camel.Exchange} has been created
123         *
124         * @param exchange the exchange
125         * @return the created event
126         */
127        EventObject createExchangeCreatedEvent(Exchange exchange);
128    
129        /**
130         * Creates an {@link EventObject} when an {@link org.apache.camel.Exchange} has been completed successfully
131         *
132         * @param exchange the exchange
133         * @return the created event
134         */
135        EventObject createExchangeCompletedEvent(Exchange exchange);
136    
137        /**
138         * Creates an {@link EventObject} when an {@link org.apache.camel.Exchange} has failed
139         *
140         * @param exchange the exchange
141         * @return the created event
142         */
143        EventObject createExchangeFailureEvent(Exchange exchange);
144    
145        /**
146         * Creates an {@link EventObject} when an {@link org.apache.camel.Exchange} has failed
147         * but was handled by the Camel error handlers such as an dead letter channel.
148         *
149         * @param exchange the exchange
150         * @param failureHandler the failure handler such as moving the message to a dead letter queue
151         * @param deadLetterChannel whether it was a dead letter channel or not handling the failure
152         * @return the created event
153         */
154        EventObject createExchangeFailureHandledEvent(Exchange exchange, Processor failureHandler, boolean deadLetterChannel);
155    
156    }