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 */
017package org.apache.activemq.network;
018
019import java.util.List;
020import java.util.concurrent.CopyOnWriteArrayList;
021
022import org.apache.activemq.advisory.AdvisorySupport;
023import org.apache.activemq.command.ActiveMQDestination;
024import org.apache.activemq.command.ConsumerInfo;
025
026/**
027 * Configuration for a NetworkBridge
028 */
029public class NetworkBridgeConfiguration {
030
031    private boolean conduitSubscriptions = true;
032    private boolean useVirtualDestSubs;
033    private boolean dynamicOnly;
034    private boolean syncDurableSubs;
035    private boolean dispatchAsync = true;
036    private boolean decreaseNetworkConsumerPriority;
037    private int consumerPriorityBase = ConsumerInfo.NETWORK_CONSUMER_PRIORITY;
038    private boolean duplex;
039    private boolean bridgeTempDestinations = true;
040    private int prefetchSize = 1000;
041    /**
042     * By default set to 0, which is disabled and prefetchSize value will be
043     * used instead.
044     */
045    private int advisoryPrefetchSize = 0;
046    private int advisoryAckPercentage = 75;
047    private int networkTTL = 1;
048    private int consumerTTL = networkTTL;
049    private int messageTTL = networkTTL;
050
051    private String brokerName = "localhost";
052    private String brokerURL = "";
053    private String userName;
054    private String password;
055    private String destinationFilter = null;
056    private String name = "NC";
057
058    protected List<ActiveMQDestination> excludedDestinations = new CopyOnWriteArrayList<ActiveMQDestination>();
059    protected List<ActiveMQDestination> dynamicallyIncludedDestinations = new CopyOnWriteArrayList<ActiveMQDestination>();
060    protected List<ActiveMQDestination> staticallyIncludedDestinations = new CopyOnWriteArrayList<ActiveMQDestination>();
061
062    private boolean suppressDuplicateQueueSubscriptions = false;
063    private boolean suppressDuplicateTopicSubscriptions = true;
064
065    private boolean alwaysSyncSend = true;
066    private boolean staticBridge = false;
067    private boolean useCompression = false;
068    private boolean advisoryForFailedForward = false;
069    private boolean useBrokerNamesAsIdSeed = true;
070    private boolean gcDestinationViews = true;
071    private long gcSweepTime = 60 * 1000;
072    private boolean checkDuplicateMessagesOnDuplex = false;
073
074    /**
075     * @return the conduitSubscriptions
076     */
077    public boolean isConduitSubscriptions() {
078        return this.conduitSubscriptions;
079    }
080
081    /**
082     * @param conduitSubscriptions the conduitSubscriptions to set
083     */
084    public void setConduitSubscriptions(boolean conduitSubscriptions) {
085        this.conduitSubscriptions = conduitSubscriptions;
086    }
087
088    /**
089     * @return the dynamicOnly
090     */
091    public boolean isDynamicOnly() {
092        return this.dynamicOnly;
093    }
094
095    /**
096     * @param dynamicOnly the dynamicOnly to set
097     */
098    public void setDynamicOnly(boolean dynamicOnly) {
099        this.dynamicOnly = dynamicOnly;
100    }
101
102    public boolean isSyncDurableSubs() {
103        return syncDurableSubs;
104    }
105
106    public void setSyncDurableSubs(boolean syncDurableSubs) {
107        this.syncDurableSubs = syncDurableSubs;
108    }
109
110    /**
111     * @return the bridgeTempDestinations
112     */
113    public boolean isBridgeTempDestinations() {
114        return this.bridgeTempDestinations;
115    }
116
117    /**
118     * @param bridgeTempDestinations the bridgeTempDestinations to set
119     */
120    public void setBridgeTempDestinations(boolean bridgeTempDestinations) {
121        this.bridgeTempDestinations = bridgeTempDestinations;
122    }
123
124    /**
125     * @return the decreaseNetworkConsumerPriority
126     */
127    public boolean isDecreaseNetworkConsumerPriority() {
128        return this.decreaseNetworkConsumerPriority;
129    }
130
131    /**
132     * @param decreaseNetworkConsumerPriority the
133     *                decreaseNetworkConsumerPriority to set
134     */
135    public void setDecreaseNetworkConsumerPriority(boolean decreaseNetworkConsumerPriority) {
136        this.decreaseNetworkConsumerPriority = decreaseNetworkConsumerPriority;
137    }
138
139    /**
140     * @return the dispatchAsync
141     */
142    public boolean isDispatchAsync() {
143        return this.dispatchAsync;
144    }
145
146    /**
147     * @param dispatchAsync the dispatchAsync to set
148     */
149    public void setDispatchAsync(boolean dispatchAsync) {
150        this.dispatchAsync = dispatchAsync;
151    }
152
153    /**
154     * @return the duplex
155     */
156    public boolean isDuplex() {
157        return this.duplex;
158    }
159
160    /**
161     * @param duplex the duplex to set
162     */
163    public void setDuplex(boolean duplex) {
164        this.duplex = duplex;
165    }
166
167    /**
168     * @return the brokerName
169     */
170    public String getBrokerName() {
171        return this.brokerName;
172    }
173
174    /**
175     * @param brokerName the localBrokerName to set
176     */
177    public void setBrokerName(String brokerName) {
178        this.brokerName = brokerName;
179    }
180
181    /**
182     * @return the networkTTL
183     */
184    public int getNetworkTTL() {
185        return this.networkTTL;
186    }
187
188    /**
189     * @param networkTTL the networkTTL to set
190     */
191    public void setNetworkTTL(int networkTTL) {
192        this.networkTTL = networkTTL;
193        setConsumerTTL(networkTTL);
194        setMessageTTL(networkTTL);
195    }
196
197    /**
198     * @return the password
199     */
200    public String getPassword() {
201        return this.password;
202    }
203
204    /**
205     * @param password the password to set
206     */
207    public void setPassword(String password) {
208        this.password = password;
209    }
210
211    /**
212     * @return the prefetchSize
213     */
214    public int getPrefetchSize() {
215        return this.prefetchSize;
216    }
217
218    /**
219     * @param prefetchSize the prefetchSize to set
220     * @org.apache.xbean.Property propertyEditor="org.apache.activemq.util.MemoryIntPropertyEditor"
221     */
222    public void setPrefetchSize(int prefetchSize) {
223        if (prefetchSize < 1) {
224            throw new IllegalArgumentException("prefetchSize must be > 0"
225                    + " because network consumers do not poll for messages.");
226        }
227        this.prefetchSize = prefetchSize;
228    }
229
230    public int getAdvisoryPrefetchSize() {
231        return advisoryPrefetchSize;
232    }
233
234    /**
235     * Prefetch size for advisory consumers.  Just like prefetchSize, if set, this
236     * value must be greater than 0 because network consumers do not poll for messages.
237     * Setting this to 0 or less means this value is disabled and prefetchSize will be
238     * used instead.
239     *
240     * @param advisoryPrefetchSize
241     */
242    public void setAdvisoryPrefetchSize(int advisoryPrefetchSize) {
243        this.advisoryPrefetchSize = advisoryPrefetchSize;
244    }
245
246    public int getAdvisoryAckPercentage() {
247        return advisoryAckPercentage;
248    }
249
250    /**
251     * @param advisoryAckPercentage the percentage of the advisory prefetch size
252     * value that can be dispatched before an ack will be sent, defaults to 75
253     * which means that when the number of received messages is greater than 75% of
254     * the prefetch size an ack will be sent back
255     */
256    public void setAdvisoryAckPercentage(int advisoryAckPercentage) {
257        this.advisoryAckPercentage = advisoryAckPercentage;
258    }
259
260    /**
261     * @return the userName
262     */
263    public String getUserName() {
264        return this.userName;
265    }
266
267    /**
268     * @param userName the userName to set
269     */
270    public void setUserName(String userName) {
271        this.userName = userName;
272    }
273
274    /**
275     * @return the destinationFilter
276     */
277    public String getDestinationFilter() {
278        if (this.destinationFilter == null) {
279            if (dynamicallyIncludedDestinations != null && !dynamicallyIncludedDestinations.isEmpty()) {
280                StringBuffer filter = new StringBuffer();
281                String delimiter = "";
282                for (ActiveMQDestination destination : dynamicallyIncludedDestinations) {
283                    if (!destination.isTemporary()) {
284                        filter.append(delimiter);
285                        filter.append(AdvisorySupport.CONSUMER_ADVISORY_TOPIC_PREFIX);
286                        filter.append(destination.getDestinationTypeAsString());
287                        filter.append(".");
288                        filter.append(destination.getPhysicalName());
289                        delimiter = ",";
290
291                        if (useVirtualDestSubs) {
292                            filter.append(delimiter);
293                            filter.append(AdvisorySupport.VIRTUAL_DESTINATION_CONSUMER_ADVISORY_TOPIC_PREFIX);
294                            filter.append(destination.getDestinationTypeAsString());
295                            filter.append(".");
296                            filter.append(destination.getPhysicalName());
297                        }
298                    }
299                }
300                return filter.toString();
301            }   else {
302                StringBuffer filter = new StringBuffer();
303                filter.append(AdvisorySupport.CONSUMER_ADVISORY_TOPIC_PREFIX);
304                filter.append(">");
305                if (useVirtualDestSubs) {
306                    filter.append(",");
307                    filter.append(AdvisorySupport.VIRTUAL_DESTINATION_CONSUMER_ADVISORY_TOPIC_PREFIX);
308                    filter.append(">");
309                }
310                return filter.toString();
311            }
312        } else {
313            // prepend consumer advisory prefix
314            // to keep backward compatibility
315            if (!this.destinationFilter.startsWith(AdvisorySupport.CONSUMER_ADVISORY_TOPIC_PREFIX)) {
316                 return AdvisorySupport.CONSUMER_ADVISORY_TOPIC_PREFIX + this.destinationFilter;
317            } else {
318                return this.destinationFilter;
319            }
320        }
321    }
322
323    /**
324     * @param destinationFilter the destinationFilter to set
325     */
326    public void setDestinationFilter(String destinationFilter) {
327        this.destinationFilter = destinationFilter;
328    }
329
330    /**
331     * @return the name
332     */
333    public String getName() {
334        return this.name;
335    }
336
337    /**
338     * @param name the name to set
339     */
340    public void setName(String name) {
341        this.name = name;
342    }
343
344    public List<ActiveMQDestination> getExcludedDestinations() {
345        return excludedDestinations;
346    }
347
348    public void setExcludedDestinations(
349            List<ActiveMQDestination> excludedDestinations) {
350        this.excludedDestinations = excludedDestinations;
351    }
352
353    public List<ActiveMQDestination> getDynamicallyIncludedDestinations() {
354        return dynamicallyIncludedDestinations;
355    }
356
357    public void setDynamicallyIncludedDestinations(
358            List<ActiveMQDestination> dynamicallyIncludedDestinations) {
359        this.dynamicallyIncludedDestinations = dynamicallyIncludedDestinations;
360    }
361
362    public List<ActiveMQDestination> getStaticallyIncludedDestinations() {
363        return staticallyIncludedDestinations;
364    }
365
366    public void setStaticallyIncludedDestinations(
367            List<ActiveMQDestination> staticallyIncludedDestinations) {
368        this.staticallyIncludedDestinations = staticallyIncludedDestinations;
369    }
370
371    public boolean isSuppressDuplicateQueueSubscriptions() {
372        return suppressDuplicateQueueSubscriptions;
373    }
374
375    /**
376     *
377     * @param val if true, duplicate network queue subscriptions (in a cyclic network) will be suppressed
378     */
379    public void setSuppressDuplicateQueueSubscriptions(boolean val) {
380        suppressDuplicateQueueSubscriptions = val;
381    }
382
383    public boolean isSuppressDuplicateTopicSubscriptions() {
384        return suppressDuplicateTopicSubscriptions;
385    }
386
387    /**
388     *
389     * @param val if true, duplicate network topic subscriptions (in a cyclic network) will be suppressed
390     */
391    public void setSuppressDuplicateTopicSubscriptions(boolean val) {
392        suppressDuplicateTopicSubscriptions  = val;
393    }
394
395    /**
396     * @return the brokerURL
397     */
398    public String getBrokerURL() {
399        return this.brokerURL;
400    }
401
402    /**
403     * @param brokerURL the brokerURL to set
404     */
405    public void setBrokerURL(String brokerURL) {
406        this.brokerURL = brokerURL;
407    }
408
409    public boolean isAlwaysSyncSend() {
410        return alwaysSyncSend;
411    }
412
413    /**
414     * @param alwaysSyncSend  when true, both persistent and non persistent
415     * messages will be sent using a request. When false, non persistent messages
416     * are acked once the oneway send succeeds, which can potentially lead to
417     * message loss.
418     * Using an async request, allows multiple outstanding requests. This ensures
419     * that a bridge need not block all sending when the remote broker needs to
420     * flow control a single destination.
421     */
422    public void setAlwaysSyncSend(boolean alwaysSyncSend) {
423        this.alwaysSyncSend = alwaysSyncSend;
424    }
425
426    public int getConsumerPriorityBase() {
427        return consumerPriorityBase;
428    }
429
430    /**
431     * @param consumerPriorityBase , default -5. Sets the starting priority
432     * for consumers. This base value will be decremented by the length of the
433     * broker path when decreaseNetworkConsumerPriority is set.
434     */
435    public void setConsumerPriorityBase(int consumerPriorityBase) {
436        this.consumerPriorityBase = consumerPriorityBase;
437    }
438
439    public boolean isStaticBridge() {
440        return staticBridge;
441    }
442
443    public void setStaticBridge(boolean staticBridge) {
444        this.staticBridge = staticBridge;
445    }
446
447    /**
448     * @param useCompression
449     *      True if the Network should enforce compression for messages sent.
450     */
451    public void setUseCompression(boolean useCompression) {
452        this.useCompression = useCompression;
453    }
454
455    /**
456     * @return the useCompression setting, true if message will be compressed on send.
457     */
458    public boolean isUseCompression() {
459        return useCompression;
460    }
461
462    public boolean isAdvisoryForFailedForward() {
463        return advisoryForFailedForward;
464    }
465
466    public void setAdvisoryForFailedForward(boolean advisoryForFailedForward) {
467        this.advisoryForFailedForward = advisoryForFailedForward;
468    }
469
470    public void setConsumerTTL(int consumerTTL) {
471        this.consumerTTL = consumerTTL;
472    }
473
474    public int getConsumerTTL() {
475        return  consumerTTL;
476    }
477
478    public void setMessageTTL(int messageTTL) {
479        this.messageTTL = messageTTL;
480    }
481
482    public int getMessageTTL() {
483        return messageTTL;
484    }
485
486    public boolean isUseBrokerNamesAsIdSeed() {
487        return useBrokerNamesAsIdSeed;
488    }
489
490    public void setUseBrokerNameAsIdSees(boolean val) {
491        useBrokerNamesAsIdSeed = val;
492    }
493
494    public boolean isGcDestinationViews() {
495        return gcDestinationViews;
496    }
497
498    public void setGcDestinationViews(boolean gcDestinationViews) {
499        this.gcDestinationViews = gcDestinationViews;
500    }
501
502    public long getGcSweepTime() {
503        return gcSweepTime;
504    }
505
506    public void setGcSweepTime(long gcSweepTime) {
507        this.gcSweepTime = gcSweepTime;
508    }
509
510    public boolean isCheckDuplicateMessagesOnDuplex() {
511        return checkDuplicateMessagesOnDuplex;
512    }
513
514    public void setCheckDuplicateMessagesOnDuplex(boolean checkDuplicateMessagesOnDuplex) {
515        this.checkDuplicateMessagesOnDuplex = checkDuplicateMessagesOnDuplex;
516    }
517
518    public boolean isUseVirtualDestSubs() {
519        return useVirtualDestSubs;
520    }
521
522    /**
523     * This was a typo, so this is deprecated as of 5.13.1
524     */
525    @Deprecated
526    public boolean isUseVirtualDestSus() {
527        return useVirtualDestSubs;
528    }
529
530    public void setUseVirtualDestSubs(
531            boolean useVirtualDestSubs) {
532        this.useVirtualDestSubs = useVirtualDestSubs;
533    }
534
535}