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.network;
018    
019    import org.apache.activemq.advisory.AdvisorySupport;
020    import org.apache.activemq.command.ActiveMQDestination;
021    import org.apache.activemq.command.ConsumerInfo;
022    import org.slf4j.Logger;
023    import org.slf4j.LoggerFactory;
024    
025    import java.util.List;
026    import java.util.concurrent.CopyOnWriteArrayList;
027    
028    /**
029     * Configuration for a NetworkBridge
030     */
031    public class NetworkBridgeConfiguration {
032        private static final Logger LOG = LoggerFactory.getLogger(NetworkBridgeConfiguration.class);
033    
034        private boolean conduitSubscriptions = true;
035        private boolean dynamicOnly;
036        private boolean dispatchAsync = true;
037        private boolean decreaseNetworkConsumerPriority;
038        private int consumerPriorityBase = ConsumerInfo.NETWORK_CONSUMER_PRIORITY;
039        private boolean duplex;
040        private boolean bridgeTempDestinations = true;
041        private int prefetchSize = 1000;
042        private int networkTTL = 1;
043        private String brokerName = "localhost";
044        private String brokerURL = "";
045        private String userName;
046        private String password;
047        private String destinationFilter = null;
048        private String name = "NC";
049    
050        protected List<ActiveMQDestination> excludedDestinations = new CopyOnWriteArrayList<ActiveMQDestination>();
051        protected List<ActiveMQDestination> dynamicallyIncludedDestinations = new CopyOnWriteArrayList<ActiveMQDestination>();
052        protected List<ActiveMQDestination> staticallyIncludedDestinations = new CopyOnWriteArrayList<ActiveMQDestination>();
053    
054        private boolean suppressDuplicateQueueSubscriptions = false;
055        private boolean suppressDuplicateTopicSubscriptions = true;
056    
057        private boolean alwaysSyncSend = true;
058        private boolean staticBridge = false;
059        private boolean useCompression = false;
060        private boolean advisoryForFailedForward = false;
061    
062        /**
063         * @return the conduitSubscriptions
064         */
065        public boolean isConduitSubscriptions() {
066            return this.conduitSubscriptions;
067        }
068    
069        /**
070         * @param conduitSubscriptions the conduitSubscriptions to set
071         */
072        public void setConduitSubscriptions(boolean conduitSubscriptions) {
073            this.conduitSubscriptions = conduitSubscriptions;
074        }
075    
076        /**
077         * @return the dynamicOnly
078         */
079        public boolean isDynamicOnly() {
080            return this.dynamicOnly;
081        }
082    
083        /**
084         * @param dynamicOnly the dynamicOnly to set
085         */
086        public void setDynamicOnly(boolean dynamicOnly) {
087            this.dynamicOnly = dynamicOnly;
088        }
089    
090        /**
091         * @return the bridgeTempDestinations
092         */
093        public boolean isBridgeTempDestinations() {
094            return this.bridgeTempDestinations;
095        }
096    
097        /**
098         * @param bridgeTempDestinations the bridgeTempDestinations to set
099         */
100        public void setBridgeTempDestinations(boolean bridgeTempDestinations) {
101            this.bridgeTempDestinations = bridgeTempDestinations;
102        }
103    
104        /**
105         * @return the decreaseNetworkConsumerPriority
106         */
107        public boolean isDecreaseNetworkConsumerPriority() {
108            return this.decreaseNetworkConsumerPriority;
109        }
110    
111        /**
112         * @param decreaseNetworkConsumerPriority the
113         *                decreaseNetworkConsumerPriority to set
114         */
115        public void setDecreaseNetworkConsumerPriority(boolean decreaseNetworkConsumerPriority) {
116            this.decreaseNetworkConsumerPriority = decreaseNetworkConsumerPriority;
117        }
118    
119        /**
120         * @return the dispatchAsync
121         */
122        public boolean isDispatchAsync() {
123            return this.dispatchAsync;
124        }
125    
126        /**
127         * @param dispatchAsync the dispatchAsync to set
128         */
129        public void setDispatchAsync(boolean dispatchAsync) {
130            this.dispatchAsync = dispatchAsync;
131        }
132    
133        /**
134         * @return the duplex
135         */
136        public boolean isDuplex() {
137            return this.duplex;
138        }
139    
140        /**
141         * @param duplex the duplex to set
142         */
143        public void setDuplex(boolean duplex) {
144            this.duplex = duplex;
145        }
146    
147        /**
148         * @return the brokerName
149         */
150        public String getBrokerName() {
151            return this.brokerName;
152        }
153    
154        /**
155         * @param brokerName the localBrokerName to set
156         */
157        public void setBrokerName(String brokerName) {
158            this.brokerName = brokerName;
159        }
160    
161        /**
162         * @return the networkTTL
163         */
164        public int getNetworkTTL() {
165            return this.networkTTL;
166        }
167    
168        /**
169         * @param networkTTL the networkTTL to set
170         */
171        public void setNetworkTTL(int networkTTL) {
172            this.networkTTL = networkTTL;
173        }
174    
175        /**
176         * @return the password
177         */
178        public String getPassword() {
179            return this.password;
180        }
181    
182        /**
183         * @param password the password to set
184         */
185        public void setPassword(String password) {
186            this.password = password;
187        }
188    
189        /**
190         * @return the prefetchSize
191         */
192        public int getPrefetchSize() {
193            return this.prefetchSize;
194        }
195    
196        /**
197         * @param prefetchSize the prefetchSize to set
198         * @org.apache.xbean.Property propertyEditor="org.apache.activemq.util.MemoryIntPropertyEditor"
199         */
200        public void setPrefetchSize(int prefetchSize) {
201            this.prefetchSize = prefetchSize;
202        }
203    
204        /**
205         * @return the userName
206         */
207        public String getUserName() {
208            return this.userName;
209        }
210    
211        /**
212         * @param userName the userName to set
213         */
214        public void setUserName(String userName) {
215            this.userName = userName;
216        }
217    
218        /**
219         * @return the destinationFilter
220         */
221        public String getDestinationFilter() {
222            if (this.destinationFilter == null) {
223                if (dynamicallyIncludedDestinations != null && !dynamicallyIncludedDestinations.isEmpty()) {
224                    StringBuffer filter = new StringBuffer();
225                    String delimiter = "";
226                    for (ActiveMQDestination destination : dynamicallyIncludedDestinations) {
227                        if (!destination.isTemporary()) {
228                            filter.append(delimiter);
229                            filter.append(AdvisorySupport.CONSUMER_ADVISORY_TOPIC_PREFIX);
230                            filter.append(destination.getDestinationTypeAsString());
231                            filter.append(".");
232                            filter.append(destination.getPhysicalName());
233                            delimiter = ",";
234                        }
235                    }
236                    return filter.toString();
237                }   else {
238                    return AdvisorySupport.CONSUMER_ADVISORY_TOPIC_PREFIX + ">";
239                }
240            } else {
241                // prepend consumer advisory prefix
242                // to keep backward compatibility
243                if (!this.destinationFilter.startsWith(AdvisorySupport.CONSUMER_ADVISORY_TOPIC_PREFIX)) {
244                     return AdvisorySupport.CONSUMER_ADVISORY_TOPIC_PREFIX + this.destinationFilter;
245                } else {
246                    return this.destinationFilter;
247                }
248            }
249        }
250    
251        /**
252         * @param destinationFilter the destinationFilter to set
253         */
254        public void setDestinationFilter(String destinationFilter) {
255            this.destinationFilter = destinationFilter;
256        }
257    
258        /**
259         * @return the name
260         */
261        public String getName() {
262            return this.name;
263        }
264    
265        /**
266         * @param name the name to set
267         */
268        public void setName(String name) {
269            this.name = name;
270        }
271    
272        public List<ActiveMQDestination> getExcludedDestinations() {
273            return excludedDestinations;
274        }
275    
276        public void setExcludedDestinations(
277                List<ActiveMQDestination> excludedDestinations) {
278            this.excludedDestinations = excludedDestinations;
279        }
280    
281        public List<ActiveMQDestination> getDynamicallyIncludedDestinations() {
282            return dynamicallyIncludedDestinations;
283        }
284    
285        public void setDynamicallyIncludedDestinations(
286                List<ActiveMQDestination> dynamicallyIncludedDestinations) {
287            this.dynamicallyIncludedDestinations = dynamicallyIncludedDestinations;
288        }
289    
290        public List<ActiveMQDestination> getStaticallyIncludedDestinations() {
291            return staticallyIncludedDestinations;
292        }
293    
294        public void setStaticallyIncludedDestinations(
295                List<ActiveMQDestination> staticallyIncludedDestinations) {
296            this.staticallyIncludedDestinations = staticallyIncludedDestinations;
297        }
298    
299        public boolean isSuppressDuplicateQueueSubscriptions() {
300            return suppressDuplicateQueueSubscriptions;
301        }
302    
303        /**
304         *
305         * @param val if true, duplicate network queue subscriptions (in a cyclic network) will be suppressed
306         */
307        public void setSuppressDuplicateQueueSubscriptions(boolean val) {
308            suppressDuplicateQueueSubscriptions = val;
309        }
310    
311        public boolean isSuppressDuplicateTopicSubscriptions() {
312            return suppressDuplicateTopicSubscriptions;
313        }
314    
315        /**
316         *
317         * @param val if true, duplicate network topic subscriptions (in a cyclic network) will be suppressed
318         */
319        public void setSuppressDuplicateTopicSubscriptions(boolean val) {
320            suppressDuplicateTopicSubscriptions  = val;
321        }
322    
323        /**
324         * @return the brokerURL
325         */
326        public String getBrokerURL() {
327            return this.brokerURL;
328        }
329    
330        /**
331         * @param brokerURL the brokerURL to set
332         */
333        public void setBrokerURL(String brokerURL) {
334            this.brokerURL = brokerURL;
335        }
336    
337        public boolean isAlwaysSyncSend() {
338            return alwaysSyncSend;
339        }
340    
341        /**
342         * @param alwaysSyncSend  when true, both persistent and non persistent
343         * messages will be sent using a request. When false, non persistent messages
344         * are acked once the oneway send succeeds, which can potentially lead to
345         * message loss.
346         * Using an async request, allows multiple outstanding requests. This ensures
347         * that a bridge need not block all sending when the remote broker needs to
348         * flow control a single destination.
349         */
350        public void setAlwaysSyncSend(boolean alwaysSyncSend) {
351            this.alwaysSyncSend = alwaysSyncSend;
352        }
353    
354        public int getConsumerPriorityBase() {
355            return consumerPriorityBase;
356        }
357    
358        /**
359         * @param consumerPriorityBase , default -5. Sets the starting priority
360         * for consumers. This base value will be decremented by the length of the
361         * broker path when decreaseNetworkConsumerPriority is set.
362         */
363        public void setConsumerPriorityBase(int consumerPriorityBase) {
364            this.consumerPriorityBase = consumerPriorityBase;
365        }
366    
367        public boolean isStaticBridge() {
368            return staticBridge;
369        }
370    
371        public void setStaticBridge(boolean staticBridge) {
372            this.staticBridge = staticBridge;
373        }
374    
375        /**
376         * @param useCompression
377         *      True if the Network should enforce compression for messages sent.
378         */
379        public void setUseCompression(boolean useCompression) {
380            this.useCompression = useCompression;
381        }
382    
383        /**
384         * @return the useCompression setting, true if message will be compressed on send.
385         */
386        public boolean isUseCompression() {
387            return useCompression;
388        }
389    
390        public boolean isAdvisoryForFailedForward() {
391            return advisoryForFailedForward;
392        }
393    
394        public void setAdvisoryForFailedForward(boolean advisoryForFailedForward) {
395            this.advisoryForFailedForward = advisoryForFailedForward;
396        }
397    }