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