MCPcopy Create free account
hub / github.com/apache/kudu / Status

Class Status

java/kudu-client/src/main/java/org/apache/kudu/client/Status.java:32–425  ·  view source on GitHub ↗

Representation of an error code and message. See also src/kudu/util/status.h in the C++ codebase.

Source from the content-addressed store, hash-verified

30 * See also {@code src/kudu/util/status.h} in the C++ codebase.
31 */
32@InterfaceAudience.Public
33@InterfaceStability.Evolving
34public class Status {
35
36 // Limit the message size we get from the servers as it can be quite large.
37 @InterfaceAudience.LimitedPrivate("Test")
38 static final int MAX_MESSAGE_LENGTH = 32 * 1024;
39 @InterfaceAudience.LimitedPrivate("Test")
40 static final String ABBREVIATION_CHARS = "...";
41 @InterfaceAudience.LimitedPrivate("Test")
42 static final int ABBREVIATION_CHARS_LENGTH = ABBREVIATION_CHARS.length();
43
44 // Keep a single OK status object else we'll end up instantiating tons of them.
45 private static final Status STATIC_OK = new Status(WireProtocol.AppStatusPB.ErrorCode.OK);
46
47 private final WireProtocol.AppStatusPB.ErrorCode code;
48 private final String message;
49 private final int posixCode;
50
51 private Status(WireProtocol.AppStatusPB.ErrorCode code, String msg, int posixCode) {
52 this.code = code;
53 this.posixCode = posixCode;
54
55 if (msg.length() > MAX_MESSAGE_LENGTH) {
56 // Truncate the message and indicate that it was abbreviated.
57 this.message = msg.substring(0, MAX_MESSAGE_LENGTH - ABBREVIATION_CHARS_LENGTH) +
58 ABBREVIATION_CHARS;
59 } else {
60 this.message = msg;
61 }
62 }
63
64 private Status(WireProtocol.AppStatusPB appStatusPB) {
65 this(appStatusPB.getCode(), appStatusPB.getMessage(), appStatusPB.getPosixCode());
66 }
67
68 private Status(WireProtocol.AppStatusPB.ErrorCode code, String msg) {
69 this(code, msg, -1);
70 }
71
72 private Status(WireProtocol.AppStatusPB.ErrorCode code) {
73 this(code, "", -1);
74 }
75
76 // Factory methods.
77
78 /**
79 * Create a status object from a master error.
80 * @param masterErrorPB pb object received via RPC from the master
81 * @return status object equivalent to the pb
82 */
83 static Status fromMasterErrorPB(Master.MasterErrorPB masterErrorPB) {
84 assert masterErrorPB.hasStatus() : "no status in PB " + masterErrorPB;
85 return new Status(masterErrorPB.getStatus());
86 }
87
88 /**
89 * Create a status object from a tablet server error.

Callers

nothing calls this directly

Calls 1

lengthMethod · 0.45

Tested by

no test coverage detected