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.activemq.tool.spi;
018    
019    import java.util.Properties;
020    
021    import javax.jms.ConnectionFactory;
022    
023    import org.apache.activemq.ActiveMQConnectionFactory;
024    
025    public class ActiveMQPojoSPI implements SPIConnectionFactory {
026        public static final String KEY_BROKER_URL        = "brokerUrl";
027        public static final String KEY_USERNAME          = "username";
028        public static final String KEY_PASSWORD          = "password";
029        public static final String KEY_CLIENT_ID         = "clientID";
030    
031        public static final String KEY_ASYNC_SEND        = "asyncSend";
032        public static final String KEY_ASYNC_DISPATCH    = "asyncDispatch";
033        public static final String KEY_ASYNC_SESSION     = "asyncSession";
034        public static final String KEY_CLOSE_TIMEOUT     = "closeTimeout";
035        public static final String KEY_COPY_MSG_ON_SEND  = "copyMsgOnSend";
036        public static final String KEY_DISABLE_TIMESTAMP = "disableTimestamp";
037        public static final String KEY_DEFER_OBJ_SERIAL  = "deferObjSerial";
038        public static final String KEY_OPTIM_ACK         = "optimAck";
039        public static final String KEY_OPTIM_DISPATCH    = "optimDispatch";
040        public static final String KEY_PREFETCH_QUEUE    = "prefetchQueue";
041        public static final String KEY_PREFETCH_TOPIC    = "prefetchTopic";
042        public static final String KEY_USE_COMPRESSION   = "useCompression";
043        public static final String KEY_USE_RETROACTIVE   = "useRetroactive";
044    
045        public ConnectionFactory createConnectionFactory(Properties settings) throws Exception {
046            ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
047            configureConnectionFactory(factory, settings);
048            return factory;
049        }
050    
051        public void configureConnectionFactory(ConnectionFactory jmsFactory, Properties settings) throws Exception {
052            ActiveMQConnectionFactory factory = (ActiveMQConnectionFactory)jmsFactory;
053            String setting;
054    
055            setting = settings.getProperty(KEY_BROKER_URL);
056            if (setting != null && setting.length() > 0) {
057                factory.setBrokerURL(setting);
058            }
059    
060            setting = settings.getProperty(KEY_USERNAME);
061            if (setting != null && setting.length() > 0) {
062                factory.setUserName(setting);
063            }
064    
065            setting = settings.getProperty(KEY_PASSWORD);
066            if (setting != null && setting.length() > 0) {
067                factory.setPassword(setting);
068            }
069    
070            setting = settings.getProperty(KEY_CLIENT_ID);
071            if (setting != null && setting.length() > 0) {
072                factory.setClientID(setting);
073            }
074    
075            setting = settings.getProperty(KEY_ASYNC_SEND);
076            if (setting != null && setting.length() > 0) {
077                factory.setUseAsyncSend(Boolean.getBoolean(setting));
078            }
079    
080            setting = settings.getProperty(KEY_ASYNC_DISPATCH);
081            if (setting != null && setting.length() > 0) {
082                factory.setDispatchAsync(Boolean.getBoolean(setting));
083            }
084    
085            setting = settings.getProperty(KEY_ASYNC_SESSION);
086            if (setting != null && setting.length() > 0) {
087                factory.setAlwaysSessionAsync(Boolean.getBoolean(setting));
088            }
089    
090            setting = settings.getProperty(KEY_CLOSE_TIMEOUT);
091            if (setting != null && setting.length() > 0) {
092                factory.setCloseTimeout(Integer.parseInt(setting));
093            }
094    
095            setting = settings.getProperty(KEY_COPY_MSG_ON_SEND);
096            if (setting != null && setting.length() > 0) {
097                factory.setCopyMessageOnSend(Boolean.getBoolean(setting));
098            }
099    
100            setting = settings.getProperty(KEY_DISABLE_TIMESTAMP);
101            if (setting != null && setting.length() > 0) {
102                factory.setDisableTimeStampsByDefault(Boolean.getBoolean(setting));
103            }
104    
105            setting = settings.getProperty(KEY_DEFER_OBJ_SERIAL);
106            if (setting != null && setting.length() > 0) {
107                factory.setObjectMessageSerializationDefered(Boolean.getBoolean(setting));
108            }
109    
110            setting = settings.getProperty(KEY_OPTIM_ACK);
111            if (setting != null && setting.length() > 0) {
112                factory.setOptimizeAcknowledge(Boolean.getBoolean(setting));
113            }
114    
115            setting = settings.getProperty(KEY_OPTIM_DISPATCH);
116            if (setting != null && setting.length() > 0) {
117                factory.setOptimizedMessageDispatch(Boolean.getBoolean(setting));
118            }
119    
120            setting = settings.getProperty(KEY_PREFETCH_QUEUE);
121            if (setting != null && setting.length() > 0) {
122                factory.getPrefetchPolicy().setQueuePrefetch(Integer.parseInt(setting));
123            }
124    
125            setting = settings.getProperty(KEY_PREFETCH_TOPIC);
126            if (setting != null && setting.length() > 0) {
127                factory.getPrefetchPolicy().setTopicPrefetch(Integer.parseInt(setting));
128            }
129    
130            setting = settings.getProperty(KEY_USE_COMPRESSION);
131            if (setting != null && setting.length() > 0) {
132                factory.setUseCompression(Boolean.getBoolean(setting));
133            }
134    
135            setting = settings.getProperty(KEY_USE_RETROACTIVE);
136            if (setting != null && setting.length() > 0) {
137                factory.setUseRetroactiveConsumer(Boolean.getBoolean(setting));
138            }
139        }
140    }