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