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: */package org.apache.openejb.resource.activemq;
018:
019: import java.net.URI;
020: import java.net.URISyntaxException;
021: import java.util.Properties;
022: import javax.resource.spi.BootstrapContext;
023: import javax.resource.spi.ResourceAdapterInternalException;
024:
025: import org.apache.openejb.util.URISupport;
026:
027: public class ActiveMQResourceAdapter extends
028: org.apache.activemq.ra.ActiveMQResourceAdapter {
029: private String dataSource;
030:
031: public String getDataSource() {
032: return dataSource;
033: }
034:
035: public void setDataSource(String dataSource) {
036: this .dataSource = dataSource;
037: }
038:
039: // DMB: Work in progress. These all should go into the service-jar.xml
040: // Sources of info:
041: // - http://activemq.apache.org/resource-adapter-properties.html
042: // - http://activemq.apache.org/camel/maven/camel-core/apidocs/org/apache/camel/processor/RedeliveryPolicy.html
043: //
044: // /**
045: // * 100 The maximum number of messages sent to a consumer on a durable topic until acknowledgements are received
046: // * @param integer
047: // */
048: // public void setDurableTopicPrefetch(Integer integer) {
049: // super.setDurableTopicPrefetch(integer);
050: // }
051: //
052: // /**
053: // * 1000 The delay before redeliveries start. Also configurable on the ActivationSpec.
054: // * @param aLong
055: // */
056: // public void setInitialRedeliveryDelay(Long aLong) {
057: // super.setInitialRedeliveryDelay(aLong);
058: // }
059: //
060: // /**
061: // * 100 The maximum number of messages sent to a consumer on a JMS stream until acknowledgements are received
062: // * @param integer
063: // */
064: // public void setInputStreamPrefetch(Integer integer) {
065: // super.setInputStreamPrefetch(integer);
066: // }
067: //
068: // /**
069: // * 5 The maximum number of redeliveries or -1 for no maximum. Also configurable on the ActivationSpec.
070: // * @param integer
071: // */
072: // public void setMaximumRedeliveries(Integer integer) {
073: // super.setMaximumRedeliveries(integer);
074: // }
075: //
076: // public void setQueueBrowserPrefetch(Integer integer) {
077: // super.setQueueBrowserPrefetch(integer);
078: // }
079: //
080: // /**
081: // * 1000 The maximum number of messages sent to a consumer on a queue until acknowledgements are received
082: // * @param integer
083: // */
084: // public void setQueuePrefetch(Integer integer) {
085: // super.setQueuePrefetch(integer);
086: // }
087: //
088: // /**
089: // * 5 The multiplier to use if exponential back off is enabled. Also configurable on the ActivationSpec.
090: // * @param aShort
091: // */
092: // public void setRedeliveryBackOffMultiplier(Short aShort) {
093: // super.setRedeliveryBackOffMultiplier(aShort);
094: // }
095: //
096: // public void setRedeliveryUseExponentialBackOff(Boolean aBoolean) {
097: // super.setRedeliveryUseExponentialBackOff(aBoolean);
098: // }
099: //
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)
109: throws ResourceAdapterInternalException {
110: Properties properties = new Properties();
111:
112: // add data source property
113: if (dataSource != null) {
114: properties.put("DataSource", dataSource);
115: }
116:
117: // prefix server uri with openejb: so our broker factory is used
118: String brokerXmlConfig = getBrokerXmlConfig();
119: if (brokerXmlConfig != null) {
120: try {
121: URISupport.CompositeData compositeData = URISupport
122: .parseComposite(new URI(brokerXmlConfig));
123: compositeData.getParameters()
124: .put("persistent", "false");
125: setBrokerXmlConfig("openejb:" + compositeData.toURI());
126: } catch (URISyntaxException e) {
127: throw new ResourceAdapterInternalException(
128: "Invalid BrokerXmlConfig", e);
129: }
130: }
131:
132: OpenEjbBrokerFactory.setThreadProperties(properties);
133: try {
134: super .start(bootstrapContext);
135: } finally {
136: OpenEjbBrokerFactory.setThreadProperties(null);
137:
138: // reset brokerXmlConfig
139: if (brokerXmlConfig != null) {
140: setBrokerXmlConfig(brokerXmlConfig);
141: }
142: }
143: }
144: }
|