blob: ba2a00af1ff3a093a0c9ab60dccab5ebc75d06d5 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.persistence.spi.result;
/**
* Represents a result from an SPI method invocation.
*/
public class Result {
/**
* Enumeration of the various categories of errors that can be returned
* in a result.
*
* The categories are:
*
* TRANSIENT_ERROR: Operation failed, but may succeed if attempted again or on other data copies
* PERMANENT_ERROR: Operation failed because it was somehow malformed or the operation parameters were wrong. Operation won't succeed
* on other data copies either.
* FATAL_ERROR: Operation failed in such a way that this node should be stopped (for instance, a disk failure). Operation will be retried
* on other data copies.
*/
public enum ErrorType {
NONE,
TRANSIENT_ERROR,
PERMANENT_ERROR,
UNUSED_ID,
FATAL_ERROR
}
/**
* Constructor to use for a result where there is no error.
*/
public Result() {
}
/**
* Creates a result with an error.
*
* @param type The type of error
* @param message A human-readable error message to further detail the error.
*/
public Result(ErrorType type, String message) {
this.type = type;
this.message = message;
}
public boolean equals(Result other) {
return type.equals(other.type) &&
message.equals(other.message);
}
@Override
public boolean equals(Object otherResult) {
if (otherResult instanceof Result) {
return equals((Result)otherResult);
}
return false;
}
public boolean hasError() {
return type != ErrorType.NONE;
}
public ErrorType getErrorType() {
return type;
}
public String getErrorMessage() {
return message;
}
@Override
public String toString() {
if (type == null) {
return "Result(OK)";
}
return "Result(" + type.toString() + ", " + message + ")";
}
ErrorType type = ErrorType.NONE;
String message = "";
}
|