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