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