1 // Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
2 //  This source code is licensed under both the GPLv2 (found in the
3 //  COPYING file in the root directory) and Apache 2.0 License
4 //  (found in the LICENSE.Apache file in the root directory).
5 
6 package org.rocksdb;
7 
8 /**
9  * The operation stage.
10  */
11 public enum OperationStage {
12   STAGE_UNKNOWN((byte)0x0),
13   STAGE_FLUSH_RUN((byte)0x1),
14   STAGE_FLUSH_WRITE_L0((byte)0x2),
15   STAGE_COMPACTION_PREPARE((byte)0x3),
16   STAGE_COMPACTION_RUN((byte)0x4),
17   STAGE_COMPACTION_PROCESS_KV((byte)0x5),
18   STAGE_COMPACTION_INSTALL((byte)0x6),
19   STAGE_COMPACTION_SYNC_FILE((byte)0x7),
20   STAGE_PICK_MEMTABLES_TO_FLUSH((byte)0x8),
21   STAGE_MEMTABLE_ROLLBACK((byte)0x9),
22   STAGE_MEMTABLE_INSTALL_FLUSH_RESULTS((byte)0xA);
23 
24   private final byte value;
25 
OperationStage(final byte value)26   OperationStage(final byte value) {
27     this.value = value;
28   }
29 
30   /**
31    * Get the internal representation value.
32    *
33    * @return the internal representation value.
34    */
getValue()35   byte getValue() {
36     return value;
37   }
38 
39   /**
40    * Get the Operation stage from the internal representation value.
41    *
42    * @param value the internal representation value.
43    *
44    * @return the operation stage
45    *
46    * @throws IllegalArgumentException if the value does not match
47    *     an OperationStage
48    */
fromValue(final byte value)49   static OperationStage fromValue(final byte value)
50       throws IllegalArgumentException {
51     for (final OperationStage threadType : OperationStage.values()) {
52       if (threadType.value == value) {
53         return threadType;
54       }
55     }
56     throw new IllegalArgumentException(
57         "Unknown value for OperationStage: " + value);
58   }
59 }
60