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.impl;
018    
019    import org.apache.camel.Endpoint;
020    import org.apache.camel.Exchange;
021    import org.apache.camel.ExchangePattern;
022    import org.apache.camel.Producer;
023    
024    /**
025     * To process the delegated producer in synchronous mode.
026     * <p/>
027     * This is used to enforce asynchronous producers to run in synchronous mode
028     * when it has been configured to do so.
029     * <p/>
030     * This delegate allows the component developers easily to support their
031     * existing asynchronous producer to behave synchronously by wrapping their
032     * producer in this synchronous delegate.
033     *
034     * @version 
035     */
036    public class SynchronousDelegateProducer implements Producer {
037    
038        private final Producer producer;
039    
040        public SynchronousDelegateProducer(Producer producer) {
041            this.producer = producer;
042        }
043    
044        public Endpoint getEndpoint() {
045            return producer.getEndpoint();
046        }
047    
048        public Exchange createExchange() {
049            return producer.createExchange();
050        }
051    
052        public Exchange createExchange(ExchangePattern pattern) {
053            return producer.createExchange(pattern);
054        }
055    
056        public Exchange createExchange(Exchange exchange) {
057            return producer.createExchange(exchange);
058        }
059    
060        public void process(Exchange exchange) throws Exception {
061            producer.process(exchange);
062        }
063    
064        public void start() throws Exception {
065            producer.start();
066        }
067    
068        public void stop() throws Exception {
069            producer.stop();
070        }
071    
072        public boolean isSingleton() {
073            return producer.isSingleton();
074        }
075    
076        @Override
077        public String toString() {
078            return producer.toString();
079        }
080    }