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