001/*
002 * Copyright 2013-2018 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright (C) 2015-2018 Ping Identity Corporation
007 *
008 * This program is free software; you can redistribute it and/or modify
009 * it under the terms of the GNU General Public License (GPLv2 only)
010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
011 * as published by the Free Software Foundation.
012 *
013 * This program is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016 * GNU General Public License for more details.
017 *
018 * You should have received a copy of the GNU General Public License
019 * along with this program; if not, see <http://www.gnu.org/licenses>.
020 */
021package com.unboundid.ldap.sdk.unboundidds.controls;
022
023
024
025import com.unboundid.util.StaticUtils;
026import com.unboundid.util.ThreadSafety;
027import com.unboundid.util.ThreadSafetyLevel;
028
029
030
031/**
032 * This enum defines the set of result code values that may be included in a
033 * an assured replication server result.
034 * <BR>
035 * <BLOCKQUOTE>
036 *   <B>NOTE:</B>  This class, and other classes within the
037 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
038 *   supported for use against Ping Identity, UnboundID, and
039 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
040 *   for proprietary functionality or for external specifications that are not
041 *   considered stable or mature enough to be guaranteed to work in an
042 *   interoperable way with other types of LDAP servers.
043 * </BLOCKQUOTE>
044 */
045@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
046public enum AssuredReplicationServerResultCode
047{
048  /**
049   * Indicates that the requested level of assurance was successfully attained.
050   */
051  COMPLETE(0),
052
053
054
055  /**
056   * Indicates that the requested level of assurance could not be attained
057   * before the timeout elapsed.
058   */
059  TIMEOUT(1),
060
061
062
063  /**
064   * Indicates that a replication conflict was encountered that will prevent
065   * the associated operation from being applied to the target server.
066   */
067  CONFLICT(2),
068
069
070
071  /**
072   * Indicates that the target server was shut down while waiting for an
073   * assurance result.
074   */
075  SERVER_SHUTDOWN(3),
076
077
078
079  /**
080   * Indicates that the target server became unavailable while waiting for an
081   * assurance result.
082   */
083  UNAVAILABLE(4),
084
085
086
087  /**
088   * Indicates that the replication assurance engine detected a duplicate
089   * request for the same operation.
090   */
091  DUPLICATE(5);
092
093
094
095  // The integer value for this server result code.
096  private final int intValue;
097
098
099
100  /**
101   * Creates a new assured replication server result code with the specified
102   * integer value.
103   *
104   * @param  intValue  The integer value for this assured replication server
105   *                   result code.
106   */
107  AssuredReplicationServerResultCode(final int intValue)
108  {
109    this.intValue = intValue;
110  }
111
112
113
114  /**
115   * Retrieves the integer value for this assured replication server result
116   * code.
117   *
118   * @return  The integer value for this assured replication server result code.
119   */
120  public int intValue()
121  {
122    return intValue;
123  }
124
125
126
127  /**
128   * Retrieves the assured replication server result code with the specified
129   * integer value.
130   *
131   * @param  intValue  The integer value for the server result code to
132   *                   retrieve.
133   *
134   * @return  The requested assured replication server result code, or
135   *          {@code null} if there is no server result code with the specified
136   *          integer value.
137   */
138  public static AssuredReplicationServerResultCode valueOf(final int intValue)
139  {
140    for (final AssuredReplicationServerResultCode rc : values())
141    {
142      if (rc.intValue == intValue)
143      {
144        return rc;
145      }
146    }
147
148    return null;
149  }
150
151
152
153  /**
154   * Retrieves the assured replication server result code with the specified
155   * name.
156   *
157   * @param  name  The name of the assured replication server result code to
158   *               retrieve.  It must not be {@code null}.
159   *
160   * @return  The requested assured replication server result code, or
161   *          {@code null} if no such result code is defined.
162   */
163  public static AssuredReplicationServerResultCode forName(final String name)
164  {
165    switch (StaticUtils.toLowerCase(name))
166    {
167      case "complete":
168        return COMPLETE;
169      case "timeout":
170        return TIMEOUT;
171      case "conflict":
172        return CONFLICT;
173      case "servershutdown":
174      case "server-shutdown":
175      case "server_shutdown":
176        return SERVER_SHUTDOWN;
177      case "unavailable":
178        return UNAVAILABLE;
179      case "duplicate":
180        return DUPLICATE;
181      default:
182        return null;
183    }
184  }
185}