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 the
048 * same location as 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 AssuredReplicationLocalLevel
062{
063  /**
064   * Indicates that no local 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 other replication server
073   * in same location.  Note that this level does not require the change to have
074   * already been processed by any other directory server, but merely requires
075   * that it exist in at least one other replication server for the sake of
076   * redundancy.  If the client interacts with another local directory server
077   * immediately after receiving a result with this level of assurance, there is
078   * no guarantee that the associated change will be visible on that server.
079   */
080  RECEIVED_ANY_SERVER(1),
081
082
083
084  /**
085   * Indicates that the operation result should not be returned to the client
086   * until the change has been processed by all available directory servers in
087   * the same location as the original server.
088   */
089  PROCESSED_ALL_SERVERS(2);
090
091
092
093  // The integer value for this local assurance level.
094  private final int intValue;
095
096
097
098  /**
099   * Creates a new local assurance level with the provided integer value.
100   *
101   * @param  intValue  The integer value for this local assurance level.
102   */
103  AssuredReplicationLocalLevel(final int intValue)
104  {
105    this.intValue = intValue;
106  }
107
108
109
110  /**
111   * Retrieves integer value for this local assurance level.
112   *
113   * @return  The integer value for this local assurance level.
114   */
115  public int intValue()
116  {
117    return intValue;
118  }
119
120
121
122  /**
123   * Retrieves the local assurance level with the specified integer value.
124   *
125   * @param  intValue  The integer value for the local assurance level to
126   *                   retrieve.
127   *
128   * @return  The requested local assurance level, or {@code null} if there is
129   *          no local assurance level with the specified integer value.
130   */
131  public static AssuredReplicationLocalLevel valueOf(final int intValue)
132  {
133    for (final AssuredReplicationLocalLevel l : values())
134    {
135      if (l.intValue == intValue)
136      {
137        return l;
138      }
139    }
140
141    return null;
142  }
143
144
145
146  /**
147   * Retrieves the local assurance level with the specified name.
148   *
149   * @param  name  The name of the local assurance level to retrieve.  It must
150   *               not be {@code null}.
151   *
152   * @return  The requested local assurance level, or {@code null} if no such
153   *          level is defined.
154   */
155  public static AssuredReplicationLocalLevel forName(final String name)
156  {
157    switch (StaticUtils.toLowerCase(name))
158    {
159      case "none":
160        return NONE;
161      case "receivedanyserver":
162      case "received-any-server":
163      case "received_any_server":
164        return RECEIVED_ANY_SERVER;
165      case "processedallservers":
166      case "processed-all-servers":
167      case "processed_all_servers":
168        return PROCESSED_ALL_SERVERS;
169      default:
170        return null;
171    }
172  }
173
174
175
176  /**
177   * Retrieves the less strict of the two provided assured replication local
178   * level values.  If the two provided values are the same, then that value
179   * will be returned.
180   *
181   * @param  l1  The first value to compare.
182   * @param  l2  The second value to compare.
183   *
184   * @return  The less strict of the two provided assured replication local
185   *          level values.
186   */
187  public static AssuredReplicationLocalLevel getLessStrict(
188                     final AssuredReplicationLocalLevel l1,
189                     final AssuredReplicationLocalLevel l2)
190  {
191    // At present, the integer values can be used to make the comparison.  If
192    // any more enum values are added, this may need to be changed.
193    if (l1.intValue <= l2.intValue)
194    {
195      return l1;
196    }
197    else
198    {
199      return l2;
200    }
201  }
202
203
204
205  /**
206   * Retrieves the more strict of the two provided assured replication local
207   * level values.  If the two provided values are the same, then that value
208   * will be returned.
209   *
210   * @param  l1  The first value to compare.
211   * @param  l2  The second value to compare.
212   *
213   * @return  The more strict of the two provided assured replication local
214   *          level values.
215   */
216  public static AssuredReplicationLocalLevel getMoreStrict(
217                     final AssuredReplicationLocalLevel l1,
218                     final AssuredReplicationLocalLevel l2)
219  {
220    // At present, the integer values can be used to make the comparison.  If
221    // any more enum values are added, this may need to be changed.
222    if (l1.intValue >= l2.intValue)
223    {
224      return l1;
225    }
226    else
227    {
228      return l2;
229    }
230  }
231}