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.processor.aggregate.OptimisticLockRetryPolicy; 025import org.apache.camel.spi.Metadata; 026 027/** 028 * To configure optimistic locking 029 * 030 * @version 031 */ 032@Metadata(label = "configuration") 033@XmlRootElement(name = "optimisticLockRetryPolicy") 034@XmlAccessorType(XmlAccessType.FIELD) 035public class OptimisticLockRetryPolicyDefinition { 036 @XmlAttribute 037 private Integer maximumRetries; 038 @XmlAttribute @Metadata(defaultValue = "50") 039 private Long retryDelay; 040 @XmlAttribute @Metadata(defaultValue = "1000") 041 private Long maximumRetryDelay; 042 @XmlAttribute @Metadata(defaultValue = "true") 043 private Boolean exponentialBackOff; 044 @XmlAttribute 045 private Boolean randomBackOff; 046 047 public OptimisticLockRetryPolicyDefinition() { 048 } 049 050 public OptimisticLockRetryPolicy createOptimisticLockRetryPolicy() { 051 OptimisticLockRetryPolicy policy = new OptimisticLockRetryPolicy(); 052 if (maximumRetries != null) { 053 policy.setMaximumRetries(maximumRetries); 054 } 055 if (retryDelay != null) { 056 policy.setRetryDelay(retryDelay); 057 } 058 if (maximumRetryDelay != null) { 059 policy.setMaximumRetryDelay(maximumRetryDelay); 060 } 061 if (exponentialBackOff != null) { 062 policy.setExponentialBackOff(exponentialBackOff); 063 } 064 if (randomBackOff != null) { 065 policy.setRandomBackOff(randomBackOff); 066 } 067 return policy; 068 } 069 070 /** 071 * Sets the maximum number of retries 072 */ 073 public OptimisticLockRetryPolicyDefinition maximumRetries(int maximumRetries) { 074 setMaximumRetries(maximumRetries); 075 return this; 076 } 077 078 public Integer getMaximumRetries() { 079 return maximumRetries; 080 } 081 082 public void setMaximumRetries(Integer maximumRetries) { 083 this.maximumRetries = maximumRetries; 084 } 085 086 /** 087 * Sets the delay in millis between retries 088 */ 089 public OptimisticLockRetryPolicyDefinition retryDelay(long retryDelay) { 090 setRetryDelay(retryDelay); 091 return this; 092 } 093 094 public Long getRetryDelay() { 095 return retryDelay; 096 } 097 098 public void setRetryDelay(Long retryDelay) { 099 this.retryDelay = retryDelay; 100 } 101 102 /** 103 * Sets the upper value of retry in millis between retries, when using exponential or random backoff 104 */ 105 public OptimisticLockRetryPolicyDefinition maximumRetryDelay(long maximumRetryDelay) { 106 setMaximumRetryDelay(maximumRetryDelay); 107 return this; 108 } 109 110 public Long getMaximumRetryDelay() { 111 return maximumRetryDelay; 112 } 113 114 public void setMaximumRetryDelay(Long 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 setExponentialBackOff(exponentialBackOff); 127 return this; 128 } 129 130 public Boolean getExponentialBackOff() { 131 return exponentialBackOff; 132 } 133 134 public void setExponentialBackOff(Boolean exponentialBackOff) { 135 this.exponentialBackOff = exponentialBackOff; 136 } 137 138 public OptimisticLockRetryPolicyDefinition randomBackOff() { 139 return randomBackOff(true); 140 } 141 142 /** 143 * Enables random backoff 144 */ 145 public OptimisticLockRetryPolicyDefinition randomBackOff(boolean randomBackOff) { 146 setRandomBackOff(randomBackOff); 147 return this; 148 } 149 150 public Boolean getRandomBackOff() { 151 return randomBackOff; 152 } 153 154 public void setRandomBackOff(Boolean randomBackOff) { 155 this.randomBackOff = randomBackOff; 156 } 157}