001    /*
002     * Copyright 2014-2015 UnboundID Corp.
003     * All Rights Reserved.
004     */
005    /*
006     * Copyright (C) 2015 UnboundID Corp.
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     */
021    package com.unboundid.ldap.sdk.unboundidds.controls;
022    
023    
024    
025    import com.unboundid.util.ThreadSafety;
026    import com.unboundid.util.ThreadSafetyLevel;
027    
028    
029    
030    /**
031     * <BLOCKQUOTE>
032     *   <B>NOTE:</B>  This class is part of the Commercial Edition of the UnboundID
033     *   LDAP SDK for Java.  It is not available for use in applications that
034     *   include only the Standard Edition of the LDAP SDK, and is not supported for
035     *   use in conjunction with non-UnboundID products.
036     * </BLOCKQUOTE>
037     * This enum defines the options that may be specified to indicate whether and
038     * when to acquire an exclusive lock in the target backend when processing a
039     * transaction.
040     *
041     * @see TransactionSettingsRequestControl
042     */
043    @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
044    public enum TransactionSettingsBackendLockBehavior
045    {
046      /**
047       * Indicates that the server should not make any attempt to acquire an
048       * exclusive lock in the target backend, whether during the initial attempt or
049       * a subsequent retry.  This will allow the highest level of concurrency for
050       * operations within the backend, but may increase the risk of lock conflicts
051       * between transactions in a server processing many operations concurrently.
052       * This risk may be mitigated by indicating that the transaction should be
053       * retried one or more times.
054       */
055      DO_NOT_ACQUIRE(0),
056    
057    
058    
059      /**
060       * Indicates that if the server is unable to successfully commit the
061       * associated transaction after one or more attempts without holding an
062       * exclusive lock in the target backend, then it should make one more attempt
063       * after acquiring the lock.  This will avoid the need to acquire the lock
064       * unless the maximum number of attempts have been unsuccessful without it.
065       */
066      ACQUIRE_AFTER_RETRIES(1),
067    
068    
069    
070      /**
071       * Indicates that if the server is unable to successfully commit the
072       * associated transaction after the first attempt without holding an exclusive
073       * lock in the target backend, then it should make one or more
074       * additional attempts (as specified by the requested number of retries) after
075       * acquiring the lock.  This will avoid the need to acquire the lock for
076       * operations that can be completed on the first attempt without it.
077       */
078      ACQUIRE_BEFORE_RETRIES(2),
079    
080    
081    
082      /**
083       * Indicates that the server should acquire an exclusive lock in the target
084       * backend before performing any backend processing for the operation.  This
085       * will limit concurrency, as the backend will not be able to process any
086       * other operation while the associated operation is in progress, but this
087       * will also minimize the chance of a thread deadlock or lock timeout as a
088       * result of a conflict between database interactions from multiple
089       * simultaneous operations.
090       */
091      ACQUIRE_BEFORE_INITIAL_ATTEMPT(3);
092    
093    
094    
095      // The integer value for this backend lock behavior.
096      private final int intValue;
097    
098    
099    
100      /**
101       * Creates a new transaction settings backend lock behavior with the provided
102       * integer value.
103       *
104       * @param  intValue  The integer value for this backend lock behavior.
105       */
106      private TransactionSettingsBackendLockBehavior(final int intValue)
107      {
108        this.intValue = intValue;
109      }
110    
111    
112    
113      /**
114       * Retrieves the integer value for this transaction settings backend lock
115       * behavior value.
116       *
117       * @return  The integer value for this transaction settings backend lock
118       *          behavior value.
119       */
120      public int intValue()
121      {
122        return intValue;
123      }
124    
125    
126    
127      /**
128       * Retrieves the backend lock behavior value with the specified integer value.
129       *
130       * @param  intValue  The integer value for the backend lock behavior to
131       *                   retrieve.
132       *
133       * @return  The backend lock behavior value with the specified integer value,
134       *          or {@code null} if there is no such backend lock behavior value.
135       */
136      public static TransactionSettingsBackendLockBehavior
137                         valueOf(final int intValue)
138      {
139        for (final TransactionSettingsBackendLockBehavior v : values())
140        {
141          if (v.intValue == intValue)
142          {
143            return v;
144          }
145        }
146    
147        return null;
148      }
149    }