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.concurrent.BlockingQueue; 022 023 import org.apache.camel.Component; 024 import org.apache.camel.Consumer; 025 import org.apache.camel.Exchange; 026 import org.apache.camel.Processor; 027 import org.apache.camel.Producer; 028 import org.apache.camel.impl.DefaultEndpoint; 029 import org.apache.camel.spi.BrowsableEndpoint; 030 import org.apache.camel.util.ObjectHelper; 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: 2624 $ 038 */ 039 public class SedaEndpoint extends DefaultEndpoint<Exchange> implements BrowsableEndpoint<Exchange> { 040 private BlockingQueue<Exchange> queue; 041 private int concurrentConsumers = 1; 042 043 public SedaEndpoint(String endpointUri, Component component, BlockingQueue<Exchange> queue) { 044 this(endpointUri, component, queue, 1); 045 } 046 047 public SedaEndpoint(String endpointUri, Component component, BlockingQueue<Exchange> queue, int concurrentConsumers) { 048 super(endpointUri, component); 049 this.queue = queue; 050 this.concurrentConsumers = concurrentConsumers; 051 } 052 053 public SedaEndpoint(String endpointUri, BlockingQueue<Exchange> queue) { 054 this(endpointUri, queue, 1); 055 } 056 057 public SedaEndpoint(String endpointUri, BlockingQueue<Exchange> queue, int concurrentConsumers) { 058 super(endpointUri); 059 ObjectHelper.notNull(queue, "queue"); 060 this.queue = queue; 061 this.concurrentConsumers = concurrentConsumers; 062 } 063 064 public Producer createProducer() throws Exception { 065 return new CollectionProducer(this, getQueue()); 066 } 067 068 public Consumer createConsumer(Processor processor) throws Exception { 069 return new SedaConsumer(this, processor); 070 } 071 072 public BlockingQueue<Exchange> getQueue() { 073 return queue; 074 } 075 076 public void setConcurrentConsumers(int concurrentConsumers) { 077 this.concurrentConsumers = concurrentConsumers; 078 } 079 080 public int getConcurrentConsumers() { 081 return concurrentConsumers; 082 } 083 084 public boolean isSingleton() { 085 return true; 086 } 087 088 public List<Exchange> getExchanges() { 089 return new ArrayList<Exchange>(getQueue()); 090 } 091 }