-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring for RequestRetryPolicies and classes in exceptions.errors…
… package (#162) Added TarantoolNoSuchProcedureException and refactored TarantoolErrors for parsing errors from MsgPack maps
- Loading branch information
Showing
27 changed files
with
483 additions
and
285 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 55 additions & 61 deletions
116
src/main/java/io/tarantool/driver/api/retry/TarantoolRequestRetryPolicies.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/io/tarantool/driver/exceptions/TarantoolNoSuchProcedureException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.tarantool.driver.exceptions; | ||
|
||
/** | ||
* Corresponds to an exception that occurs when the procedure has not (yet) been defined in the Tarantool instance. | ||
* <p></p> | ||
* For example: this exception can be raised when a Cartridge role is not up yet or is being reloaded at the moment. | ||
* This can happen when the tarantool 'router' node is restarted or hot-reloaded but the cluster is under | ||
* load at the moment. If CRUD module is used in the cluster then 'cartridge.roles.crud-router' may | ||
* have not been initialized yet and all requests to CRUD will fail with this exception. | ||
* | ||
* You can use this exception when you are sure that it's worth trying a few more times until the role is up. | ||
* | ||
* @author Oleg Kuznetsov | ||
*/ | ||
public class TarantoolNoSuchProcedureException extends TarantoolException { | ||
public TarantoolNoSuchProcedureException(String errorMessage) { | ||
super(errorMessage); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/io/tarantool/driver/exceptions/errors/BoxErrorKey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.tarantool.driver.exceptions.errors; | ||
|
||
import org.msgpack.value.StringValue; | ||
import org.msgpack.value.ValueFactory; | ||
|
||
/** | ||
* Errors keys for error message in box error | ||
* | ||
* @author Oleg Kuznetsov | ||
*/ | ||
enum BoxErrorKey implements ErrorKey { | ||
CODE("code", ValueFactory.newString("code")), | ||
BASE_TYPE("base_type", ValueFactory.newString("base_type")), | ||
TYPE("type", ValueFactory.newString("type")), | ||
MESSAGE("message", ValueFactory.newString("message")), | ||
TRACE("trace", ValueFactory.newString("trace")); | ||
|
||
private final String key; | ||
private final StringValue msgPackKey; | ||
|
||
BoxErrorKey(String key, StringValue msgPackKey) { | ||
this.key = key; | ||
this.msgPackKey = msgPackKey; | ||
} | ||
|
||
@Override | ||
public String getKey() { | ||
return key; | ||
} | ||
|
||
@Override | ||
public StringValue getMsgPackKey() { | ||
return msgPackKey; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/io/tarantool/driver/exceptions/errors/ErrorCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io.tarantool.driver.exceptions.errors; | ||
|
||
/** | ||
* Error codes used to classify errors | ||
* <a href="https://github.com/tarantool/tarantool/blob/master/src/box/errcode.h">Tarantool error codes</a> | ||
* | ||
* @author Oleg Kuznetsov | ||
*/ | ||
enum ErrorCode { | ||
NO_SUCH_PROCEDURE(33L), NO_CONNECTION(77L), TIMEOUT(78L); | ||
private final Long code; | ||
|
||
ErrorCode(Long code) { | ||
this.code = code; | ||
} | ||
|
||
public Long getCode() { | ||
return code; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/io/tarantool/driver/exceptions/errors/ErrorKey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.tarantool.driver.exceptions.errors; | ||
|
||
import org.msgpack.value.StringValue; | ||
|
||
/** | ||
* Representations for error key | ||
* | ||
* @author Oleg Kuznetsov | ||
*/ | ||
interface ErrorKey { | ||
String getKey(); | ||
|
||
StringValue getMsgPackKey(); | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/io/tarantool/driver/exceptions/errors/ErrorMessageBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package io.tarantool.driver.exceptions.errors; | ||
|
||
import org.msgpack.value.StringValue; | ||
import org.msgpack.value.Value; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* This class can create error message by keys from msgPack error response | ||
* | ||
* @author Oleg Kuznetsov | ||
*/ | ||
class ErrorMessageBuilder { | ||
|
||
private final StringBuilder stringBuilder; | ||
private final Map<Value, Value> values; | ||
private final ErrorKey[] keys; | ||
|
||
ErrorMessageBuilder(String startsWith, ErrorKey[] keys, Map<Value, Value> values) { | ||
this.stringBuilder = new StringBuilder(startsWith); | ||
this.values = values; | ||
this.keys = keys; | ||
} | ||
|
||
String build() { | ||
for (ErrorKey key : keys) { | ||
final StringValue stringValue = key.getMsgPackKey(); | ||
final String s = values.containsKey(stringValue) ? values.get(stringValue).toString() : null; | ||
if (s != null && s.length() != 0) { | ||
stringBuilder.append("\n").append(key.getKey().toLowerCase()).append(": ").append(s); | ||
} | ||
} | ||
|
||
return stringBuilder.toString(); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/io/tarantool/driver/exceptions/errors/ErrorsErrorKey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package io.tarantool.driver.exceptions.errors; | ||
|
||
import org.msgpack.value.StringValue; | ||
import org.msgpack.value.ValueFactory; | ||
|
||
/** | ||
* Errors keys for error message from tarantool/errors library | ||
* | ||
* @author Oleg Kuznetsov | ||
*/ | ||
enum ErrorsErrorKey implements ErrorKey { | ||
LINE("line", ValueFactory.newString("line")), | ||
CLASS_NAME("class_name", ValueFactory.newString("class_name")), | ||
ERR("err", ValueFactory.newString("err")), | ||
FILE("file", ValueFactory.newString("file")), | ||
ERROR_MESSAGE("str", ValueFactory.newString("str")), | ||
STACKTRACE("stack", ValueFactory.newString("stack")); | ||
|
||
private final String key; | ||
private final StringValue msgPackKey; | ||
|
||
ErrorsErrorKey(String key, StringValue msgPackKey) { | ||
this.key = key; | ||
this.msgPackKey = msgPackKey; | ||
} | ||
|
||
@Override | ||
public String getKey() { | ||
return key; | ||
} | ||
|
||
@Override | ||
public StringValue getMsgPackKey() { | ||
return msgPackKey; | ||
} | ||
} |
Oops, something went wrong.