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: 664624 $ 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 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(Boolean.TRUE); 098 return this; 099 } 100 101 public RedeliveryPolicyType useExponentialBackOff() { 102 setUseExponentialBackOff(Boolean.TRUE); 103 return this; 104 } 105 106 // Properties 107 //------------------------------------------------------------------------- 108 109 public Double getBackOffMultiplier() { 110 return backOffMultiplier; 111 } 112 113 public void setBackOffMultiplier(Double backOffMultiplier) { 114 this.backOffMultiplier = backOffMultiplier; 115 } 116 117 public Double getCollisionAvoidanceFactor() { 118 return collisionAvoidanceFactor; 119 } 120 121 public void setCollisionAvoidanceFactor(Double collisionAvoidanceFactor) { 122 this.collisionAvoidanceFactor = collisionAvoidanceFactor; 123 } 124 125 public Long getInitialRedeliveryDelay() { 126 return initialRedeliveryDelay; 127 } 128 129 public void setInitialRedeliveryDelay(Long initialRedeliveryDelay) { 130 this.initialRedeliveryDelay = initialRedeliveryDelay; 131 } 132 133 public Integer getMaximumRedeliveries() { 134 return maximumRedeliveries; 135 } 136 137 public void setMaximumRedeliveries(Integer maximumRedeliveries) { 138 this.maximumRedeliveries = maximumRedeliveries; 139 } 140 141 public Boolean getUseCollisionAvoidance() { 142 return useCollisionAvoidance; 143 } 144 145 public void setUseCollisionAvoidance(Boolean useCollisionAvoidance) { 146 this.useCollisionAvoidance = useCollisionAvoidance; 147 } 148 149 public Boolean getUseExponentialBackOff() { 150 return useExponentialBackOff; 151 } 152 153 public void setUseExponentialBackOff(Boolean useExponentialBackOff) { 154 this.useExponentialBackOff = useExponentialBackOff; 155 } 156 }