mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Fabio Pistolesi
11.16.2016 7160f59040db3b159e1d73d9ba58055e8806163d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
 * The contents of this file are subject to the terms of the Common Development and
 * Distribution License (the License). You may not use this file except in compliance with the
 * License.
 *
 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
 * specific language governing permission and limitations under the License.
 *
 * When distributing Covered Software, include this CDDL Header Notice in each file and include
 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
 * Header, with the fields enclosed by brackets [] replaced by your own identifying
 * information: "Portions Copyright [year] [name of copyright owner]".
 *
 * Copyright 2008 Sun Microsystems, Inc.
 * Portions Copyright 2015 ForgeRock AS.
 */
package org.opends.server.replication.common;
 
/**
 * The possible events for the status state machine of a DS. See StateMachine
 * class for further details.
 */
public enum StatusMachineEvent
{
 
  /**
   * Invalid event: special event used to be returned by some methods to signal
   * an error.
   */
  INVALID_EVENT((byte) -1),
  /**
   * Event used when one wants the DS to enter the NOT_CONNECTED_STATUS.
   */
  TO_NOT_CONNECTED_STATUS_EVENT((byte) 0),
  /**
   * Event used when one wants the DS to enter the NORMAL_STATUS.
   */
  TO_NORMAL_STATUS_EVENT((byte) 1),
  /**
   * Event used when one wants the DS to enter the DEGRADED_STATUS.
   */
  TO_DEGRADED_STATUS_EVENT((byte) 2),
  /**
   * Event used when one wants the DS to enter the FULL_UPDATE_STATUS.
   */
  TO_FULL_UPDATE_STATUS_EVENT((byte) 3),
  /**
   * Event used when one wants the DS to enter the BAD_GEN_ID_STATUS.
   */
  TO_BAD_GEN_ID_STATUS_EVENT((byte) 4);
  /** The status value. */
  private byte value = -1;
 
  private StatusMachineEvent(byte value)
  {
    this.value = value;
  }
 
  /**
   * Returns the StatusMachineEvent matching the passed event numeric
   * representation.
   * @param value The numeric value for the event to return
   * @return The matching StatusMachineEvent
   * @throws java.lang.IllegalArgumentException If provided event value is
   * wrong
   */
  public static StatusMachineEvent valueOf(byte value)
    throws IllegalArgumentException
  {
    switch (value)
    {
      case 0:
        return TO_NOT_CONNECTED_STATUS_EVENT;
      case 1:
        return TO_NORMAL_STATUS_EVENT;
      case 2:
        return TO_DEGRADED_STATUS_EVENT;
      case 3:
        return TO_FULL_UPDATE_STATUS_EVENT;
      case 4:
        return TO_BAD_GEN_ID_STATUS_EVENT;
      default:
        throw new IllegalArgumentException("Wrong event numeric value: "
          + value);
    }
  }
 
  /**
   * Returns the event matching the passed requested status.
   * When an entity receives a request to enter a particular status, this
   * order is translated into a state machine event according to what is
   * requested. Then, according to the current status and the computed event,
   * the state machine retruns the matching new status
   * (StateMachine.computeNewStatus).
   * @param reqStatus The status to translate to an event.
   * @return The matching event.
   */
  public static StatusMachineEvent statusToEvent(ServerStatus reqStatus)
  {
   switch (reqStatus)
    {
      case NOT_CONNECTED_STATUS:
        return TO_NOT_CONNECTED_STATUS_EVENT;
      case NORMAL_STATUS:
        return TO_NORMAL_STATUS_EVENT;
      case DEGRADED_STATUS:
        return TO_DEGRADED_STATUS_EVENT;
      case FULL_UPDATE_STATUS:
        return TO_FULL_UPDATE_STATUS_EVENT;
      case BAD_GEN_ID_STATUS:
        return TO_BAD_GEN_ID_STATUS_EVENT;
      default:
        return INVALID_EVENT;
    }
  }
 
  /**
   * Get a numeric representation of the event.
   * @return The numeric representation of the event
   */
  public byte getValue()
  {
    return value;
  }
}