]>
git.proxmox.com Git - ceph.git/blob - 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 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).
8 import java
.util
.Objects
;
11 * Represents the status returned by a function call in RocksDB.
13 * Currently only used with {@link RocksDBException} when the
14 * status is not {@link Code#Ok}
17 private final Code code
;
18 /* @Nullable */ private final SubCode subCode
;
19 /* @Nullable */ private final String state
;
21 public Status(final Code code
, final SubCode subCode
, final String state
) {
23 this.subCode
= subCode
;
28 * Intentionally private as this will be called from JNI
30 private Status(final byte code
, final byte subCode
, final String state
) {
31 this.code
= Code
.getCode(code
);
32 this.subCode
= SubCode
.getSubCode(subCode
);
36 public Code
getCode() {
40 public SubCode
getSubCode() {
44 public String
getState() {
48 public String
getCodeString() {
49 final StringBuilder builder
= new StringBuilder()
51 if(subCode
!= null && subCode
!= SubCode
.None
) {
53 .append(subCode
.name())
56 return builder
.toString();
59 // should stay in sync with /include/rocksdb/status.h:Code and /java/rocksjni/portal.h:toJavaStatusCode
63 Corruption( (byte)0x2),
64 NotSupported( (byte)0x3),
65 InvalidArgument( (byte)0x4),
67 MergeInProgress( (byte)0x6),
68 Incomplete( (byte)0x7),
69 ShutdownInProgress( (byte)0x8),
75 Undefined( (byte)0x7F);
77 private final byte value
;
79 Code(final byte value
) {
83 public static Code
getCode(final byte value
) {
84 for (final Code code
: Code
.values()) {
85 if (code
.value
== value
){
89 throw new IllegalArgumentException(
90 "Illegal value provided for Code (" + value
+ ").");
94 * Returns the byte value of the enumerations value.
96 * @return byte representation
98 public byte getValue() {
103 // should stay in sync with /include/rocksdb/status.h:SubCode and /java/rocksjni/portal.h:toJavaStatusSubCode
104 public enum SubCode
{
106 MutexTimeout( (byte)0x1),
107 LockTimeout( (byte)0x2),
108 LockLimit( (byte)0x3),
110 Deadlock( (byte)0x5),
111 StaleFile( (byte)0x6),
112 MemoryLimit( (byte)0x7),
113 Undefined( (byte)0x7F);
115 private final byte value
;
117 SubCode(final byte value
) {
121 public static SubCode
getSubCode(final byte value
) {
122 for (final SubCode subCode
: SubCode
.values()) {
123 if (subCode
.value
== value
){
127 throw new IllegalArgumentException(
128 "Illegal value provided for SubCode (" + value
+ ").");
132 * Returns the byte value of the enumerations value.
134 * @return byte representation
136 public byte getValue() {
142 public boolean equals(Object o
) {
145 if (o
== null || getClass() != o
.getClass())
147 Status status
= (Status
) o
;
148 return code
== status
.code
&& subCode
== status
.subCode
&& Objects
.equals(state
, status
.state
);
152 public int hashCode() {
153 return Objects
.hash(code
, subCode
, state
);