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