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 type used to refer to a thread operation.
10  *
11  * A thread operation describes high-level action of a thread,
12  * examples include compaction and flush.
13  */
14 public enum OperationType {
15   OP_UNKNOWN((byte)0x0),
16   OP_COMPACTION((byte)0x1),
17   OP_FLUSH((byte)0x2);
18 
19   private final byte value;
20 
OperationType(final byte value)21   OperationType(final byte value) {
22     this.value = value;
23   }
24 
25   /**
26    * Get the internal representation value.
27    *
28    * @return the internal representation value.
29    */
getValue()30   byte getValue() {
31     return value;
32   }
33 
34   /**
35    * Get the Operation type from the internal representation value.
36    *
37    * @param value the internal representation value.
38    *
39    * @return the operation type
40    *
41    * @throws IllegalArgumentException if the value does not match
42    *     an OperationType
43    */
fromValue(final byte value)44   static OperationType fromValue(final byte value)
45       throws IllegalArgumentException {
46     for (final OperationType threadType : OperationType.values()) {
47       if (threadType.value == value) {
48         return threadType;
49       }
50     }
51     throw new IllegalArgumentException(
52         "Unknown value for OperationType: " + value);
53   }
54 }
55