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