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 import org.apache.commons.logging.Log;
024 import org.apache.commons.logging.LogFactory;
025
026 /**
027 * A default implementation of @{link Producer} for implementation inheritence
028 *
029 * @version $Revision: 789087 $
030 */
031 public abstract class DefaultProducer extends ServiceSupport implements Producer {
032 private final transient Log log = LogFactory.getLog(getClass());
033 private final Endpoint endpoint;
034
035 public DefaultProducer(Endpoint endpoint) {
036 this.endpoint = endpoint;
037 }
038
039 @Override
040 public String toString() {
041 return "Producer[" + endpoint.getEndpointUri() + "]";
042 }
043
044 public Endpoint getEndpoint() {
045 return endpoint;
046 }
047
048 public Exchange createExchange() {
049 return endpoint.createExchange();
050 }
051
052 public Exchange createExchange(ExchangePattern pattern) {
053 return endpoint.createExchange(pattern);
054 }
055
056 public Exchange createExchange(Exchange exchange) {
057 return endpoint.createExchange(exchange);
058 }
059
060 public boolean isSingleton() {
061 return true;
062 }
063
064 protected void doStart() throws Exception {
065 if (log.isDebugEnabled()) {
066 log.debug("Starting producer: " + this);
067 }
068 }
069
070 protected void doStop() throws Exception {
071 if (log.isDebugEnabled()) {
072 log.debug("Stopping producer: " + this);
073 }
074 }
075 }