001/*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License").  You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
010 * or http://forgerock.org/license/CDDLv1.0.html.
011 * See the License for the specific language governing permissions
012 * and limitations under the License.
013 *
014 * When distributing Covered Code, include this CDDL HEADER in each
015 * file and include the License file at legal-notices/CDDLv1_0.txt.
016 * If applicable, add the following below this CDDL HEADER, with the
017 * fields enclosed by brackets "[]" replaced with your own identifying
018 * information:
019 *      Portions Copyright [yyyy] [name of copyright owner]
020 *
021 * CDDL HEADER END
022 *
023 *
024 *      Copyright 2008 Sun Microsystems, Inc.
025 *      Portions Copyright 2015 ForgeRock AS.
026 */
027package org.opends.server.replication.common;
028
029/**
030 * The various status a DS can take.
031 */
032public enum ServerStatus
033{
034
035  /**
036   * Invalid status: special status used in state machine implementation to
037   * return an error (impossible status). See class StatusMachine class for
038   * further details.
039   */
040  INVALID_STATUS((byte) -1),
041  /**
042   * Not connected status: special status used as initial status of the state
043   * machine in the DS context only as already connected while state machine
044   * considered in RS context.
045   */
046  NOT_CONNECTED_STATUS((byte) 0),
047  /**
048   * DS in normal status.
049   * When:
050   * - everything is fine
051   * Properties:
052   * - no referrals
053   * - updates received from RS
054   * - if assured mode, RS asks for ack
055   */
056  NORMAL_STATUS((byte) 1),
057  /**
058   * DS in degraded status.
059   * When:
060   * - DS is too late compared to number of updates RS has to send
061   * Properties:
062   * - referrals returned
063   * - updates received from RS
064   * - if assured mode, RS does not asks for ack
065   */
066  DEGRADED_STATUS((byte) 2),
067  /**
068   * DS in full update (local DS is initialized from another DS).
069   * (if local DS initializes another, it is not in this status)
070   * When:
071   * - A full update is being performed to our local DS
072   * Properties:
073   * - referrals returned
074   * - no updates received from RS
075   * - no ack requested as no updates received
076   */
077  FULL_UPDATE_STATUS((byte) 3),
078  /**
079   * DS in bad generation id status.
080   * When:
081   * - A reset generation id order has been sent to topology
082   * Properties:
083   * - no referrals returned
084   * - no updates received from RS
085   * - no ack requested as no updates received
086   */
087  BAD_GEN_ID_STATUS((byte) 4);
088
089  /** The status value. */
090  private byte value = -1;
091
092  private ServerStatus(byte value)
093  {
094    this.value = value;
095  }
096
097  /**
098   * Returns the ServerStatus matching the passed status numeric representation.
099   * @param value The numeric value for the status to return
100   * @return The matching ServerStatus
101   * @throws java.lang.IllegalArgumentException If provided status value is
102   * wrong
103   */
104  public static ServerStatus valueOf(byte value) throws IllegalArgumentException
105  {
106    switch (value)
107    {
108      case -1:
109        return INVALID_STATUS;
110      case 0:
111        return NOT_CONNECTED_STATUS;
112      case 1:
113        return NORMAL_STATUS;
114      case 2:
115        return DEGRADED_STATUS;
116      case 3:
117        return FULL_UPDATE_STATUS;
118      case 4:
119        return BAD_GEN_ID_STATUS;
120      default:
121        throw new IllegalArgumentException("Wrong status numeric value: " +
122          value);
123    }
124  }
125
126  /**
127   * Get a numeric representation of the status.
128   * @return The numeric representation of the status
129   */
130  public byte getValue()
131  {
132    return value;
133  }
134
135  /**
136   * Get a user readable string representing this status (User friendly string
137   * for monitoring purpose).
138   * @return A user readable string representing this status.
139   */
140  public String toString()
141  {
142    switch (value)
143    {
144      case -1:
145        return "Invalid";
146      case 0:
147        return "Not connected";
148      case 1:
149        return "Normal";
150      case 2:
151        return "Degraded";
152      case 3:
153        return "Full update";
154      case 4:
155        return "Bad generation id";
156      default:
157        throw new IllegalArgumentException("Wrong status numeric value: " +
158          value);
159    }
160  }
161}