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.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),
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),
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),
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);
108
109
110
111  // The integer value for this remote assurance level.
112  private final int intValue;
113
114
115
116  /**
117   * Creates a new remote assurance level with the provided integer value.
118   *
119   * @param  intValue  The integer value for this remote assurance level.
120   */
121  AssuredReplicationRemoteLevel(final int intValue)
122  {
123    this.intValue = intValue;
124  }
125
126
127
128  /**
129   * Retrieves integer value for this remote assurance level.
130   *
131   * @return  The integer value for this remote assurance level.
132   */
133  public int intValue()
134  {
135    return intValue;
136  }
137
138
139
140  /**
141   * Retrieves the remote assurance level with the specified integer value.
142   *
143   * @param  intValue  The integer value for the remote assurance level to
144   *                   retrieve.
145   *
146   * @return  The requested remote assurance level, or {@code null} if there is
147   *          no remote assurance level with the specified integer value.
148   */
149  @Nullable()
150  public static AssuredReplicationRemoteLevel valueOf(final int intValue)
151  {
152    for (final AssuredReplicationRemoteLevel l : values())
153    {
154      if (l.intValue == intValue)
155      {
156        return l;
157      }
158    }
159
160    return null;
161  }
162
163
164
165  /**
166   * Retrieves the remote assurance level with the specified name.
167   *
168   * @param  name  The name of the remote assurance level to retrieve.  It must
169   *               not be {@code null}.
170   *
171   * @return  The requested remote assurance level, or {@code null} if no such
172   *          level is defined.
173   */
174  @Nullable()
175  public static AssuredReplicationRemoteLevel forName(
176                     @NotNull final String name)
177  {
178    switch (StaticUtils.toLowerCase(name))
179    {
180      case "none":
181        return NONE;
182      case "receivedanyremotelocation":
183      case "received-any-remote-location":
184      case "received_any_remote_location":
185        return RECEIVED_ANY_REMOTE_LOCATION;
186      case "receivedallremotelocations":
187      case "received-all-remote-locations":
188      case "received_all_remote_locations":
189        return RECEIVED_ALL_REMOTE_LOCATIONS;
190      case "processedallremoteservers":
191      case "processed-all-remote-servers":
192      case "processed_all_remote_servers":
193        return PROCESSED_ALL_REMOTE_SERVERS;
194      default:
195        return null;
196    }
197  }
198
199
200
201  /**
202   * Retrieves the less strict of the two provided assured replication remote
203   * level values.  If the two provided values are the same, then that value
204   * will be returned.
205   *
206   * @param  l1  The first value to compare.
207   * @param  l2  The second value to compare.
208   *
209   * @return  The less strict of the two provided assured replication remote
210   *          level values.
211   */
212  @NotNull()
213  public static AssuredReplicationRemoteLevel getLessStrict(
214                     @NotNull final AssuredReplicationRemoteLevel l1,
215                     @NotNull final AssuredReplicationRemoteLevel l2)
216  {
217    // At present, the integer values can be used to make the comparison.  If
218    // any more enum values are added, this may need to be changed.
219    if (l1.intValue <= l2.intValue)
220    {
221      return l1;
222    }
223    else
224    {
225      return l2;
226    }
227  }
228
229
230
231  /**
232   * Retrieves the more strict of the two provided assured replication remote
233   * level values.  If the two provided values are the same, then that value
234   * will be returned.
235   *
236   * @param  l1  The first value to compare.
237   * @param  l2  The second value to compare.
238   *
239   * @return  The more strict of the two provided assured replication remote
240   *          level values.
241   */
242  @NotNull()
243  public static AssuredReplicationRemoteLevel getMoreStrict(
244                     @NotNull final AssuredReplicationRemoteLevel l1,
245                     @NotNull final AssuredReplicationRemoteLevel l2)
246  {
247    // At present, the integer values can be used to make the comparison.  If
248    // any more enum values are added, this may need to be changed.
249    if (l1.intValue >= l2.intValue)
250    {
251      return l1;
252    }
253    else
254    {
255      return l2;
256    }
257  }
258}