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.aggregate.OptimisticLockRetryPolicy;
025    
026    /**
027     * Represents an XML <optimisticLockRetryPolicy/> element
028     *
029     * @version
030     */
031    @XmlRootElement(name = "optimisticLockRetryPolicy")
032    @XmlAccessorType(XmlAccessType.FIELD)
033    public class OptimisticLockRetryPolicyDefinition {
034        @XmlAttribute
035        private Integer maximumRetries;
036        @XmlAttribute
037        private Long retryDelay;
038        @XmlAttribute
039        private Long maximumRetryDelay;
040        @XmlAttribute
041        private Boolean exponentialBackOff;
042        @XmlAttribute
043        private Boolean randomBackOff;
044    
045        public OptimisticLockRetryPolicyDefinition() {
046        }
047    
048        public OptimisticLockRetryPolicy createOptimisticLockRetryPolicy() {
049            OptimisticLockRetryPolicy policy = new OptimisticLockRetryPolicy();
050            if (maximumRetries != null) {
051                policy.setMaximumRetries(maximumRetries);
052            }
053            if (retryDelay != null) {
054                policy.setRetryDelay(retryDelay);
055            }
056            if (maximumRetryDelay != null) {
057                policy.setMaximumRetryDelay(maximumRetryDelay);
058            }
059            if (exponentialBackOff != null) {
060                policy.setExponentialBackOff(exponentialBackOff);
061            }
062            if (randomBackOff != null) {
063                policy.setRandomBackOff(randomBackOff);
064            }
065            return policy;
066        }
067    
068        public OptimisticLockRetryPolicyDefinition maximumRetries(int maximumRetries) {
069            setMaximumRetries(maximumRetries);
070            return this;
071        }
072    
073        public Integer getMaximumRetries() {
074            return maximumRetries;
075        }
076    
077        public void setMaximumRetries(Integer maximumRetries) {
078            this.maximumRetries = maximumRetries;
079        }
080    
081        public OptimisticLockRetryPolicyDefinition retryDelay(long retryDelay) {
082            setRetryDelay(retryDelay);
083            return this;
084        }
085    
086        public Long getRetryDelay() {
087            return retryDelay;
088        }
089    
090        public void setRetryDelay(Long retryDelay) {
091            this.retryDelay = retryDelay;
092        }
093    
094        public OptimisticLockRetryPolicyDefinition maximumRetryDelay(long maximumRetryDelay) {
095            setMaximumRetryDelay(maximumRetryDelay);
096            return this;
097        }
098    
099        public Long getMaximumRetryDelay() {
100            return maximumRetryDelay;
101        }
102    
103        public void setMaximumRetryDelay(Long maximumRetryDelay) {
104            this.maximumRetryDelay = maximumRetryDelay;
105        }
106    
107        public OptimisticLockRetryPolicyDefinition exponentialBackOff() {
108            return exponentialBackOff(true);
109        }
110    
111        public OptimisticLockRetryPolicyDefinition exponentialBackOff(boolean exponentialBackOff) {
112            setExponentialBackOff(exponentialBackOff);
113            return this;
114        }
115    
116        public Boolean getExponentialBackOff() {
117            return exponentialBackOff;
118        }
119    
120        public void setExponentialBackOff(Boolean exponentialBackOff) {
121            this.exponentialBackOff = exponentialBackOff;
122        }
123    
124        public OptimisticLockRetryPolicyDefinition randomBackOff() {
125            return randomBackOff(true);
126        }
127    
128        public OptimisticLockRetryPolicyDefinition randomBackOff(boolean randomBackOff) {
129            setRandomBackOff(randomBackOff);
130            return this;
131        }
132    
133        public Boolean getRandomBackOff() {
134            return randomBackOff;
135        }
136    
137        public void setRandomBackOff(Boolean randomBackOff) {
138            this.randomBackOff = randomBackOff;
139        }
140    }