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 was handled by the Camel error handlers such as an dead letter channel. 165 * 166 * @param exchange the exchange 167 * @param failureHandler the failure handler such as moving the message to a dead letter queue 168 * @param deadLetterChannel whether it was a dead letter channel or not handling the failure 169 * @param deadLetterUri the dead letter uri, if its a dead letter channel 170 * @return the created event 171 */ 172 EventObject createExchangeFailureHandledEvent(Exchange exchange, Processor failureHandler, 173 boolean deadLetterChannel, String deadLetterUri); 174 175 /** 176 * Creates an {@link EventObject} when an {@link org.apache.camel.Exchange} is about to be redelivered 177 * 178 * @param exchange the exchange 179 * @param attempt the current redelivery attempt (starts from 1) 180 * @return the created event 181 */ 182 EventObject createExchangeRedeliveryEvent(Exchange exchange, int attempt); 183 184 /** 185 * Creates an {@link EventObject} when an {@link org.apache.camel.Exchange} is about to be sent to the endpoint (eg before). 186 * 187 * @param exchange the exchange 188 * @param endpoint the destination 189 * @return the created event 190 */ 191 EventObject createExchangeSendingEvent(Exchange exchange, Endpoint endpoint); 192 193 /** 194 * Creates an {@link EventObject} when an {@link org.apache.camel.Exchange} has completely been sent to the endpoint (eg after). 195 * 196 * @param exchange the exchange 197 * @param endpoint the destination 198 * @param timeTaken time in millis taken 199 * @return the created event 200 */ 201 EventObject createExchangeSentEvent(Exchange exchange, Endpoint endpoint, long timeTaken); 202 203 /** 204 * Creates an {@link EventObject} for Camel is suspending. 205 * 206 * @param context camel context 207 * @return the created event 208 */ 209 EventObject createCamelContextSuspendingEvent(CamelContext context); 210 211 /** 212 * Creates an {@link EventObject} for Camel has been suspended successfully. 213 * 214 * @param context camel context 215 * @return the created event 216 */ 217 EventObject createCamelContextSuspendedEvent(CamelContext context); 218 219 /** 220 * Creates an {@link EventObject} for Camel is resuming. 221 * 222 * @param context camel context 223 * @return the created event 224 */ 225 EventObject createCamelContextResumingEvent(CamelContext context); 226 227 /** 228 * Creates an {@link EventObject} for Camel has been resumed successfully. 229 * 230 * @param context camel context 231 * @return the created event 232 */ 233 EventObject createCamelContextResumedEvent(CamelContext context); 234 235 /** 236 * Creates an {@link EventObject} for Camel failing to resume 237 * 238 * @param context camel context 239 * @param cause the cause exception 240 * @return the created event 241 */ 242 EventObject createCamelContextResumeFailureEvent(CamelContext context, Throwable cause); 243 244}