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.concurrent.BlockingQueue;
020
021 import org.apache.camel.Component;
022 import org.apache.camel.Consumer;
023 import org.apache.camel.Exchange;
024 import org.apache.camel.Processor;
025 import org.apache.camel.Producer;
026 import org.apache.camel.impl.DefaultEndpoint;
027 import org.apache.camel.impl.DefaultExchange;
028 import org.apache.camel.impl.DefaultProducer;
029
030 /**
031 * An implementation of the <a
032 * href="http://activemq.apache.org/camel/queue.html">Queue components</a> for
033 * asynchronous SEDA exchanges on a {@link BlockingQueue} within a CamelContext
034 *
035 * @org.apache.xbean.XBean
036 * @version $Revision: 519973 $
037 */
038 public class SedaEndpoint<E extends Exchange> extends DefaultEndpoint<E> {
039 private BlockingQueue<E> queue;
040
041 public SedaEndpoint(String endpointUri, Component component, BlockingQueue<E> queue) {
042 super(endpointUri, component);
043 this.queue = queue;
044 }
045
046 public SedaEndpoint(String uri, SedaComponent<E> component) {
047 this(uri, component, component.createQueue());
048 }
049
050 public Producer<E> createProducer() throws Exception {
051 return new DefaultProducer(this) {
052 public void process(Exchange exchange) {
053 queue.add(toExchangeType(exchange));
054 }
055 };
056 }
057
058 public Consumer<E> createConsumer(Processor processor) throws Exception {
059 return new SedaConsumer<E>(this, processor);
060 }
061
062 public E createExchange() {
063 // How can we create a specific Exchange if we are generic??
064 // perhaps it would be better if we did not implement this.
065 return (E)new DefaultExchange(getContext());
066 }
067
068 public BlockingQueue<E> getQueue() {
069 return queue;
070 }
071
072 public boolean isSingleton() {
073 return true;
074 }
075
076 }