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