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