001 /** 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one or more 004 * contributor license agreements. See the NOTICE file distributed with 005 * this work for additional information regarding copyright ownership. 006 * The ASF licenses this file to You under the Apache License, Version 2.0 007 * (the "License"); you may not use this file except in compliance with 008 * the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 package org.apache.camel.component.activemq; 019 020 import org.apache.activemq.pool.PooledConnectionFactory; 021 import org.apache.activemq.spring.ActiveMQConnectionFactory; 022 import org.apache.camel.component.jms.JmsConfiguration; 023 024 import javax.jms.ConnectionFactory; 025 026 /** 027 * @version $Revision: 1.1 $ 028 */ 029 public class ActiveMQConfiguration extends JmsConfiguration { 030 private String brokerURL = ActiveMQConnectionFactory.DEFAULT_BROKER_URL; 031 032 public ActiveMQConfiguration() { 033 } 034 035 public String getBrokerURL() { 036 return brokerURL; 037 } 038 039 /** 040 * Sets the broker URL to use to connect to ActiveMQ using the 041 * <a href="http://activemq.apache.org/configuring-transports.html">ActiveMQ URI format</a> 042 * 043 * @param brokerURL the URL of the broker. 044 */ 045 public void setBrokerURL(String brokerURL) { 046 this.brokerURL = brokerURL; 047 } 048 049 @Override 050 public ActiveMQConnectionFactory getListenerConnectionFactory() { 051 return (ActiveMQConnectionFactory) super.getListenerConnectionFactory(); 052 } 053 054 @Override 055 public void setListenerConnectionFactory(ConnectionFactory listenerConnectionFactory) { 056 if (listenerConnectionFactory instanceof ActiveMQConnectionFactory) { 057 super.setListenerConnectionFactory(listenerConnectionFactory); 058 } 059 else { 060 throw new IllegalArgumentException("ConnectionFactory " + listenerConnectionFactory 061 + " is not an instanceof " + ActiveMQConnectionFactory.class.getName()); 062 } 063 } 064 065 @Override 066 protected ConnectionFactory createListenerConnectionFactory() { 067 ActiveMQConnectionFactory answer = new ActiveMQConnectionFactory(); 068 answer.setBrokerURL(getBrokerURL()); 069 return answer; 070 } 071 072 @Override 073 protected ConnectionFactory createTemplateConnectionFactory() { 074 return new PooledConnectionFactory(getListenerConnectionFactory()); 075 } 076 }