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    @Metadata(javaType = "java.lang.Integer")
035    private String maximumRetries;
036    @XmlAttribute
037    @Metadata(javaType = "java.time.Duration", defaultValue = "50ms")
038    private String retryDelay;
039    @XmlAttribute
040    @Metadata(javaType = "java.time.Duration", defaultValue = "1s")
041    private String maximumRetryDelay;
042    @XmlAttribute
043    @Metadata(javaType = "java.lang.Boolean", defaultValue = "true")
044    private String exponentialBackOff;
045    @XmlAttribute
046    @Metadata(javaType = "java.lang.Boolean")
047    private String randomBackOff;
048
049    public OptimisticLockRetryPolicyDefinition() {
050    }
051
052    /**
053     * Sets the maximum number of retries
054     */
055    public OptimisticLockRetryPolicyDefinition maximumRetries(int maximumRetries) {
056        return maximumRetries(String.valueOf(maximumRetries));
057    }
058
059    public OptimisticLockRetryPolicyDefinition maximumRetries(String maximumRetries) {
060        setMaximumRetries(maximumRetries);
061        return this;
062    }
063
064    public String getMaximumRetries() {
065        return maximumRetries;
066    }
067
068    public void setMaximumRetries(String maximumRetries) {
069        this.maximumRetries = maximumRetries;
070    }
071
072    /**
073     * Sets the delay in millis between retries
074     */
075    public OptimisticLockRetryPolicyDefinition retryDelay(long retryDelay) {
076        return retryDelay(Long.toString(retryDelay));
077    }
078
079    /**
080     * Sets the delay in millis between retries
081     */
082    public OptimisticLockRetryPolicyDefinition retryDelay(String retryDelay) {
083        setRetryDelay(retryDelay);
084        return this;
085    }
086
087    public String getRetryDelay() {
088        return retryDelay;
089    }
090
091    public void setRetryDelay(String retryDelay) {
092        this.retryDelay = retryDelay;
093    }
094
095    /**
096     * Sets the upper value of retry in millis between retries, when using
097     * exponential or random backoff
098     */
099    public OptimisticLockRetryPolicyDefinition maximumRetryDelay(long maximumRetryDelay) {
100        return maximumRetryDelay(Long.toString(maximumRetryDelay));
101    }
102
103    /**
104     * Sets the upper value of retry in millis between retries, when using
105     * exponential or random backoff
106     */
107    public OptimisticLockRetryPolicyDefinition maximumRetryDelay(String maximumRetryDelay) {
108        setMaximumRetryDelay(maximumRetryDelay);
109        return this;
110    }
111
112    public String getMaximumRetryDelay() {
113        return maximumRetryDelay;
114    }
115
116    public void setMaximumRetryDelay(String maximumRetryDelay) {
117        this.maximumRetryDelay = maximumRetryDelay;
118    }
119
120    /**
121     * Enable exponential backoff
122     */
123    public OptimisticLockRetryPolicyDefinition exponentialBackOff() {
124        return exponentialBackOff(true);
125    }
126
127    public OptimisticLockRetryPolicyDefinition exponentialBackOff(boolean exponentialBackOff) {
128        return exponentialBackOff(Boolean.toString(exponentialBackOff));
129    }
130
131    public OptimisticLockRetryPolicyDefinition exponentialBackOff(String exponentialBackOff) {
132        setExponentialBackOff(exponentialBackOff);
133        return this;
134    }
135
136    public String getExponentialBackOff() {
137        return exponentialBackOff;
138    }
139
140    public void setExponentialBackOff(String exponentialBackOff) {
141        this.exponentialBackOff = exponentialBackOff;
142    }
143
144    public OptimisticLockRetryPolicyDefinition randomBackOff() {
145        return randomBackOff(true);
146    }
147
148    /**
149     * Enables random backoff
150     */
151    public OptimisticLockRetryPolicyDefinition randomBackOff(boolean randomBackOff) {
152        return randomBackOff(String.valueOf(randomBackOff));
153    }
154
155    public OptimisticLockRetryPolicyDefinition randomBackOff(String randomBackOff) {
156        setRandomBackOff(randomBackOff);
157        return this;
158    }
159
160    public String getRandomBackOff() {
161        return randomBackOff;
162    }
163
164    public void setRandomBackOff(String randomBackOff) {
165        this.randomBackOff = randomBackOff;
166    }
167}