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 */
017package org.apache.camel.impl;
018
019import org.apache.camel.Endpoint;
020import org.apache.camel.Exchange;
021import org.apache.camel.ExchangePattern;
022import 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 */
036public 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    @Deprecated
057    public Exchange createExchange(Exchange exchange) {
058        return producer.createExchange(exchange);
059    }
060
061    public void process(Exchange exchange) throws Exception {
062        producer.process(exchange);
063    }
064
065    public void start() throws Exception {
066        producer.start();
067    }
068
069    public void stop() throws Exception {
070        producer.stop();
071    }
072
073    public boolean isSingleton() {
074        return producer.isSingleton();
075    }
076
077    @Override
078    public String toString() {
079        return producer.toString();
080    }
081}