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