update: add call back service

This commit is contained in:
hongqiaowei
2021-02-01 10:57:28 +08:00
parent bd67e36540
commit e1becde4b0
2 changed files with 102 additions and 18 deletions

View File

@@ -17,27 +17,20 @@
package we.util;
import java.util.Map;
/**
* @author hongqiaowei
*/
public class ReactiveResult<D> {
public static final int SUCC = 1;
public static final int FAIL = 0;
public int code = -1;
public String msg;
public D data;
public class ReactiveResult<D> extends Result<D> {
public Throwable t;
public Map<Object, Object> context;
public ReactiveResult(int code, String msg, D data, Throwable t) {
this.code = code;
this.msg = msg;
this.data = data;
super(code, msg, data);
this.t = t;
}
@@ -46,7 +39,9 @@ public class ReactiveResult<D> {
}
public static <D> ReactiveResult<D> succ(D data) {
return new ReactiveResult<D>(SUCC, null, data, null);
ReactiveResult rr = succ();
rr.data = data;
return rr;
}
public static ReactiveResult fail() {
@@ -54,11 +49,15 @@ public class ReactiveResult<D> {
}
public static ReactiveResult fail(String msg) {
return new ReactiveResult(FAIL, msg, null, null);
ReactiveResult rr = fail();
rr.msg = msg;
return rr;
}
public static ReactiveResult fail(Throwable t) {
return new ReactiveResult(FAIL, null, null, t);
ReactiveResult rr = fail();
rr.t = t;
return rr;
}
public static ReactiveResult with(int code) {
@@ -66,11 +65,15 @@ public class ReactiveResult<D> {
}
public static ReactiveResult with(int code, String msg) {
return new ReactiveResult(code, msg, null, null);
ReactiveResult rr = with(code);
rr.msg = msg;
return rr;
}
public static <D> ReactiveResult<D> with(int code, D data) {
return new ReactiveResult<D>(code, null, data, null);
ReactiveResult rr = with(code);
rr.data = data;
return rr;
}
@Override

View File

@@ -0,0 +1,81 @@
/*
* Copyright (C) 2020 the original author or authors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package we.util;
/**
* @author hongqiaowei
*/
public class Result<D> {
public static final int SUCC = 1;
public static final int FAIL = 0;
public int code = -1;
public String msg;
public D data;
public Result(int code, String msg, D data) {
this.code = code;
this.msg = msg;
this.data = data;
}
public static Result succ() {
return new Result(SUCC, null, null);
}
public static <D> Result<D> succ(D data) {
Result r = succ();
r.data = data;
return r;
}
public static Result fail() {
return new Result(FAIL, null, null);
}
public static Result fail(String msg) {
Result r = fail();
r.msg = msg;
return r;
}
public static Result with(int code) {
return new Result(code, null, null);
}
public static Result with(int code, String msg) {
Result r = with(code);
r.msg = msg;
return r;
}
public static <D> Result<D> with(int code, D data) {
Result r = with(code);
r.data = data;
return r;
}
@Override
public String toString() {
return JacksonUtils.writeValueAsString(this);
}
}