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