001/*
002 * Copyright 2013-2024 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2013-2024 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-2024 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.NotNull;
041import com.unboundid.util.Nullable;
042import com.unboundid.util.StaticUtils;
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
050 * different locations from 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 AssuredReplicationRemoteLevel
064{
065  /**
066   * Indicates that no remote 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 replication server in a
075   * different location.  Note that this level does not require the change to
076   * have already been processed by any other directory server, but merely
077   * requires that it exist in at least one remote replication server for the
078   * sake of redundancy.  If the client interacts with another remote directory
079   * server immediately after receiving a result with this level of assurance,
080   * there is no guarantee that the associated change will be visible on that
081   * server.
082   */
083  RECEIVED_ANY_REMOTE_LOCATION(1, "received-any-remote-location"),
084
085
086
087  /**
088   * Indicates that the operation result should not be returned to the client
089   * until the change has been received by at least one replication server in
090   * each of the remote locations.  Note that this level does not require the
091   * change to have already been processed by any other directory server, but
092   * merely requires that it exist in at least one remote replication server in
093   * each remote location for the sake of redundancy.  If the client interacts
094   * with another remote directory server immediately after receiving a result
095   * with this level of assurance, there is no guarantee that the associated
096   * change will be visible on that server.
097   */
098  RECEIVED_ALL_REMOTE_LOCATIONS(2, "received-all-remote-locations"),
099
100
101
102  /**
103   * Indicates that the operation result should not be returned to the client
104   * until the change has been processed by all available servers in all remote
105   * locations.
106   */
107  PROCESSED_ALL_REMOTE_SERVERS(3, "processed-all-remote-servers");
108
109
110
111  // The integer value for this remote assurance level.
112  private final int intValue;
113
114  // The name for this local assurance level.
115  @NotNull private final String name;
116
117
118
119  /**
120   * Creates a new remote assurance level with the provided integer value.
121   *
122   * @param  intValue  The integer value for this remote assurance level.
123   * @param  name      The name for this remote assurance level.
124   */
125  AssuredReplicationRemoteLevel(final int intValue,
126                                @NotNull final String name)
127  {
128    this.intValue = intValue;
129    this.name = name;
130  }
131
132
133
134  /**
135   * Retrieves integer value for this remote assurance level.
136   *
137   * @return  The integer value for this remote assurance level.
138   */
139  public int intValue()
140  {
141    return intValue;
142  }
143
144
145
146  /**
147   * Retrieves the name for this remote assurance level.
148   *
149   * @return  The name for this remote assurance level.
150   */
151  @NotNull()
152  public String getName()
153  {
154    return name;
155  }
156
157
158
159  /**
160   * Retrieves the remote assurance level with the specified integer value.
161   *
162   * @param  intValue  The integer value for the remote assurance level to
163   *                   retrieve.
164   *
165   * @return  The requested remote assurance level, or {@code null} if there is
166   *          no remote assurance level with the specified integer value.
167   */
168  @Nullable()
169  public static AssuredReplicationRemoteLevel valueOf(final int intValue)
170  {
171    for (final AssuredReplicationRemoteLevel l : values())
172    {
173      if (l.intValue == intValue)
174      {
175        return l;
176      }
177    }
178
179    return null;
180  }
181
182
183
184  /**
185   * Retrieves the remote assurance level with the specified name.
186   *
187   * @param  name  The name of the remote assurance level to retrieve.  It must
188   *               not be {@code null}.
189   *
190   * @return  The requested remote assurance level, or {@code null} if no such
191   *          level is defined.
192   */
193  @Nullable()
194  public static AssuredReplicationRemoteLevel forName(
195                     @NotNull final String name)
196  {
197    switch (StaticUtils.toLowerCase(name))
198    {
199      case "none":
200        return NONE;
201      case "receivedanyremotelocation":
202      case "received-any-remote-location":
203      case "received_any_remote_location":
204        return RECEIVED_ANY_REMOTE_LOCATION;
205      case "receivedallremotelocations":
206      case "received-all-remote-locations":
207      case "received_all_remote_locations":
208        return RECEIVED_ALL_REMOTE_LOCATIONS;
209      case "processedallremoteservers":
210      case "processed-all-remote-servers":
211      case "processed_all_remote_servers":
212        return PROCESSED_ALL_REMOTE_SERVERS;
213      default:
214        return null;
215    }
216  }
217
218
219
220  /**
221   * Retrieves the less strict of the two provided assured replication remote
222   * level values.  If the two provided values are the same, then that value
223   * will be returned.
224   *
225   * @param  l1  The first value to compare.
226   * @param  l2  The second value to compare.
227   *
228   * @return  The less strict of the two provided assured replication remote
229   *          level values.
230   */
231  @NotNull()
232  public static AssuredReplicationRemoteLevel getLessStrict(
233                     @NotNull final AssuredReplicationRemoteLevel l1,
234                     @NotNull final AssuredReplicationRemoteLevel l2)
235  {
236    // At present, the integer values can be used to make the comparison.  If
237    // any more enum values are added, this may need to be changed.
238    if (l1.intValue <= l2.intValue)
239    {
240      return l1;
241    }
242    else
243    {
244      return l2;
245    }
246  }
247
248
249
250  /**
251   * Retrieves the more strict of the two provided assured replication remote
252   * level values.  If the two provided values are the same, then that value
253   * will be returned.
254   *
255   * @param  l1  The first value to compare.
256   * @param  l2  The second value to compare.
257   *
258   * @return  The more strict of the two provided assured replication remote
259   *          level values.
260   */
261  @NotNull()
262  public static AssuredReplicationRemoteLevel getMoreStrict(
263                     @NotNull final AssuredReplicationRemoteLevel l1,
264                     @NotNull final AssuredReplicationRemoteLevel l2)
265  {
266    // At present, the integer values can be used to make the comparison.  If
267    // any more enum values are added, this may need to be changed.
268    if (l1.intValue >= l2.intValue)
269    {
270      return l1;
271    }
272    else
273    {
274      return l2;
275    }
276  }
277}