Home » openejb-3.1.2-src » org.apache » openejb » resource » activemq » [javadoc | source]

    1   /**
    2    *
    3    * Licensed to the Apache Software Foundation (ASF) under one or more
    4    * contributor license agreements.  See the NOTICE file distributed with
    5    * this work for additional information regarding copyright ownership.
    6    * The ASF licenses this file to You under the Apache License, Version 2.0
    7    * (the "License"); you may not use this file except in compliance with
    8    * the License.  You may obtain a copy of the License at
    9    *
   10    *     http://www.apache.org/licenses/LICENSE-2.0
   11    *
   12    *  Unless required by applicable law or agreed to in writing, software
   13    *  distributed under the License is distributed on an "AS IS" BASIS,
   14    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   15    *  See the License for the specific language governing permissions and
   16    *  limitations under the License.
   17    */
   18   package org.apache.openejb.resource.activemq;
   19   
   20   import java.net.URI;
   21   import java.net.URISyntaxException;
   22   import java.util.Properties;
   23   import javax.resource.spi.BootstrapContext;
   24   import javax.resource.spi.ResourceAdapterInternalException;
   25   
   26   import org.apache.openejb.util.URISupport;
   27   
   28   
   29   public class ActiveMQResourceAdapter extends org.apache.activemq.ra.ActiveMQResourceAdapter {
   30       private String dataSource;
   31   
   32       public String getDataSource() {
   33           return dataSource;
   34       }
   35   
   36       public void setDataSource(String dataSource) {
   37           this.dataSource = dataSource;
   38       }
   39   //   DMB:  Work in progress.  These all should go into the service-jar.xml
   40   //   Sources of info:
   41   //         - http://activemq.apache.org/resource-adapter-properties.html
   42   //         - http://activemq.apache.org/camel/maven/camel-core/apidocs/org/apache/camel/processor/RedeliveryPolicy.html
   43   //
   44   //    /**
   45   //     * 100	 The maximum number of messages sent to a consumer on a durable topic until acknowledgements are received
   46   //     * @param integer
   47   //     */
   48   //    public void setDurableTopicPrefetch(Integer integer) {
   49   //        super.setDurableTopicPrefetch(integer);
   50   //    }
   51   //
   52   //    /**
   53   //     * 1000	 The delay before redeliveries start. Also configurable on the ActivationSpec.
   54   //     * @param aLong
   55   //     */
   56   //    public void setInitialRedeliveryDelay(Long aLong) {
   57   //        super.setInitialRedeliveryDelay(aLong);
   58   //    }
   59   //
   60   //    /**
   61   //     * 100	 The maximum number of messages sent to a consumer on a JMS stream until acknowledgements are received
   62   //     * @param integer
   63   //     */
   64   //    public void setInputStreamPrefetch(Integer integer) {
   65   //        super.setInputStreamPrefetch(integer);
   66   //    }
   67   //
   68   //    /**
   69   //     * 5	 The maximum number of redeliveries or -1 for no maximum. Also configurable on the ActivationSpec.
   70   //     * @param integer
   71   //     */
   72   //    public void setMaximumRedeliveries(Integer integer) {
   73   //        super.setMaximumRedeliveries(integer);
   74   //    }
   75   //
   76   //    public void setQueueBrowserPrefetch(Integer integer) {
   77   //        super.setQueueBrowserPrefetch(integer);
   78   //    }
   79   //
   80   //    /**
   81   //     * 1000	 The maximum number of messages sent to a consumer on a queue until acknowledgements are received
   82   //     * @param integer
   83   //     */
   84   //    public void setQueuePrefetch(Integer integer) {
   85   //        super.setQueuePrefetch(integer);
   86   //    }
   87   //
   88   //    /**
   89   //     * 5	 The multiplier to use if exponential back off is enabled. Also configurable on the ActivationSpec.
   90   //     * @param aShort
   91   //     */
   92   //    public void setRedeliveryBackOffMultiplier(Short aShort) {
   93   //        super.setRedeliveryBackOffMultiplier(aShort);
   94   //    }
   95   //
   96   //    public void setRedeliveryUseExponentialBackOff(Boolean aBoolean) {
   97   //        super.setRedeliveryUseExponentialBackOff(aBoolean);
   98   //    }
   99   //
  100   //    /**
  101   //     * 32766  The maximum number of messages sent to a consumer on a non-durable topic until acknowledgements are received
  102   //     * @param integer
  103   //     */
  104   //    public void setTopicPrefetch(Integer integer) {
  105   //        super.setTopicPrefetch(integer);
  106   //    }
  107   
  108       public void start(BootstrapContext bootstrapContext) throws ResourceAdapterInternalException {
  109           Properties properties = new Properties();
  110   
  111           // add data source property
  112           if (dataSource != null) {
  113               properties.put("DataSource", dataSource);
  114           }
  115   
  116           // prefix server uri with openejb: so our broker factory is used
  117           String brokerXmlConfig = getBrokerXmlConfig();
  118           if (brokerXmlConfig != null && brokerXmlConfig.startsWith("broker:")) {
  119               try {
  120                   URISupport.CompositeData compositeData = URISupport.parseComposite(new URI(brokerXmlConfig));
  121                   compositeData.getParameters().put("persistent", "false");
  122                   setBrokerXmlConfig("openejb:" + compositeData.toURI());
  123               } catch (URISyntaxException e) {
  124                   throw new ResourceAdapterInternalException("Invalid BrokerXmlConfig", e);
  125               }
  126           }
  127   
  128           OpenEjbBrokerFactory.setThreadProperties(properties);
  129           try {
  130               super.start(bootstrapContext);
  131           } finally {
  132               OpenEjbBrokerFactory.setThreadProperties(null);
  133   
  134               // reset brokerXmlConfig
  135               if (brokerXmlConfig != null) {
  136                   setBrokerXmlConfig(brokerXmlConfig);
  137               }
  138           }
  139       }
  140   }

Home » openejb-3.1.2-src » org.apache » openejb » resource » activemq » [javadoc | source]