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