001/*
002 * Copyright 2013-2017 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright (C) 2015-2017 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.ThreadSafety;
026import com.unboundid.util.ThreadSafetyLevel;
027
028
029
030/**
031 * This enum defines an assurance level that may be used for servers in the
032 * same location as the server receiving the change.
033 * <BR>
034 * <BLOCKQUOTE>
035 *   <B>NOTE:</B>  This class, and other classes within the
036 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
037 *   supported for use against Ping Identity, UnboundID, and Alcatel-Lucent 8661
038 *   server products.  These classes provide support for proprietary
039 *   functionality or for external specifications that are not considered stable
040 *   or mature enough to be guaranteed to work in an interoperable way with
041 *   other types of LDAP servers.
042 * </BLOCKQUOTE>
043 */
044@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
045public enum AssuredReplicationLocalLevel
046{
047  /**
048   * Indicates that no local assurance is desired for the associated operation.
049   */
050  NONE(0),
051
052
053
054  /**
055   * Indicates that the operation result should not be returned to the client
056   * until the change has been received by at least one other replication server
057   * in same location.  Note that this level does not require the change to have
058   * already been processed by any other directory server, but merely requires
059   * that it exist in at least one other replication server for the sake of
060   * redundancy.  If the client interacts with another local directory server
061   * immediately after receiving a result with this level of assurance, there is
062   * no guarantee that the associated change will be visible on that server.
063   */
064  RECEIVED_ANY_SERVER(1),
065
066
067
068  /**
069   * Indicates that the operation result should not be returned to the client
070   * until the change has been processed by all available directory servers in
071   * the same location as the original server.
072   */
073  PROCESSED_ALL_SERVERS(2);
074
075
076
077  // The integer value for this local assurance level.
078  private final int intValue;
079
080
081
082  /**
083   * Creates a new local assurance level with the provided integer value.
084   *
085   * @param  intValue  The integer value for this local assurance level.
086   */
087  AssuredReplicationLocalLevel(final int intValue)
088  {
089    this.intValue = intValue;
090  }
091
092
093
094  /**
095   * Retrieves integer value for this local assurance level.
096   *
097   * @return  The integer value for this local assurance level.
098   */
099  public int intValue()
100  {
101    return intValue;
102  }
103
104
105
106  /**
107   * Retrieves the local assurance level with the specified integer value.
108   *
109   * @param  intValue  The integer value for the local assurance level to
110   *                   retrieve.
111   *
112   * @return  The requested local assurance level, or {@code null} if there is
113   *          no local assurance level with the specified integer value.
114   */
115  public static AssuredReplicationLocalLevel valueOf(final int intValue)
116  {
117    for (final AssuredReplicationLocalLevel l : values())
118    {
119      if (l.intValue == intValue)
120      {
121        return l;
122      }
123    }
124
125    return null;
126  }
127
128
129
130  /**
131   * Retrieves the less strict of the two provided assured replication local
132   * level values.  If the two provided values are the same, then that value
133   * will be returned.
134   *
135   * @param  l1  The first value to compare.
136   * @param  l2  The second value to compare.
137   *
138   * @return  The less strict of the two provided assured replication local
139   *          level values.
140   */
141  public static AssuredReplicationLocalLevel getLessStrict(
142                     final AssuredReplicationLocalLevel l1,
143                     final AssuredReplicationLocalLevel l2)
144  {
145    // At present, the integer values can be used to make the comparison.  If
146    // any more enum values are added, this may need to be changed.
147    if (l1.intValue <= l2.intValue)
148    {
149      return l1;
150    }
151    else
152    {
153      return l2;
154    }
155  }
156
157
158
159  /**
160   * Retrieves the more strict of the two provided assured replication local
161   * level values.  If the two provided values are the same, then that value
162   * will be returned.
163   *
164   * @param  l1  The first value to compare.
165   * @param  l2  The second value to compare.
166   *
167   * @return  The more strict of the two provided assured replication local
168   *          level values.
169   */
170  public static AssuredReplicationLocalLevel getMoreStrict(
171                     final AssuredReplicationLocalLevel l1,
172                     final AssuredReplicationLocalLevel l2)
173  {
174    // At present, the integer values can be used to make the comparison.  If
175    // any more enum values are added, this may need to be changed.
176    if (l1.intValue >= l2.intValue)
177    {
178      return l1;
179    }
180    else
181    {
182      return l2;
183    }
184  }
185}