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 */
017package org.apache.camel.model;
018
019import javax.xml.bind.annotation.XmlAccessType;
020import javax.xml.bind.annotation.XmlAccessorType;
021import javax.xml.bind.annotation.XmlAttribute;
022import javax.xml.bind.annotation.XmlRootElement;
023
024import org.apache.camel.spi.Metadata;
025
026/**
027 * To configure optimistic locking
028 */
029@Metadata(label = "configuration")
030@XmlRootElement(name = "optimisticLockRetryPolicy")
031@XmlAccessorType(XmlAccessType.FIELD)
032public class OptimisticLockRetryPolicyDefinition {
033    @XmlAttribute
034    private Integer maximumRetries;
035    @XmlAttribute
036    @Metadata(defaultValue = "50")
037    private Long retryDelay;
038    @XmlAttribute
039    @Metadata(defaultValue = "1000")
040    private Long maximumRetryDelay;
041    @XmlAttribute
042    @Metadata(defaultValue = "true")
043    private Boolean exponentialBackOff;
044    @XmlAttribute
045    private Boolean randomBackOff;
046
047    public OptimisticLockRetryPolicyDefinition() {
048    }
049
050    /**
051     * Sets the maximum number of retries
052     */
053    public OptimisticLockRetryPolicyDefinition maximumRetries(int maximumRetries) {
054        setMaximumRetries(maximumRetries);
055        return this;
056    }
057
058    public Integer getMaximumRetries() {
059        return maximumRetries;
060    }
061
062    public void setMaximumRetries(Integer maximumRetries) {
063        this.maximumRetries = maximumRetries;
064    }
065
066    /**
067     * Sets the delay in millis between retries
068     */
069    public OptimisticLockRetryPolicyDefinition retryDelay(long retryDelay) {
070        setRetryDelay(retryDelay);
071        return this;
072    }
073
074    public Long getRetryDelay() {
075        return retryDelay;
076    }
077
078    public void setRetryDelay(Long retryDelay) {
079        this.retryDelay = retryDelay;
080    }
081
082    /**
083     * Sets the upper value of retry in millis between retries, when using
084     * exponential or random backoff
085     */
086    public OptimisticLockRetryPolicyDefinition maximumRetryDelay(long maximumRetryDelay) {
087        setMaximumRetryDelay(maximumRetryDelay);
088        return this;
089    }
090
091    public Long getMaximumRetryDelay() {
092        return maximumRetryDelay;
093    }
094
095    public void setMaximumRetryDelay(Long maximumRetryDelay) {
096        this.maximumRetryDelay = maximumRetryDelay;
097    }
098
099    /**
100     * Enable exponential backoff
101     */
102    public OptimisticLockRetryPolicyDefinition exponentialBackOff() {
103        return exponentialBackOff(true);
104    }
105
106    public OptimisticLockRetryPolicyDefinition exponentialBackOff(boolean exponentialBackOff) {
107        setExponentialBackOff(exponentialBackOff);
108        return this;
109    }
110
111    public Boolean getExponentialBackOff() {
112        return exponentialBackOff;
113    }
114
115    public void setExponentialBackOff(Boolean exponentialBackOff) {
116        this.exponentialBackOff = exponentialBackOff;
117    }
118
119    public OptimisticLockRetryPolicyDefinition randomBackOff() {
120        return randomBackOff(true);
121    }
122
123    /**
124     * Enables random backoff
125     */
126    public OptimisticLockRetryPolicyDefinition randomBackOff(boolean randomBackOff) {
127        setRandomBackOff(randomBackOff);
128        return this;
129    }
130
131    public Boolean getRandomBackOff() {
132        return randomBackOff;
133    }
134
135    public void setRandomBackOff(Boolean randomBackOff) {
136        this.randomBackOff = randomBackOff;
137    }
138}