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 */
017 package org.apache.camel.component.seda;
018
019 import java.util.ArrayList;
020 import java.util.List;
021 import java.util.Map;
022 import java.util.concurrent.BlockingQueue;
023
024 import org.apache.camel.Component;
025 import org.apache.camel.Consumer;
026 import org.apache.camel.Exchange;
027 import org.apache.camel.Processor;
028 import org.apache.camel.Producer;
029 import org.apache.camel.impl.DefaultEndpoint;
030 import org.apache.camel.spi.BrowsableEndpoint;
031
032 /**
033 * An implementation of the <a
034 * href="http://activemq.apache.org/camel/queue.html">Queue components</a> for
035 * asynchronous SEDA exchanges on a {@link BlockingQueue} within a CamelContext
036 *
037 * @version $Revision: 655516 $
038 */
039 public class SedaEndpoint extends DefaultEndpoint<Exchange> implements BrowsableEndpoint<Exchange> {
040 private BlockingQueue<Exchange> queue;
041
042 public SedaEndpoint(String endpointUri, Component component, BlockingQueue<Exchange> queue) {
043 super(endpointUri, component);
044 this.queue = queue;
045 }
046
047 public SedaEndpoint(String uri, SedaComponent component, Map parameters) {
048 this(uri, component, component.createQueue(uri, parameters));
049 }
050
051 public SedaEndpoint(String endpointUri, BlockingQueue<Exchange> queue) {
052 super(endpointUri);
053 this.queue = queue;
054 }
055
056 public Producer createProducer() throws Exception {
057 return new CollectionProducer(this, getQueue());
058 }
059
060 public Consumer createConsumer(Processor processor) throws Exception {
061 return new SedaConsumer(this, processor);
062 }
063
064 public BlockingQueue<Exchange> getQueue() {
065 return queue;
066 }
067
068 public boolean isSingleton() {
069 return true;
070 }
071
072 public List<Exchange> getExchanges() {
073 return new ArrayList<Exchange>(getQueue());
074 }
075 }