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.management.event;
018
019import java.util.EventObject;
020
021import org.apache.camel.CamelContext;
022import org.apache.camel.DelegateProcessor;
023import org.apache.camel.Endpoint;
024import org.apache.camel.Exchange;
025import org.apache.camel.Processor;
026import org.apache.camel.Route;
027import org.apache.camel.spi.EventFactory;
028
029/**
030 * Default implementation of the {@link org.apache.camel.spi.EventFactory}.
031 *
032 * @version 
033 */
034public class DefaultEventFactory implements EventFactory {
035
036    public EventObject createCamelContextStartingEvent(CamelContext context) {
037        return new CamelContextStartingEvent(context);
038    }
039
040    public EventObject createCamelContextStartedEvent(CamelContext context) {
041        return new CamelContextStartedEvent(context);
042    }
043
044    public EventObject createCamelContextStoppingEvent(CamelContext context) {
045        return new CamelContextStoppingEvent(context);
046    }
047
048    public EventObject createCamelContextStoppedEvent(CamelContext context) {
049        return new CamelContextStoppedEvent(context);
050    }
051
052    public EventObject createCamelContextStartupFailureEvent(CamelContext context, Throwable cause) {
053        return new CamelContextStartupFailureEvent(context, cause);
054    }
055
056    public EventObject createCamelContextStopFailureEvent(CamelContext context, Throwable cause) {
057        return new CamelContextStopFailureEvent(context, cause);
058    }
059
060    public EventObject createServiceStartupFailureEvent(CamelContext context, Object service, Throwable cause) {
061        return new ServiceStartupFailureEvent(context, service, cause);
062    }
063
064    public EventObject createServiceStopFailureEvent(CamelContext context, Object service, Throwable cause) {
065        return new ServiceStopFailureEvent(context, service, cause);
066    }
067
068    public EventObject createRouteStartedEvent(Route route) {
069        return new RouteStartedEvent(route);
070    }
071
072    public EventObject createRouteStoppedEvent(Route route) {
073        return new RouteStoppedEvent(route);
074    }
075
076    public EventObject createRouteAddedEvent(Route route) {
077        return new RouteAddedEvent(route);
078    }
079
080    public EventObject createRouteRemovedEvent(Route route) {
081        return new RouteRemovedEvent(route);
082    }
083
084    public EventObject createExchangeCreatedEvent(Exchange exchange) {
085        return new ExchangeCreatedEvent(exchange);
086    }
087
088    public EventObject createExchangeCompletedEvent(Exchange exchange) {
089        return new ExchangeCompletedEvent(exchange);
090    }
091
092    public EventObject createExchangeFailedEvent(Exchange exchange) {
093        return new ExchangeFailedEvent(exchange);
094    }
095
096    public EventObject createExchangeFailureHandledEvent(Exchange exchange, Processor failureHandler,
097                                                         boolean deadLetterChannel, String deadLetterUri) {
098        // unwrap delegate processor
099        Processor handler = failureHandler;
100        if (handler instanceof DelegateProcessor) {
101            handler = ((DelegateProcessor) handler).getProcessor();
102        }
103        return new ExchangeFailureHandledEvent(exchange, handler, deadLetterChannel, deadLetterUri);
104    }
105
106    public EventObject createExchangeRedeliveryEvent(Exchange exchange, int attempt) {
107        return new ExchangeRedeliveryEvent(exchange, attempt);
108    }
109
110    public EventObject createExchangeSendingEvent(Exchange exchange, Endpoint endpoint) {
111        return new ExchangeSendingEvent(exchange, endpoint);
112    }
113
114    public EventObject createExchangeSentEvent(Exchange exchange, Endpoint endpoint, long timeTaken) {
115        return new ExchangeSentEvent(exchange, endpoint, timeTaken);
116    }
117
118    public EventObject createCamelContextSuspendingEvent(CamelContext context) {
119        return new CamelContextSuspendingEvent(context);
120    }
121
122    public EventObject createCamelContextSuspendedEvent(CamelContext context) {
123        return new CamelContextSuspendedEvent(context);
124    }
125
126    public EventObject createCamelContextResumingEvent(CamelContext context) {
127        return new CamelContextResumingEvent(context);
128    }
129
130    public EventObject createCamelContextResumedEvent(CamelContext context) {
131        return new CamelContextResumedEvent(context);
132    }
133
134    public EventObject createCamelContextResumeFailureEvent(CamelContext context, Throwable cause) {
135        return new CamelContextResumeFailureEvent(context, cause);
136    }
137}