001/* 002 * Copyright 2014-2024 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2014-2024 Ping Identity Corporation 007 * 008 * Licensed under the Apache License, Version 2.0 (the "License"); 009 * you may not use this file except in compliance with the License. 010 * You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, software 015 * distributed under the License is distributed on an "AS IS" BASIS, 016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 017 * See the License for the specific language governing permissions and 018 * limitations under the License. 019 */ 020/* 021 * Copyright (C) 2014-2024 Ping Identity Corporation 022 * 023 * This program is free software; you can redistribute it and/or modify 024 * it under the terms of the GNU General Public License (GPLv2 only) 025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 026 * as published by the Free Software Foundation. 027 * 028 * This program is distributed in the hope that it will be useful, 029 * but WITHOUT ANY WARRANTY; without even the implied warranty of 030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 031 * GNU General Public License for more details. 032 * 033 * You should have received a copy of the GNU General Public License 034 * along with this program; if not, see <http://www.gnu.org/licenses>. 035 */ 036package com.unboundid.ldap.sdk.unboundidds.controls; 037 038 039 040import com.unboundid.util.NotNull; 041import com.unboundid.util.Nullable; 042import com.unboundid.util.StaticUtils; 043import com.unboundid.util.ThreadSafety; 044import com.unboundid.util.ThreadSafetyLevel; 045 046 047 048/** 049 * This enum defines the options that may be specified to indicate whether and 050 * when to acquire an exclusive lock in the target backend when processing a 051 * transaction. 052 * <BR> 053 * <BLOCKQUOTE> 054 * <B>NOTE:</B> This class, and other classes within the 055 * {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only 056 * supported for use against Ping Identity, UnboundID, and 057 * Nokia/Alcatel-Lucent 8661 server products. These classes provide support 058 * for proprietary functionality or for external specifications that are not 059 * considered stable or mature enough to be guaranteed to work in an 060 * interoperable way with other types of LDAP servers. 061 * </BLOCKQUOTE> 062 * 063 * @see TransactionSettingsRequestControl 064 */ 065@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 066public enum TransactionSettingsBackendLockBehavior 067{ 068 /** 069 * Indicates that the server should not make any attempt to acquire an 070 * exclusive lock in the target backend, whether during the initial attempt or 071 * a subsequent retry. This will allow the highest level of concurrency for 072 * operations within the backend, but may increase the risk of lock conflicts 073 * between transactions in a server processing many operations concurrently. 074 * This risk may be mitigated by indicating that the transaction should be 075 * retried one or more times. 076 */ 077 DO_NOT_ACQUIRE(0), 078 079 080 081 /** 082 * Indicates that if the server is unable to successfully commit the 083 * associated transaction after one or more attempts without holding an 084 * exclusive lock in the target backend, then it should make one more attempt 085 * after acquiring the lock. This will avoid the need to acquire the lock 086 * unless the maximum number of attempts have been unsuccessful without it. 087 */ 088 ACQUIRE_AFTER_RETRIES(1), 089 090 091 092 /** 093 * Indicates that if the server is unable to successfully commit the 094 * associated transaction after the first attempt without holding an exclusive 095 * lock in the target backend, then it should make one or more 096 * additional attempts (as specified by the requested number of retries) after 097 * acquiring the lock. This will avoid the need to acquire the lock for 098 * operations that can be completed on the first attempt without it. 099 */ 100 ACQUIRE_BEFORE_RETRIES(2), 101 102 103 104 /** 105 * Indicates that the server should acquire an exclusive lock in the target 106 * backend before performing any backend processing for the operation. This 107 * will limit concurrency, as the backend will not be able to process any 108 * other operation while the associated operation is in progress, but this 109 * will also minimize the chance of a thread deadlock or lock timeout as a 110 * result of a conflict between database interactions from multiple 111 * simultaneous operations. 112 */ 113 ACQUIRE_BEFORE_INITIAL_ATTEMPT(3); 114 115 116 117 // The integer value for this backend lock behavior. 118 private final int intValue; 119 120 121 122 /** 123 * Creates a new transaction settings backend lock behavior with the provided 124 * integer value. 125 * 126 * @param intValue The integer value for this backend lock behavior. 127 */ 128 TransactionSettingsBackendLockBehavior(final int intValue) 129 { 130 this.intValue = intValue; 131 } 132 133 134 135 /** 136 * Retrieves the integer value for this transaction settings backend lock 137 * behavior value. 138 * 139 * @return The integer value for this transaction settings backend lock 140 * behavior value. 141 */ 142 public int intValue() 143 { 144 return intValue; 145 } 146 147 148 149 /** 150 * Retrieves the backend lock behavior value with the specified integer value. 151 * 152 * @param intValue The integer value for the backend lock behavior to 153 * retrieve. 154 * 155 * @return The backend lock behavior value with the specified integer value, 156 * or {@code null} if there is no such backend lock behavior value. 157 */ 158 @Nullable() 159 public static TransactionSettingsBackendLockBehavior 160 valueOf(final int intValue) 161 { 162 for (final TransactionSettingsBackendLockBehavior v : values()) 163 { 164 if (v.intValue == intValue) 165 { 166 return v; 167 } 168 } 169 170 return null; 171 } 172 173 174 175 /** 176 * Retrieves the transaction settings backend lock behavior with the specified 177 * name. 178 * 179 * @param name The name of the transaction settings backend lock behavior to 180 * retrieve. It must not be {@code null}. 181 * 182 * @return The requested transaction settings backend lock behavior, or 183 * {@code null} if no such behavior is defined. 184 */ 185 @Nullable() 186 public static TransactionSettingsBackendLockBehavior forName( 187 @NotNull final String name) 188 { 189 switch (StaticUtils.toLowerCase(name)) 190 { 191 case "donotacquire": 192 case "do-not-acquire": 193 case "do_not_acquire": 194 return DO_NOT_ACQUIRE; 195 case "acquireafterretries": 196 case "acquire-after-retries": 197 case "acquire_after_retries": 198 return ACQUIRE_AFTER_RETRIES; 199 case "acquirebeforeretries": 200 case "acquire-before-retries": 201 case "acquire_before_retries": 202 return ACQUIRE_BEFORE_RETRIES; 203 case "acquirebeforeinitialattempt": 204 case "acquire-before-initial-attempt": 205 case "acquire_before_initial_attempt": 206 return ACQUIRE_BEFORE_INITIAL_ATTEMPT; 207 default: 208 return null; 209 } 210 } 211}