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