Home » activemq-parent-5.3.1-source-release » org.apache » activemq » camel » component » [javadoc | source]

    1   /**
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    */
   17   package org.apache.activemq.camel.component;
   18   
   19   import java.util.concurrent.CopyOnWriteArrayList;
   20   
   21   import org.apache.activemq.Service;
   22   import org.apache.camel.CamelContext;
   23   import org.apache.camel.component.jms.JmsComponent;
   24   import org.apache.camel.component.jms.JmsConfiguration;
   25   import org.springframework.jms.connection.SingleConnectionFactory;
   26   
   27   /**
   28    * The <a href="http://activemq.apache.org/camel/activemq.html">ActiveMQ Component</a>
   29    *
   30    * @version $Revision: 910986 $
   31    */
   32   public class ActiveMQComponent extends JmsComponent {
   33       private final CopyOnWriteArrayList<SingleConnectionFactory> singleConnectionFactoryList =
   34           new CopyOnWriteArrayList<SingleConnectionFactory>();
   35       private final CopyOnWriteArrayList<Service> pooledConnectionFactoryServiceList =
   36           new CopyOnWriteArrayList<Service>();
   37       private boolean exposeAllQueues;
   38       private CamelEndpointLoader endpointLoader;
   39   
   40       /**
   41        * Creates an <a href="http://activemq.apache.org/camel/activemq.html">ActiveMQ Component</a>
   42        *
   43        * @return the created component
   44        */
   45       public static ActiveMQComponent activeMQComponent() {
   46           return new ActiveMQComponent();
   47       }
   48   
   49       /**
   50        * Creates an <a href="http://activemq.apache.org/camel/activemq.html">ActiveMQ Component</a>
   51        * connecting to the given <a href="http://activemq.apache.org/configuring-transports.html">broker URL</a>
   52        *
   53        * @param brokerURL the URL to connect to
   54        * @return the created component
   55        */
   56       public static ActiveMQComponent activeMQComponent(String brokerURL) {
   57           ActiveMQComponent answer = new ActiveMQComponent();
   58           if (answer.getConfiguration() instanceof ActiveMQConfiguration) {
   59               ((ActiveMQConfiguration) answer.getConfiguration())
   60                       .setBrokerURL(brokerURL);
   61           }
   62           return answer;
   63       }
   64   
   65       public ActiveMQComponent() {
   66       }
   67   
   68       public ActiveMQComponent(CamelContext context) {
   69           super(context);
   70       }
   71   
   72       public ActiveMQComponent(ActiveMQConfiguration configuration) {
   73           super(configuration);
   74       }
   75   
   76      
   77       public void setBrokerURL(String brokerURL) {
   78           if (getConfiguration() instanceof ActiveMQConfiguration) {
   79               ((ActiveMQConfiguration)getConfiguration()).setBrokerURL(brokerURL);
   80           }
   81       }
   82   
   83       public void setUserName(String userName) {
   84           if (getConfiguration() instanceof ActiveMQConfiguration) {
   85               ((ActiveMQConfiguration)getConfiguration()).setUserName(userName);
   86           }
   87       }
   88   
   89       public void setPassword(String password) {
   90           if (getConfiguration() instanceof ActiveMQConfiguration) {
   91               ((ActiveMQConfiguration)getConfiguration()).setPassword(password);
   92           }
   93       }
   94   
   95       public boolean isExposeAllQueues() {
   96           return exposeAllQueues;
   97       }
   98   
   99       /**
  100        * If enabled this will cause all Queues in the ActiveMQ broker to be eagerly populated into the CamelContext
  101        * so that they can be easily browsed by any Camel tooling. This option is disabled by default.
  102        *
  103        * @param exposeAllQueues
  104        */
  105       public void setExposeAllQueues(boolean exposeAllQueues) {
  106           this.exposeAllQueues = exposeAllQueues;
  107       }
  108   
  109       public void setUsePooledConnection(boolean usePooledConnection) {
  110           if (getConfiguration() instanceof ActiveMQConfiguration) {
  111               ((ActiveMQConfiguration)getConfiguration()).setUsePooledConnection(usePooledConnection);
  112           }
  113       }
  114   
  115       public void setUseSingleConnection(boolean useSingleConnection) {
  116           if (getConfiguration() instanceof ActiveMQConfiguration) {
  117               ((ActiveMQConfiguration)getConfiguration()).setUseSingleConnection(useSingleConnection);
  118           }
  119       }
  120   
  121       protected void addPooledConnectionFactoryService(Service pooledConnectionFactoryService) {
  122           pooledConnectionFactoryServiceList.add(pooledConnectionFactoryService);
  123       }
  124   
  125       protected void addSingleConnectionFactory(SingleConnectionFactory singleConnectionFactory) {
  126           singleConnectionFactoryList.add(singleConnectionFactory);
  127       }
  128   
  129       @Override
  130       protected void doStart() throws Exception {
  131           super.doStart();
  132           if (isExposeAllQueues()) {
  133               endpointLoader = new CamelEndpointLoader(getCamelContext());
  134               endpointLoader.afterPropertiesSet();
  135           }
  136       }
  137   
  138       @Override
  139       protected void doStop() throws Exception {
  140           if (endpointLoader != null) {
  141               endpointLoader.destroy();
  142               endpointLoader = null;
  143           }
  144           for (Service s : pooledConnectionFactoryServiceList) {
  145               s.stop();
  146           }
  147           pooledConnectionFactoryServiceList.clear();
  148           for (SingleConnectionFactory s : singleConnectionFactoryList) {
  149               s.destroy();
  150           }
  151           singleConnectionFactoryList.clear();
  152           super.doStop();
  153       }
  154   
  155       @Override
  156       public void setConfiguration(JmsConfiguration configuration) {
  157           if (configuration instanceof ActiveMQConfiguration) {
  158               ((ActiveMQConfiguration) configuration).setActiveMQComponent(this);
  159           }
  160           super.setConfiguration(configuration);
  161       }
  162   
  163       @Override
  164       protected JmsConfiguration createConfiguration() {
  165           ActiveMQConfiguration answer = new ActiveMQConfiguration();
  166           answer.setActiveMQComponent(this);
  167           return answer;
  168       }
  169   }

Home » activemq-parent-5.3.1-source-release » org.apache » activemq » camel » component » [javadoc | source]