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.camel.model; 018 019 import javax.xml.bind.annotation.XmlAccessType; 020 import javax.xml.bind.annotation.XmlAccessorType; 021 import javax.xml.bind.annotation.XmlAttribute; 022 import javax.xml.bind.annotation.XmlRootElement; 023 024 import org.apache.camel.processor.RedeliveryPolicy; 025 026 /** 027 * Represents an XML <redeliveryPolicy/> element 028 * 029 * @version $Revision: 706818 $ 030 */ 031 @XmlRootElement(name = "redeliveryPolicy") 032 @XmlAccessorType(XmlAccessType.FIELD) 033 public class RedeliveryPolicyType { 034 @XmlAttribute 035 private Integer maximumRedeliveries; 036 @XmlAttribute 037 private Long initialRedeliveryDelay; 038 @XmlAttribute 039 private Double backOffMultiplier; 040 @XmlAttribute 041 private Boolean useExponentialBackOff; 042 @XmlAttribute 043 private Double collisionAvoidanceFactor; 044 @XmlAttribute 045 private Boolean useCollisionAvoidance; 046 @XmlAttribute 047 private Long maximumRedeliveryDelay; 048 049 public RedeliveryPolicy createRedeliveryPolicy(RedeliveryPolicy parentPolicy) { 050 RedeliveryPolicy answer = parentPolicy.copy(); 051 052 // copy across the properties - if they are set 053 if (maximumRedeliveries != null) { 054 answer.setMaximumRedeliveries(maximumRedeliveries); 055 } 056 if (initialRedeliveryDelay != null) { 057 answer.setDelay(initialRedeliveryDelay); 058 } 059 if (backOffMultiplier != null) { 060 answer.setBackOffMultiplier(backOffMultiplier); 061 } 062 if (useExponentialBackOff != null) { 063 answer.setUseExponentialBackOff(useExponentialBackOff); 064 } 065 if (collisionAvoidanceFactor != null) { 066 answer.setCollisionAvoidanceFactor(collisionAvoidanceFactor); 067 } 068 if (useCollisionAvoidance != null) { 069 answer.setUseCollisionAvoidance(useCollisionAvoidance); 070 } 071 if (maximumRedeliveryDelay != null) { 072 answer.setMaximumRedeliveryDelay(maximumRedeliveryDelay); 073 } 074 return answer; 075 } 076 077 public String toString() { 078 return "RedeliveryPolicy[maximumRedeliveries: " + maximumRedeliveries + "]"; 079 } 080 081 // Fluent API 082 //------------------------------------------------------------------------- 083 public RedeliveryPolicyType backOffMultiplier(double backOffMultiplier) { 084 setBackOffMultiplier(backOffMultiplier); 085 return this; 086 } 087 088 public RedeliveryPolicyType collisionAvoidancePercent(double collisionAvoidancePercent) { 089 setCollisionAvoidanceFactor(collisionAvoidancePercent * 0.01d); 090 return this; 091 } 092 093 public RedeliveryPolicyType collisionAvoidanceFactor(double collisionAvoidanceFactor) { 094 setCollisionAvoidanceFactor(collisionAvoidanceFactor); 095 return this; 096 } 097 098 public RedeliveryPolicyType initialRedeliveryDelay(long initialRedeliveryDelay) { 099 setInitialRedeliveryDelay(initialRedeliveryDelay); 100 return this; 101 } 102 103 public RedeliveryPolicyType maximumRedeliveries(int maximumRedeliveries) { 104 setMaximumRedeliveries(maximumRedeliveries); 105 return this; 106 } 107 108 public RedeliveryPolicyType useCollisionAvoidance() { 109 setUseCollisionAvoidance(Boolean.TRUE); 110 return this; 111 } 112 113 public RedeliveryPolicyType useExponentialBackOff() { 114 setUseExponentialBackOff(Boolean.TRUE); 115 return this; 116 } 117 118 public RedeliveryPolicyType maximumRedeliveryDelay(long maximumRedeliveryDelay) { 119 setMaximumRedeliveryDelay(maximumRedeliveryDelay); 120 return this; 121 } 122 123 // Properties 124 //------------------------------------------------------------------------- 125 126 public Double getBackOffMultiplier() { 127 return backOffMultiplier; 128 } 129 130 public void setBackOffMultiplier(Double backOffMultiplier) { 131 this.backOffMultiplier = backOffMultiplier; 132 } 133 134 public Double getCollisionAvoidanceFactor() { 135 return collisionAvoidanceFactor; 136 } 137 138 public void setCollisionAvoidanceFactor(Double collisionAvoidanceFactor) { 139 this.collisionAvoidanceFactor = collisionAvoidanceFactor; 140 } 141 142 public Long getInitialRedeliveryDelay() { 143 return initialRedeliveryDelay; 144 } 145 146 public void setInitialRedeliveryDelay(Long initialRedeliveryDelay) { 147 this.initialRedeliveryDelay = initialRedeliveryDelay; 148 } 149 150 public Integer getMaximumRedeliveries() { 151 return maximumRedeliveries; 152 } 153 154 public void setMaximumRedeliveries(Integer maximumRedeliveries) { 155 this.maximumRedeliveries = maximumRedeliveries; 156 } 157 158 public Boolean getUseCollisionAvoidance() { 159 return useCollisionAvoidance; 160 } 161 162 public void setUseCollisionAvoidance(Boolean useCollisionAvoidance) { 163 this.useCollisionAvoidance = useCollisionAvoidance; 164 } 165 166 public Boolean getUseExponentialBackOff() { 167 return useExponentialBackOff; 168 } 169 170 public void setUseExponentialBackOff(Boolean useExponentialBackOff) { 171 this.useExponentialBackOff = useExponentialBackOff; 172 } 173 174 public Long getMaximumRedeliveryDelay() { 175 return maximumRedeliveryDelay; 176 } 177 178 public void setMaximumRedeliveryDelay(Long maximumRedeliveryDelay) { 179 this.maximumRedeliveryDelay = maximumRedeliveryDelay; 180 } 181 }