Classes in this File | Line Coverage | Branch Coverage | Complexity | |||||||
QueueEndpoint |
|
| 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.component.queue; |
|
18 | ||
19 | import java.util.concurrent.BlockingQueue; |
|
20 | ||
21 | import org.apache.camel.Consumer; |
|
22 | import org.apache.camel.Exchange; |
|
23 | import org.apache.camel.Processor; |
|
24 | import org.apache.camel.Producer; |
|
25 | import org.apache.camel.impl.DefaultEndpoint; |
|
26 | import org.apache.camel.impl.DefaultExchange; |
|
27 | import org.apache.camel.impl.DefaultProducer; |
|
28 | ||
29 | /** |
|
30 | * Represents a queue endpoint that uses a {@link BlockingQueue} |
|
31 | * object to process inbound exchanges. |
|
32 | * |
|
33 | * @org.apache.xbean.XBean |
|
34 | * @version $Revision: 519973 $ |
|
35 | */ |
|
36 | 2 | public class QueueEndpoint<E extends Exchange> extends DefaultEndpoint<E> { |
37 | private BlockingQueue<E> queue; |
|
38 | ||
39 | public QueueEndpoint(String uri, QueueComponent<E> component) { |
|
40 | 26 | super(uri, component); |
41 | 26 | this.queue = component.createQueue(); |
42 | 26 | } |
43 | ||
44 | public Producer<E> createProducer() throws Exception { |
|
45 | 4 | return new DefaultProducer(this) { |
46 | 4 | public void process(Exchange exchange) { |
47 | 2 | queue.add(toExchangeType(exchange)); |
48 | 2 | } |
49 | }; |
|
50 | } |
|
51 | ||
52 | public Consumer<E> createConsumer(Processor processor) throws Exception { |
|
53 | 2 | return new QueueEndpointConsumer<E>(this, processor); |
54 | } |
|
55 | ||
56 | public E createExchange() { |
|
57 | // How can we create a specific Exchange if we are generic?? |
|
58 | // perhaps it would be better if we did not implement this. |
|
59 | 3 | return (E) new DefaultExchange(getContext()); |
60 | } |
|
61 | ||
62 | public BlockingQueue<E> getQueue() { |
|
63 | 4 | return queue; |
64 | } |
|
65 | ||
66 | public boolean isSingleton() { |
|
67 | 26 | return true; |
68 | } |
|
69 | ||
70 | ||
71 | } |