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.core.xml;
018
019 import javax.xml.bind.annotation.XmlAccessType;
020 import javax.xml.bind.annotation.XmlAccessorType;
021 import javax.xml.bind.annotation.XmlAttribute;
022 import javax.xml.bind.annotation.XmlTransient;
023
024 import org.apache.camel.ConsumerTemplate;
025 import org.apache.camel.impl.DefaultConsumerTemplate;
026 import org.apache.camel.util.ServiceHelper;
027
028 /**
029 * A factory for creating a new {@link org.apache.camel.ConsumerTemplate}
030 * instance with a minimum of XML
031 *
032 * @version
033 */
034 @XmlAccessorType(XmlAccessType.FIELD)
035 public abstract class AbstractCamelConsumerTemplateFactoryBean extends AbstractCamelFactoryBean<ConsumerTemplate> {
036
037 @XmlTransient
038 private ConsumerTemplate template;
039 @XmlAttribute
040 private Integer maximumCacheSize;
041
042 public ConsumerTemplate getObject() throws Exception {
043 template = new DefaultConsumerTemplate(getCamelContext());
044
045 // set custom cache size if provided
046 if (maximumCacheSize != null) {
047 template.setMaximumCacheSize(maximumCacheSize);
048 }
049
050 // must start it so its ready to use
051 ServiceHelper.startService(template);
052 return template;
053 }
054
055 public Class<DefaultConsumerTemplate> getObjectType() {
056 return DefaultConsumerTemplate.class;
057 }
058
059 public void destroy() throws Exception {
060 ServiceHelper.stopService(template);
061 }
062
063 // Properties
064 // -------------------------------------------------------------------------
065
066 public Integer getMaximumCacheSize() {
067 return maximumCacheSize;
068 }
069
070 public void setMaximumCacheSize(Integer maximumCacheSize) {
071 this.maximumCacheSize = maximumCacheSize;
072 }
073 }