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