001 /**
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one or more
004 * contributor license agreements. See the NOTICE file distributed with
005 * this work for additional information regarding copyright ownership.
006 * The ASF licenses this file to You under the Apache License, Version 2.0
007 * (the "License"); you may not use this file except in compliance with
008 * the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018 package org.apache.camel.impl;
019
020 import org.apache.camel.Route;
021 import org.apache.camel.Endpoint;
022 import org.apache.camel.Processor;
023 import org.apache.camel.Service;
024 import org.apache.camel.Consumer;
025 import org.apache.camel.Exchange;
026
027 import java.util.List;
028
029 /**
030 * A {@link Route} which starts with an
031 * <a href="http://activemq.apache.org/camel/event-driven-consumer.html">Event Driven Consumer</a>
032 *
033 * @version $Revision: 1.1 $
034 */
035 public class EventDrivenConsumerRoute<E extends Exchange> extends Route<E> {
036 private Processor processor;
037
038 public EventDrivenConsumerRoute(Endpoint endpoint, Processor processor) {
039 super(endpoint);
040 this.processor = processor;
041 }
042
043 @Override
044 public String toString() {
045 return "EventDrivenConsumerRoute[" + getEndpoint() + " -> " + processor + "]";
046 }
047
048 public Processor getProcessor() {
049 return processor;
050 }
051
052 public void setProcessor(Processor processor) {
053 this.processor = processor;
054 }
055
056 /**
057 * Factory method to lazily create the complete list of services required for this route
058 * such as adding the processor or consumer
059 */
060 protected void addServices(List<Service> services) throws Exception {
061 Processor processor = getProcessor();
062 if (processor instanceof Service) {
063 Service service = (Service) processor;
064 services.add(service);
065 }
066 Endpoint<E> endpoint = getEndpoint();
067 Consumer<E> consumer = endpoint.createConsumer(processor);
068 if (consumer != null) {
069 services.add(consumer);
070 }
071 }
072 }