Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
EventDrivenConsumerRoute |
|
| 0.0;0 |
1 | /** |
|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
3 | * contributor license agreements. See the NOTICE file distributed with |
|
4 | * this work for additional information regarding copyright ownership. |
|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
6 | * (the "License"); you may not use this file except in compliance with |
|
7 | * the License. You may obtain a copy of the License at |
|
8 | * |
|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
10 | * |
|
11 | * Unless required by applicable law or agreed to in writing, software |
|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 | * See the License for the specific language governing permissions and |
|
15 | * limitations under the License. |
|
16 | */ |
|
17 | package org.apache.camel.impl; |
|
18 | ||
19 | import java.util.List; |
|
20 | ||
21 | import org.apache.camel.Consumer; |
|
22 | import org.apache.camel.Endpoint; |
|
23 | import org.apache.camel.Exchange; |
|
24 | import org.apache.camel.Processor; |
|
25 | import org.apache.camel.Route; |
|
26 | import org.apache.camel.Service; |
|
27 | ||
28 | /** |
|
29 | * A {@link Route} which starts with an |
|
30 | * <a href="http://activemq.apache.org/camel/event-driven-consumer.html">Event Driven Consumer</a> |
|
31 | * |
|
32 | * @version $Revision: 1.1 $ |
|
33 | */ |
|
34 | public class EventDrivenConsumerRoute<E extends Exchange> extends Route<E> { |
|
35 | private Processor processor; |
|
36 | ||
37 | public EventDrivenConsumerRoute(Endpoint endpoint, Processor processor) { |
|
38 | 258 | super(endpoint); |
39 | 258 | this.processor = processor; |
40 | 258 | } |
41 | ||
42 | @Override |
|
43 | public String toString() { |
|
44 | 255 | return "EventDrivenConsumerRoute[" + getEndpoint() + " -> " + processor + "]"; |
45 | } |
|
46 | ||
47 | public Processor getProcessor() { |
|
48 | 258 | return processor; |
49 | } |
|
50 | ||
51 | public void setProcessor(Processor processor) { |
|
52 | 0 | this.processor = processor; |
53 | 0 | } |
54 | ||
55 | /** |
|
56 | * Factory method to lazily create the complete list of services required for this route |
|
57 | * such as adding the processor or consumer |
|
58 | */ |
|
59 | @Override |
|
60 | protected void addServices(List<Service> services) throws Exception { |
|
61 | 219 | Processor processor = getProcessor(); |
62 | 219 | if (processor instanceof Service) { |
63 | 219 | Service service = (Service) processor; |
64 | 219 | services.add(service); |
65 | } |
|
66 | 219 | Endpoint<E> endpoint = getEndpoint(); |
67 | 219 | Consumer<E> consumer = endpoint.createConsumer(processor); |
68 | 219 | if (consumer != null) { |
69 | 219 | services.add(consumer); |
70 | } |
|
71 | 219 | } |
72 | } |