rename Timi
This commit is contained in:
+8
-8
@@ -1,4 +1,4 @@
|
||||
package com.imyeyu.java.bean.timi;
|
||||
package com.imyeyu.java.bean;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@@ -11,10 +11,10 @@ import java.util.Map;
|
||||
* @since 2023-04-27 15:55
|
||||
*/
|
||||
@Getter
|
||||
public class TimiError extends AssertionError {
|
||||
public class ActionError extends AssertionError {
|
||||
|
||||
/** 代码 */
|
||||
protected final TimiCode code;
|
||||
protected final ResultCode code;
|
||||
|
||||
/** 消息代码 */
|
||||
protected final String messageCode;
|
||||
@@ -23,7 +23,7 @@ public class TimiError extends AssertionError {
|
||||
protected final transient Map<String, Object> messageArgs;
|
||||
|
||||
/** @param code 代码 */
|
||||
public TimiError(TimiCode code) {
|
||||
public ActionError(ResultCode code) {
|
||||
this(code, code.toString());
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public class TimiError extends AssertionError {
|
||||
* @param code 代码
|
||||
* @param messageCode 消息代码
|
||||
*/
|
||||
public TimiError(TimiCode code, String messageCode) {
|
||||
public ActionError(ResultCode code, String messageCode) {
|
||||
this(code, messageCode, null);
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public class TimiError extends AssertionError {
|
||||
* @param messageCode 消息代码
|
||||
* @param messageArgs 消息插值参数
|
||||
*/
|
||||
public TimiError(TimiCode code, String messageCode, Map<String, Object> messageArgs) {
|
||||
public ActionError(ResultCode code, String messageCode, Map<String, Object> messageArgs) {
|
||||
super(messageCode);
|
||||
this.code = code;
|
||||
this.messageCode = messageCode;
|
||||
@@ -56,7 +56,7 @@ public class TimiError extends AssertionError {
|
||||
*
|
||||
* @return 响应
|
||||
*/
|
||||
public TimiResponse<?> toResponse() {
|
||||
return new TimiResponse<>(code).messageCode(messageCode, messageArgs);
|
||||
public Response<?> toResponse() {
|
||||
return new Response<>(code).messageCode(messageCode, messageArgs);
|
||||
}
|
||||
}
|
||||
+25
-26
@@ -1,7 +1,6 @@
|
||||
package com.imyeyu.java.bean.timi;
|
||||
package com.imyeyu.java.bean;
|
||||
|
||||
import com.imyeyu.java.TimiJava;
|
||||
import com.imyeyu.java.bean.CallbackReturn;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -13,10 +12,10 @@ import java.util.Map;
|
||||
* @since 2021-05-20 15:18
|
||||
*/
|
||||
@Getter
|
||||
public class TimiException extends RuntimeException {
|
||||
public class ActionException extends RuntimeException {
|
||||
|
||||
/** 代码 */
|
||||
protected final TimiCode code;
|
||||
protected final ResultCode code;
|
||||
|
||||
/** 消息代码 */
|
||||
protected final String messageCode;
|
||||
@@ -25,7 +24,7 @@ public class TimiException extends RuntimeException {
|
||||
protected final transient Map<String, Object> messageArgs;
|
||||
|
||||
/** @param code 代码 */
|
||||
public TimiException(TimiCode code) {
|
||||
public ActionException(ResultCode code) {
|
||||
this(code, code.toString());
|
||||
}
|
||||
|
||||
@@ -35,7 +34,7 @@ public class TimiException extends RuntimeException {
|
||||
* @param code 代码
|
||||
* @param messageCode 消息代码
|
||||
*/
|
||||
public TimiException(TimiCode code, String messageCode) {
|
||||
public ActionException(ResultCode code, String messageCode) {
|
||||
this(code, messageCode, (Map<String, Object>) null);
|
||||
}
|
||||
|
||||
@@ -46,7 +45,7 @@ public class TimiException extends RuntimeException {
|
||||
* @param messageCode 消息代码
|
||||
* @param messageArgs 消息插值参数
|
||||
*/
|
||||
public TimiException(TimiCode code, String messageCode, Map<String, Object> messageArgs) {
|
||||
public ActionException(ResultCode code, String messageCode, Map<String, Object> messageArgs) {
|
||||
super(messageCode);
|
||||
this.code = code;
|
||||
this.messageCode = messageCode;
|
||||
@@ -60,7 +59,7 @@ public class TimiException extends RuntimeException {
|
||||
* @param messageCode 消息代码
|
||||
* @param e 异常
|
||||
*/
|
||||
public TimiException(TimiCode code, String messageCode, Throwable e) {
|
||||
public ActionException(ResultCode code, String messageCode, Throwable e) {
|
||||
super(messageCode, e);
|
||||
this.code = code;
|
||||
this.messageCode = messageCode;
|
||||
@@ -72,63 +71,63 @@ public class TimiException extends RuntimeException {
|
||||
*
|
||||
* @return 响应
|
||||
*/
|
||||
public TimiResponse<?> toResponse() {
|
||||
return new TimiResponse<>(code).messageCode(messageCode, messageArgs);
|
||||
public Response<?> toResponse() {
|
||||
return new Response<>(code).messageCode(messageCode, messageArgs);
|
||||
}
|
||||
|
||||
public static <T> T required(T t, String messageCode) {
|
||||
if (TimiJava.isEmpty(t)) {
|
||||
throw new TimiException(TimiCode.ARG_MISS, messageCode);
|
||||
throw new ActionException(ResultCode.ARG_MISS, messageCode);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
public static <T> T required(T t, String messageCode, Map<String, Object> messageArgs) {
|
||||
if (TimiJava.isEmpty(t)) {
|
||||
throw new TimiException(TimiCode.ARG_MISS, messageCode, messageArgs);
|
||||
throw new ActionException(ResultCode.ARG_MISS, messageCode, messageArgs);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
public static <T> void requiredNull(T t, String messageCode) throws TimiException {
|
||||
public static <T> void requiredNull(T t, String messageCode) throws ActionException {
|
||||
if (t != null) {
|
||||
throw new TimiException(TimiCode.ERROR, messageCode);
|
||||
throw new ActionException(ResultCode.ERROR, messageCode);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> void requiredNull(T t, String messageCode, Map<String, Object> messageArgs) throws TimiException {
|
||||
public static <T> void requiredNull(T t, String messageCode, Map<String, Object> messageArgs) throws ActionException {
|
||||
if (t != null) {
|
||||
throw new TimiException(TimiCode.ERROR, messageCode, messageArgs);
|
||||
throw new ActionException(ResultCode.ERROR, messageCode, messageArgs);
|
||||
}
|
||||
}
|
||||
|
||||
public static void requiredTrue(boolean bool, String messageCode) throws TimiException {
|
||||
public static void requiredTrue(boolean bool, String messageCode) throws ActionException {
|
||||
if (bool) {
|
||||
return;
|
||||
}
|
||||
throw new TimiException(TimiCode.ERROR, messageCode);
|
||||
throw new ActionException(ResultCode.ERROR, messageCode);
|
||||
}
|
||||
|
||||
public static void requiredTrue(boolean bool, String messageCode, Map<String, Object> messageArgs) throws TimiException {
|
||||
public static void requiredTrue(boolean bool, String messageCode, Map<String, Object> messageArgs) throws ActionException {
|
||||
if (bool) {
|
||||
return;
|
||||
}
|
||||
throw new TimiException(TimiCode.ERROR, messageCode, messageArgs);
|
||||
throw new ActionException(ResultCode.ERROR, messageCode, messageArgs);
|
||||
}
|
||||
|
||||
public static void requiredTrue(CallbackReturn<Boolean> callback, String messageCode) throws TimiException {
|
||||
TimiException.required(callback, "not found callback");
|
||||
public static void requiredTrue(CallbackReturn<Boolean> callback, String messageCode) throws ActionException {
|
||||
ActionException.required(callback, "not found callback");
|
||||
if (callback.handler()) {
|
||||
return;
|
||||
}
|
||||
throw new TimiException(TimiCode.ERROR, messageCode);
|
||||
throw new ActionException(ResultCode.ERROR, messageCode);
|
||||
}
|
||||
|
||||
public static void requiredTrue(CallbackReturn<Boolean> callback, String messageCode, Map<String, Object> messageArgs) throws TimiException {
|
||||
TimiException.required(callback, "not found callback");
|
||||
public static void requiredTrue(CallbackReturn<Boolean> callback, String messageCode, Map<String, Object> messageArgs) throws ActionException {
|
||||
ActionException.required(callback, "not found callback");
|
||||
if (callback.handler()) {
|
||||
return;
|
||||
}
|
||||
throw new TimiException(TimiCode.ERROR, messageCode, messageArgs);
|
||||
throw new ActionException(ResultCode.ERROR, messageCode, messageArgs);
|
||||
}
|
||||
}
|
||||
+11
-11
@@ -1,4 +1,4 @@
|
||||
package com.imyeyu.java.bean.timi;
|
||||
package com.imyeyu.java.bean;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
@@ -16,7 +16,7 @@ import java.util.Map;
|
||||
* @since 2021-07-01 20:18
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
public class TimiResponse<T> implements Serializable {
|
||||
public class Response<T> implements Serializable {
|
||||
|
||||
/** 响应代码 */
|
||||
@Setter
|
||||
@@ -48,7 +48,7 @@ public class TimiResponse<T> implements Serializable {
|
||||
*
|
||||
* @param code 代码
|
||||
*/
|
||||
public TimiResponse(TimiCode code) {
|
||||
public Response(ResultCode code) {
|
||||
this(code, null);
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public class TimiResponse<T> implements Serializable {
|
||||
* @param code 代码
|
||||
* @param data 数据体
|
||||
*/
|
||||
public TimiResponse(TimiCode code, T data) {
|
||||
public Response(ResultCode code, T data) {
|
||||
this(code, data, null);
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public class TimiResponse<T> implements Serializable {
|
||||
* @param data 数据体
|
||||
* @param message 响应消息
|
||||
*/
|
||||
public TimiResponse(TimiCode code, T data, String message) {
|
||||
public Response(ResultCode code, T data, String message) {
|
||||
this.code = code.getValue();
|
||||
this.data = data;
|
||||
this.message = message;
|
||||
@@ -90,12 +90,12 @@ public class TimiResponse<T> implements Serializable {
|
||||
*
|
||||
* @return 异常
|
||||
*/
|
||||
public TimiException toException() {
|
||||
TimiCode code = TimiCode.fromCode(this.code);
|
||||
public ActionException toException() {
|
||||
ResultCode code = ResultCode.fromCode(this.code);
|
||||
if (code == null) {
|
||||
throw new NullPointerException("unknow timi code: " + this.code);
|
||||
}
|
||||
return new TimiException(code, messageCode == null ? message : messageCode, messageArgs);
|
||||
return new ActionException(code, messageCode == null ? message : messageCode, messageArgs);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,7 +104,7 @@ public class TimiResponse<T> implements Serializable {
|
||||
* @param message 响应消息
|
||||
* @return 本对象
|
||||
*/
|
||||
public TimiResponse<T> message(String message) {
|
||||
public Response<T> message(String message) {
|
||||
this.message = message;
|
||||
return this;
|
||||
}
|
||||
@@ -115,7 +115,7 @@ public class TimiResponse<T> implements Serializable {
|
||||
* @param messageCode 响应消息代码
|
||||
* @return 本对象
|
||||
*/
|
||||
public TimiResponse<T> messageCode(String messageCode) {
|
||||
public Response<T> messageCode(String messageCode) {
|
||||
this.messageCode = messageCode;
|
||||
return this;
|
||||
}
|
||||
@@ -127,7 +127,7 @@ public class TimiResponse<T> implements Serializable {
|
||||
* @param messageArgs 插值参数
|
||||
* @return 本对象
|
||||
*/
|
||||
public TimiResponse<T> messageCode(String messageCode, Map<String, Object> messageArgs) {
|
||||
public Response<T> messageCode(String messageCode, Map<String, Object> messageArgs) {
|
||||
this.messageCode = messageCode;
|
||||
this.messageArgs = messageArgs;
|
||||
return this;
|
||||
+13
-13
@@ -1,4 +1,4 @@
|
||||
package com.imyeyu.java.bean.timi;
|
||||
package com.imyeyu.java.bean;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@@ -9,7 +9,7 @@ import lombok.Getter;
|
||||
* @since 2021-05-21 14:32
|
||||
*/
|
||||
@Getter
|
||||
public enum TimiCode {
|
||||
public enum ResultCode {
|
||||
|
||||
// ---------- 200 正常 ----------
|
||||
|
||||
@@ -80,7 +80,7 @@ public enum TimiCode {
|
||||
/** 代码 */
|
||||
final Integer value;
|
||||
|
||||
TimiCode(Integer value) {
|
||||
ResultCode(Integer value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ public enum TimiCode {
|
||||
*
|
||||
* @return 异常
|
||||
*/
|
||||
public TimiException toException() {
|
||||
public ActionException toException() {
|
||||
return toException(toString());
|
||||
}
|
||||
|
||||
@@ -99,8 +99,8 @@ public enum TimiCode {
|
||||
* @param msg 异常消息
|
||||
* @return 异常
|
||||
*/
|
||||
public TimiException toException(String msg) {
|
||||
return new TimiException(this, msg);
|
||||
public ActionException toException(String msg) {
|
||||
return new ActionException(this, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,8 +108,8 @@ public enum TimiCode {
|
||||
*
|
||||
* @return 返回对象
|
||||
*/
|
||||
public TimiResponse<?> toResponse() {
|
||||
return new TimiResponse<>(this).message(toString());
|
||||
public Response<?> toResponse() {
|
||||
return new Response<>(this).message(toString());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,11 +118,11 @@ public enum TimiCode {
|
||||
* @param code 代码
|
||||
* @return 对象
|
||||
*/
|
||||
public static TimiCode fromCode(int code) {
|
||||
TimiCode[] codes = values();
|
||||
for (TimiCode timiCode : codes) {
|
||||
if (timiCode.getValue() == code) {
|
||||
return timiCode;
|
||||
public static ResultCode fromCode(int code) {
|
||||
ResultCode[] codes = values();
|
||||
for (ResultCode resultCode : codes) {
|
||||
if (resultCode.getValue() == code) {
|
||||
return resultCode;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -1,2 +0,0 @@
|
||||
/** 个人常用的通用类 */
|
||||
package com.imyeyu.java.bean.timi;
|
||||
@@ -2,7 +2,7 @@ package com.imyeyu.java.thread;
|
||||
|
||||
import com.imyeyu.java.bean.Callback;
|
||||
import com.imyeyu.java.bean.CallbackArg;
|
||||
import com.imyeyu.java.bean.timi.TimiException;
|
||||
import com.imyeyu.java.bean.ActionException;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
@@ -83,8 +83,8 @@ public class AsyncRetryExecutor {
|
||||
* @param task 构建器对象
|
||||
*/
|
||||
private AsyncRetryExecutor(Task task) {
|
||||
TimiException.required(task, "not found task");
|
||||
TimiException.required(task.getCallback(), "not found task.callback");
|
||||
ActionException.required(task, "not found task");
|
||||
ActionException.required(task.getCallback(), "not found task.callback");
|
||||
thread = new Thread(() -> {
|
||||
int retryCount = 0;
|
||||
while (isRunning && !isSuccess && (task.maxRetry < 0 || retryCount <= task.maxRetry)) {
|
||||
|
||||
Reference in New Issue
Block a user