]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/java/src/main/java/org/rocksdb/Status.java
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / rocksdb / java / src / main / java / org / rocksdb / Status.java
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under the BSD-style license found in the
3 // LICENSE file in the root directory of this source tree. An additional grant
4 // of patent rights can be found in the PATENTS file in the same directory.
5
6 package org.rocksdb;
7
8 /**
9 * Represents the status returned by a function call in RocksDB.
10 *
11 * Currently only used with {@link RocksDBException} when the
12 * status is not {@link Code#Ok}
13 */
14 public class Status {
15 private final Code code;
16 /* @Nullable */ private final SubCode subCode;
17 /* @Nullable */ private final String state;
18
19 public Status(final Code code, final SubCode subCode, final String state) {
20 this.code = code;
21 this.subCode = subCode;
22 this.state = state;
23 }
24
25 /**
26 * Intentionally private as this will be called from JNI
27 */
28 private Status(final byte code, final byte subCode, final String state) {
29 this.code = Code.getCode(code);
30 this.subCode = SubCode.getSubCode(subCode);
31 this.state = state;
32 }
33
34 public Code getCode() {
35 return code;
36 }
37
38 public SubCode getSubCode() {
39 return subCode;
40 }
41
42 public String getState() {
43 return state;
44 }
45
46 public String getCodeString() {
47 final StringBuilder builder = new StringBuilder()
48 .append(code.name());
49 if(subCode != null && subCode != SubCode.None) {
50 builder.append("(")
51 .append(subCode.name())
52 .append(")");
53 }
54 return builder.toString();
55 }
56
57 public enum Code {
58 Ok( (byte)0x0),
59 NotFound( (byte)0x1),
60 Corruption( (byte)0x2),
61 NotSupported( (byte)0x3),
62 InvalidArgument( (byte)0x4),
63 IOError( (byte)0x5),
64 MergeInProgress( (byte)0x6),
65 Incomplete( (byte)0x7),
66 ShutdownInProgress( (byte)0x8),
67 TimedOut( (byte)0x9),
68 Aborted( (byte)0xA),
69 Busy( (byte)0xB),
70 Expired( (byte)0xC),
71 TryAgain( (byte)0xD);
72
73 private final byte value;
74
75 Code(final byte value) {
76 this.value = value;
77 }
78
79 public static Code getCode(final byte value) {
80 for (final Code code : Code.values()) {
81 if (code.value == value){
82 return code;
83 }
84 }
85 throw new IllegalArgumentException(
86 "Illegal value provided for Code.");
87 }
88 }
89
90 public enum SubCode {
91 None( (byte)0x0),
92 MutexTimeout( (byte)0x1),
93 LockTimeout( (byte)0x2),
94 LockLimit( (byte)0x3),
95 MaxSubCode( (byte)0x7E);
96
97 private final byte value;
98
99 SubCode(final byte value) {
100 this.value = value;
101 }
102
103 public static SubCode getSubCode(final byte value) {
104 for (final SubCode subCode : SubCode.values()) {
105 if (subCode.value == value){
106 return subCode;
107 }
108 }
109 throw new IllegalArgumentException(
110 "Illegal value provided for SubCode.");
111 }
112 }
113 }