001 /** 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one or more 004 * contributor license agreements. See the NOTICE file distributed with 005 * this work for additional information regarding copyright ownership. 006 * The ASF licenses this file to You under the Apache License, Version 2.0 007 * (the "License"); you may not use this file except in compliance with 008 * the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 package org.apache.camel.model; 019 020 import org.apache.camel.processor.RedeliveryPolicy; 021 022 import javax.xml.bind.annotation.XmlAccessType; 023 import javax.xml.bind.annotation.XmlAccessorType; 024 import javax.xml.bind.annotation.XmlRootElement; 025 026 /** 027 * @version $Revision: 1.1 $ 028 */ 029 @XmlRootElement(name = "redeliveryPolicy") 030 @XmlAccessorType(XmlAccessType.FIELD) 031 public class RedeliveryPolicyType { 032 private Integer maximumRedeliveries; 033 private Long initialRedeliveryDelay; 034 private Double backOffMultiplier; 035 private Boolean useExponentialBackOff; 036 private Double collisionAvoidanceFactor; 037 private Boolean useCollisionAvoidance; 038 039 040 public RedeliveryPolicy createRedeliveryPolicy(RedeliveryPolicy parentPolicy) { 041 RedeliveryPolicy answer = parentPolicy.copy(); 042 043 // copy across the properties - if they are set 044 if (maximumRedeliveries != null) { 045 answer.setMaximumRedeliveries(maximumRedeliveries); 046 } 047 if (initialRedeliveryDelay != null) { 048 answer.setInitialRedeliveryDelay(initialRedeliveryDelay); 049 } 050 if (backOffMultiplier != null) { 051 answer.setBackOffMultiplier(backOffMultiplier); 052 } 053 if (useExponentialBackOff != null) { 054 answer.setUseExponentialBackOff(useExponentialBackOff); 055 } 056 if (collisionAvoidanceFactor != null) { 057 answer.setCollisionAvoidanceFactor(collisionAvoidanceFactor); 058 } 059 if (useCollisionAvoidance != null) { 060 answer.setUseCollisionAvoidance(useCollisionAvoidance); 061 } 062 return answer; 063 } 064 065 public String toString() { 066 return "RedeliveryPolicy[maxRedeliveries: " + maximumRedeliveries + "]"; 067 } 068 069 // Fluent API 070 //------------------------------------------------------------------------- 071 public RedeliveryPolicyType backOffMultiplier(double backOffMultiplier) { 072 setBackOffMultiplier(backOffMultiplier); 073 return this; 074 } 075 076 public RedeliveryPolicyType collisionAvoidancePercent(double collisionAvoidancePercent) { 077 setCollisionAvoidanceFactor(collisionAvoidancePercent * 0.01d); 078 return this; 079 } 080 081 public RedeliveryPolicyType collisionAvoidanceFactor(double collisionAvoidanceFactor) { 082 setCollisionAvoidanceFactor(collisionAvoidanceFactor); 083 return this; 084 } 085 086 public RedeliveryPolicyType initialRedeliveryDelay(long initialRedeliveryDelay) { 087 setInitialRedeliveryDelay(initialRedeliveryDelay); 088 return this; 089 } 090 091 public RedeliveryPolicyType maximumRedeliveries(int maximumRedeliveries) { 092 setMaximumRedeliveries(maximumRedeliveries); 093 return this; 094 } 095 096 public RedeliveryPolicyType useCollisionAvoidance() { 097 setUseCollisionAvoidance(true); 098 return this; 099 } 100 101 public RedeliveryPolicyType useExponentialBackOff() { 102 setUseExponentialBackOff(true); 103 return this; 104 } 105 106 107 108 109 // Properties 110 //------------------------------------------------------------------------- 111 112 public Double getBackOffMultiplier() { 113 return backOffMultiplier; 114 } 115 116 public void setBackOffMultiplier(Double backOffMultiplier) { 117 this.backOffMultiplier = backOffMultiplier; 118 } 119 120 public Double getCollisionAvoidanceFactor() { 121 return collisionAvoidanceFactor; 122 } 123 124 public void setCollisionAvoidanceFactor(Double collisionAvoidanceFactor) { 125 this.collisionAvoidanceFactor = collisionAvoidanceFactor; 126 } 127 128 public Long getInitialRedeliveryDelay() { 129 return initialRedeliveryDelay; 130 } 131 132 public void setInitialRedeliveryDelay(Long initialRedeliveryDelay) { 133 this.initialRedeliveryDelay = initialRedeliveryDelay; 134 } 135 136 public Integer getMaximumRedeliveries() { 137 return maximumRedeliveries; 138 } 139 140 public void setMaximumRedeliveries(Integer maximumRedeliveries) { 141 this.maximumRedeliveries = maximumRedeliveries; 142 } 143 144 public Boolean getUseCollisionAvoidance() { 145 return useCollisionAvoidance; 146 } 147 148 public void setUseCollisionAvoidance(Boolean useCollisionAvoidance) { 149 this.useCollisionAvoidance = useCollisionAvoidance; 150 } 151 152 public Boolean getUseExponentialBackOff() { 153 return useExponentialBackOff; 154 } 155 156 public void setUseExponentialBackOff(Boolean useExponentialBackOff) { 157 this.useExponentialBackOff = useExponentialBackOff; 158 } 159 }