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 createExchangeFailureHandlingEvent(Exchange exchange, Processor failureHandler, boolean deadLetterChannel, String deadLetterUri) { 097 // unwrap delegate processor 098 Processor handler = failureHandler; 099 if (handler instanceof DelegateProcessor) { 100 handler = ((DelegateProcessor) handler).getProcessor(); 101 } 102 return new ExchangeFailureHandlingEvent(exchange, handler, deadLetterChannel, deadLetterUri); 103 } 104 105 public EventObject createExchangeFailureHandledEvent(Exchange exchange, Processor failureHandler, 106 boolean deadLetterChannel, String deadLetterUri) { 107 // unwrap delegate processor 108 Processor handler = failureHandler; 109 if (handler instanceof DelegateProcessor) { 110 handler = ((DelegateProcessor) handler).getProcessor(); 111 } 112 return new ExchangeFailureHandledEvent(exchange, handler, deadLetterChannel, deadLetterUri); 113 } 114 115 public EventObject createExchangeRedeliveryEvent(Exchange exchange, int attempt) { 116 return new ExchangeRedeliveryEvent(exchange, attempt); 117 } 118 119 public EventObject createExchangeSendingEvent(Exchange exchange, Endpoint endpoint) { 120 return new ExchangeSendingEvent(exchange, endpoint); 121 } 122 123 public EventObject createExchangeSentEvent(Exchange exchange, Endpoint endpoint, long timeTaken) { 124 return new ExchangeSentEvent(exchange, endpoint, timeTaken); 125 } 126 127 public EventObject createCamelContextSuspendingEvent(CamelContext context) { 128 return new CamelContextSuspendingEvent(context); 129 } 130 131 public EventObject createCamelContextSuspendedEvent(CamelContext context) { 132 return new CamelContextSuspendedEvent(context); 133 } 134 135 public EventObject createCamelContextResumingEvent(CamelContext context) { 136 return new CamelContextResumingEvent(context); 137 } 138 139 public EventObject createCamelContextResumedEvent(CamelContext context) { 140 return new CamelContextResumedEvent(context); 141 } 142 143 public EventObject createCamelContextResumeFailureEvent(CamelContext context, Throwable cause) { 144 return new CamelContextResumeFailureEvent(context, cause); 145 } 146}