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