【不兼容】DLong更名为Uint128
This commit is contained in:
@@ -116,7 +116,7 @@ public abstract class ConvertFactory<R extends Reader, W extends Writer> {
|
||||
this.register(BigDecimal.class, BigDecimalSimpledCoder.instance);
|
||||
this.register(InetAddress.class, InetAddressSimpledCoder.instance);
|
||||
this.register(LongAdder.class, LongAdderSimpledCoder.instance);
|
||||
this.register(DLong.class, DLongSimpledCoder.instance);
|
||||
this.register(Uint128.class, Uint128SimpledCoder.instance);
|
||||
this.register(Class.class, TypeSimpledCoder.instance);
|
||||
this.register(InetSocketAddress.class, InetAddressSimpledCoder.InetSocketAddressSimpledCoder.instance);
|
||||
this.register(Pattern.class, PatternSimpledCoder.instance);
|
||||
|
||||
@@ -19,15 +19,15 @@ import org.redkale.util.*;
|
||||
* @param <R> Reader输入的子类型
|
||||
* @param <W> Writer输出的子类型
|
||||
*/
|
||||
public final class DLongSimpledCoder<R extends Reader, W extends Writer> extends SimpledCoder<R, W, DLong> {
|
||||
public final class Uint128SimpledCoder<R extends Reader, W extends Writer> extends SimpledCoder<R, W, Uint128> {
|
||||
|
||||
private static final ByteArraySimpledCoder bsSimpledCoder = ByteArraySimpledCoder.instance;
|
||||
|
||||
public static final DLongSimpledCoder instance = new DLongSimpledCoder();
|
||||
public static final Uint128SimpledCoder instance = new Uint128SimpledCoder();
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void convertTo(final W out, final DLong value) {
|
||||
public void convertTo(final W out, final Uint128 value) {
|
||||
if (value == null) {
|
||||
out.writeNull();
|
||||
} else {
|
||||
@@ -37,26 +37,26 @@ public final class DLongSimpledCoder<R extends Reader, W extends Writer> extends
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public DLong convertFrom(R in) {
|
||||
public Uint128 convertFrom(R in) {
|
||||
byte[] bs = bsSimpledCoder.convertFrom(in);
|
||||
if (bs == null) {
|
||||
return null;
|
||||
}
|
||||
return DLong.create(bs);
|
||||
return Uint128.create(bs);
|
||||
}
|
||||
|
||||
/**
|
||||
* DLong 的JsonSimpledCoder实现
|
||||
* Uint128 的JsonSimpledCoder实现
|
||||
*
|
||||
* @param <R> Reader输入的子类型
|
||||
* @param <W> Writer输出的子类型
|
||||
*/
|
||||
public static class DLongJsonSimpledCoder<R extends JsonReader, W extends JsonWriter> extends SimpledCoder<R, W, DLong> {
|
||||
public static class Uint128JsonSimpledCoder<R extends JsonReader, W extends JsonWriter> extends SimpledCoder<R, W, Uint128> {
|
||||
|
||||
public static final DLongJsonSimpledCoder instance = new DLongJsonSimpledCoder();
|
||||
public static final Uint128JsonSimpledCoder instance = new Uint128JsonSimpledCoder();
|
||||
|
||||
@Override
|
||||
public void convertTo(final W out, final DLong value) {
|
||||
public void convertTo(final W out, final Uint128 value) {
|
||||
if (value == null) {
|
||||
out.writeNull();
|
||||
} else {
|
||||
@@ -65,12 +65,12 @@ public final class DLongSimpledCoder<R extends Reader, W extends Writer> extends
|
||||
}
|
||||
|
||||
@Override
|
||||
public DLong convertFrom(R in) {
|
||||
public Uint128 convertFrom(R in) {
|
||||
final String str = in.readSmallString();
|
||||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
return DLong.create(Utility.hexToBin(str));
|
||||
return Uint128.create(Utility.hexToBin(str));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import java.math.*;
|
||||
import java.net.*;
|
||||
import org.redkale.convert.*;
|
||||
import org.redkale.convert.ext.*;
|
||||
import org.redkale.util.DLong;
|
||||
import org.redkale.util.Uint128;
|
||||
|
||||
/**
|
||||
* JSON的ConvertFactory
|
||||
@@ -38,7 +38,7 @@ public final class JsonFactory extends ConvertFactory<JsonReader, JsonWriter> {
|
||||
if (parent == null) {
|
||||
this.register(InetAddress.class, InetAddressSimpledCoder.InetAddressJsonSimpledCoder.instance);
|
||||
this.register(InetSocketAddress.class, InetAddressSimpledCoder.InetSocketAddressJsonSimpledCoder.instance);
|
||||
this.register(DLong.class, DLongSimpledCoder.DLongJsonSimpledCoder.instance);
|
||||
this.register(Uint128.class, Uint128SimpledCoder.Uint128JsonSimpledCoder.instance);
|
||||
this.register(BigInteger.class, BigIntegerSimpledCoder.BigIntegerJsonSimpledCoder.instance);
|
||||
this.register(BigDecimal.class, BigDecimalSimpledCoder.BigDecimalJsonSimpledCoder.instance);
|
||||
this.register(java.time.Instant.class, InstantSimpledCoder.InstantJsonSimpledCoder.instance);
|
||||
|
||||
@@ -57,9 +57,9 @@ public abstract class Sncp {
|
||||
private Sncp() {
|
||||
}
|
||||
|
||||
public static DLong hash(final java.lang.reflect.Method method) {
|
||||
public static Uint128 hash(final java.lang.reflect.Method method) {
|
||||
if (method == null) {
|
||||
return DLong.ZERO;
|
||||
return Uint128.ZERO;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder(); //不能使用method.toString() 因为包含declaringClass信息导致接口与实现类的方法hash不一致
|
||||
sb.append(method.getReturnType().getName()).append(' ');
|
||||
@@ -84,15 +84,15 @@ public abstract class Sncp {
|
||||
*
|
||||
* @return hash值
|
||||
*/
|
||||
public static DLong hash(final String name) {
|
||||
public static Uint128 hash(final String name) {
|
||||
if (name == null || name.isEmpty()) {
|
||||
return DLong.ZERO;
|
||||
return Uint128.ZERO;
|
||||
}
|
||||
byte[] bytes = name.trim().getBytes();
|
||||
synchronized (md5) {
|
||||
bytes = md5.digest(bytes);
|
||||
}
|
||||
return DLong.create(bytes);
|
||||
return Uint128.create(bytes);
|
||||
}
|
||||
|
||||
public static boolean isRemote(Service service) {
|
||||
|
||||
@@ -49,7 +49,7 @@ public final class SncpClient {
|
||||
|
||||
private final int addrPort;
|
||||
|
||||
protected final DLong serviceid;
|
||||
protected final Uint128 serviceid;
|
||||
|
||||
protected final int serviceVersion;
|
||||
|
||||
@@ -116,7 +116,7 @@ public final class SncpClient {
|
||||
return clientSncpAddress;
|
||||
}
|
||||
|
||||
public DLong getServiceid() {
|
||||
public Uint128 getServiceid() {
|
||||
return serviceid;
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ public final class SncpClient {
|
||||
public static List<Method> parseMethod(final Class serviceClass) {
|
||||
final List<Method> list = new ArrayList<>();
|
||||
final List<Method> multis = new ArrayList<>();
|
||||
final Map<DLong, Method> actionids = new HashMap<>();
|
||||
final Map<Uint128, Method> actionids = new HashMap<>();
|
||||
for (final java.lang.reflect.Method method : serviceClass.getMethods()) {
|
||||
if (method.isSynthetic()) {
|
||||
continue;
|
||||
@@ -204,7 +204,7 @@ public final class SncpClient {
|
||||
}
|
||||
//if (onlySncpDyn && method.getAnnotation(SncpDyn.class) == null) continue;
|
||||
|
||||
DLong actionid = Sncp.hash(method);
|
||||
Uint128 actionid = Sncp.hash(method);
|
||||
Method old = actionids.get(actionid);
|
||||
if (old != null) {
|
||||
if (old.getDeclaringClass().equals(method.getDeclaringClass())) {
|
||||
@@ -314,7 +314,7 @@ public final class SncpClient {
|
||||
}
|
||||
final int reqBodyLength = writer.count() - HEADER_SIZE; //body总长度
|
||||
final long seqid = System.nanoTime();
|
||||
final DLong actionid = action.actionid;
|
||||
final Uint128 actionid = action.actionid;
|
||||
if (messageAgent != null) { //MQ模式
|
||||
final ByteArray reqbytes = writer.toByteArray();
|
||||
fillHeader(reqbytes, seqid, actionid, traceid, reqBodyLength);
|
||||
@@ -499,7 +499,7 @@ public final class SncpClient {
|
||||
if (buffer.getChar() != HEADER_SIZE) {
|
||||
throw new RuntimeException("sncp(" + action.method + ") buffer receive header.length not " + HEADER_SIZE);
|
||||
}
|
||||
DLong rserviceid = DLong.read(buffer);
|
||||
Uint128 rserviceid = Uint128.read(buffer);
|
||||
if (!rserviceid.equals(this.serviceid)) {
|
||||
throw new RuntimeException("sncp(" + action.method + ") response.serviceid = " + serviceid + ", but request.serviceid =" + rserviceid);
|
||||
}
|
||||
@@ -507,8 +507,8 @@ public final class SncpClient {
|
||||
if (version != this.serviceVersion) {
|
||||
throw new RuntimeException("sncp(" + action.method + ") response.serviceVersion = " + serviceVersion + ", but request.serviceVersion =" + version);
|
||||
}
|
||||
DLong raction = DLong.read(buffer);
|
||||
DLong actid = action.actionid;
|
||||
Uint128 raction = Uint128.read(buffer);
|
||||
Uint128 actid = action.actionid;
|
||||
if (!actid.equals(raction)) {
|
||||
throw new RuntimeException("sncp(" + action.method + ") response.actionid = " + action.actionid + ", but request.actionid =(" + raction + ")");
|
||||
}
|
||||
@@ -516,14 +516,14 @@ public final class SncpClient {
|
||||
buffer.getChar(); //端口
|
||||
}
|
||||
|
||||
private void fillHeader(ByteArray buffer, long seqid, DLong actionid, String traceid, int bodyLength) {
|
||||
private void fillHeader(ByteArray buffer, long seqid, Uint128 actionid, String traceid, int bodyLength) {
|
||||
fillRespHeader(buffer, seqid, this.serviceid, this.serviceVersion,
|
||||
actionid, traceid, this.addrBytes, this.addrPort, bodyLength, 0); //结果码, 请求方固定传0
|
||||
}
|
||||
|
||||
protected static final class SncpAction {
|
||||
|
||||
protected final DLong actionid;
|
||||
protected final Uint128 actionid;
|
||||
|
||||
protected final Method method;
|
||||
|
||||
@@ -550,7 +550,7 @@ public final class SncpClient {
|
||||
protected final Creator<? extends CompletableFuture> futureCreator;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public SncpAction(final Class clazz, Method method, DLong actionid) {
|
||||
public SncpAction(final Class clazz, Method method, Uint128 actionid) {
|
||||
this.actionid = actionid == null ? Sncp.hash(method) : actionid;
|
||||
Type rt = TypeToken.getGenericType(method.getGenericReturnType(), clazz);
|
||||
this.resultTypes = rt == void.class ? null : rt;
|
||||
|
||||
@@ -17,12 +17,12 @@ import org.redkale.util.*;
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class SncpDispatcherServlet extends DispatcherServlet<DLong, SncpContext, SncpRequest, SncpResponse, SncpServlet> {
|
||||
public class SncpDispatcherServlet extends DispatcherServlet<Uint128, SncpContext, SncpRequest, SncpResponse, SncpServlet> {
|
||||
|
||||
private final Object sncplock = new Object();
|
||||
|
||||
@Override
|
||||
public void addServlet(SncpServlet servlet, Object attachment, AnyValue conf, DLong... mappings) {
|
||||
public void addServlet(SncpServlet servlet, Object attachment, AnyValue conf, Uint128... mappings) {
|
||||
synchronized (sncplock) {
|
||||
for (SncpServlet s : getServlets()) {
|
||||
if (s.service == servlet.service) {
|
||||
|
||||
@@ -39,9 +39,9 @@ public final class SncpDynServlet extends SncpServlet {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(SncpDynServlet.class.getSimpleName());
|
||||
|
||||
private final DLong serviceid;
|
||||
private final Uint128 serviceid;
|
||||
|
||||
private final HashMap<DLong, SncpServletAction> actions = new HashMap<>();
|
||||
private final HashMap<Uint128, SncpServletAction> actions = new HashMap<>();
|
||||
|
||||
public SncpDynServlet(final BsonConvert convert, final String serviceName, final Class serviceOrSourceType, final Service service,
|
||||
final AtomicInteger maxTypeLength, AtomicInteger maxNameLength) {
|
||||
@@ -49,7 +49,7 @@ public final class SncpDynServlet extends SncpServlet {
|
||||
this.maxTypeLength = maxTypeLength;
|
||||
this.maxNameLength = maxNameLength;
|
||||
this.serviceid = Sncp.hash(type.getName() + ':' + serviceName);
|
||||
Set<DLong> actionids = new HashSet<>();
|
||||
Set<Uint128> actionids = new HashSet<>();
|
||||
RedkaleClassLoader.putReflectionPublicMethods(service.getClass().getName());
|
||||
for (java.lang.reflect.Method method : service.getClass().getMethods()) {
|
||||
if (method.isSynthetic()) {
|
||||
@@ -79,7 +79,7 @@ public final class SncpDynServlet extends SncpServlet {
|
||||
}
|
||||
}
|
||||
|
||||
final DLong actionid = Sncp.hash(method);
|
||||
final Uint128 actionid = Sncp.hash(method);
|
||||
SncpServletAction action;
|
||||
try {
|
||||
action = SncpServletAction.create(service, actionid, method);
|
||||
@@ -114,7 +114,7 @@ public final class SncpDynServlet extends SncpServlet {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DLong getServiceid() {
|
||||
public Uint128 getServiceid() {
|
||||
return serviceid;
|
||||
}
|
||||
|
||||
@@ -326,7 +326,7 @@ public final class SncpDynServlet extends SncpServlet {
|
||||
* @return SncpServletAction
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static SncpServletAction create(final Service service, final DLong actionid, final Method method) {
|
||||
public static SncpServletAction create(final Service service, final Uint128 actionid, final Method method) {
|
||||
final Class serviceClass = service.getClass();
|
||||
final String supDynName = SncpServletAction.class.getName().replace('.', '/');
|
||||
final String serviceName = serviceClass.getName().replace('.', '/');
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.nio.ByteBuffer;
|
||||
import java.util.logging.*;
|
||||
import org.redkale.convert.bson.BsonConvert;
|
||||
import org.redkale.net.Request;
|
||||
import org.redkale.util.DLong;
|
||||
import org.redkale.util.Uint128;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -41,9 +41,9 @@ public class SncpRequest extends Request<SncpContext> {
|
||||
|
||||
private int serviceVersion;
|
||||
|
||||
private DLong serviceid;
|
||||
private Uint128 serviceid;
|
||||
|
||||
private DLong actionid;
|
||||
private Uint128 actionid;
|
||||
|
||||
private int bodyLength;
|
||||
|
||||
@@ -82,9 +82,9 @@ public class SncpRequest extends Request<SncpContext> {
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
this.serviceid = DLong.read(buffer); //16
|
||||
this.serviceid = Uint128.read(buffer); //16
|
||||
this.serviceVersion = buffer.getInt(); //4
|
||||
this.actionid = DLong.read(buffer); //16
|
||||
this.actionid = Uint128.read(buffer); //16
|
||||
buffer.get(addrBytes); //ipaddr //6
|
||||
this.bodyLength = buffer.getInt(); //4
|
||||
|
||||
@@ -159,11 +159,11 @@ public class SncpRequest extends Request<SncpContext> {
|
||||
return serviceVersion;
|
||||
}
|
||||
|
||||
public DLong getServiceid() {
|
||||
public Uint128 getServiceid() {
|
||||
return serviceid;
|
||||
}
|
||||
|
||||
public DLong getActionid() {
|
||||
public Uint128 getActionid() {
|
||||
return actionid;
|
||||
}
|
||||
|
||||
|
||||
@@ -90,19 +90,19 @@ public class SncpResponse extends Response<SncpContext, SncpRequest> {
|
||||
request.getActionid(), request.getTraceid(), this.addrBytes, this.addrPort, bodyLength, retcode);
|
||||
}
|
||||
|
||||
protected static void fillRespHeader(ByteArray buffer, long seqid, DLong serviceid, int serviceVersion,
|
||||
DLong actionid, String traceid, byte[] addrBytes, int addrPort, int bodyLength, int retcode) {
|
||||
protected static void fillRespHeader(ByteArray buffer, long seqid, Uint128 serviceid, int serviceVersion,
|
||||
Uint128 actionid, String traceid, byte[] addrBytes, int addrPort, int bodyLength, int retcode) {
|
||||
//---------------------head----------------------------------
|
||||
int offset = 0;
|
||||
buffer.putLong(offset, seqid);
|
||||
offset += 8;
|
||||
buffer.putChar(offset, (char) SncpRequest.HEADER_SIZE);
|
||||
offset += 2;
|
||||
DLong.write(buffer, offset, serviceid);
|
||||
Uint128.write(buffer, offset, serviceid);
|
||||
offset += 16;
|
||||
buffer.putInt(offset, serviceVersion);
|
||||
offset += 4;
|
||||
DLong.write(buffer, offset, actionid);
|
||||
Uint128.write(buffer, offset, actionid);
|
||||
offset += 16;
|
||||
buffer.put(offset, addrBytes);
|
||||
offset += addrBytes.length; //4
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.redkale.util.*;
|
||||
* @author zhangjx
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class SncpServer extends Server<DLong, SncpContext, SncpRequest, SncpResponse, SncpServlet> {
|
||||
public class SncpServer extends Server<Uint128, SncpContext, SncpRequest, SncpResponse, SncpServlet> {
|
||||
|
||||
private final AtomicInteger maxTypeLength = new AtomicInteger();
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ public abstract class SncpServlet extends Servlet<SncpContext, SncpRequest, Sncp
|
||||
return type;
|
||||
}
|
||||
|
||||
public abstract DLong getServiceid();
|
||||
public abstract Uint128 getServiceid();
|
||||
|
||||
protected ExecutorService getExecutor() {
|
||||
Thread thread = Thread.currentThread();
|
||||
|
||||
@@ -10,26 +10,26 @@ import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 16bytes数据结构
|
||||
* 注意: 为了提高性能, DLong中的bytes是直接返回, 不得对bytes的内容进行修改。
|
||||
* 注意: 为了提高性能, Uint128中的bytes是直接返回, 不得对bytes的内容进行修改。
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public final class DLong extends Number implements Comparable<DLong> {
|
||||
public final class Uint128 extends Number implements Comparable<Uint128> {
|
||||
|
||||
public static final DLong ZERO = new DLong(new byte[16]);
|
||||
public static final Uint128 ZERO = new Uint128(new byte[16]);
|
||||
|
||||
protected final byte[] value;
|
||||
|
||||
protected DLong(long v1, long v2) { //暂时不用
|
||||
protected Uint128(long v1, long v2) { //暂时不用
|
||||
this.value = new byte[]{(byte) (v1 >> 56), (byte) (v1 >> 48), (byte) (v1 >> 40), (byte) (v1 >> 32),
|
||||
(byte) (v1 >> 24), (byte) (v1 >> 16), (byte) (v1 >> 8), (byte) v1, (byte) (v2 >> 56), (byte) (v2 >> 48), (byte) (v2 >> 40), (byte) (v2 >> 32),
|
||||
(byte) (v2 >> 24), (byte) (v2 >> 16), (byte) (v2 >> 8), (byte) v2};
|
||||
}
|
||||
|
||||
protected DLong(byte[] bytes) {
|
||||
protected Uint128(byte[] bytes) {
|
||||
if (bytes == null || bytes.length != 16) {
|
||||
throw new NumberFormatException("Not 16 length bytes");
|
||||
}
|
||||
@@ -44,27 +44,27 @@ public final class DLong extends Number implements Comparable<DLong> {
|
||||
return value;
|
||||
}
|
||||
|
||||
public static DLong create(byte[] bytes) {
|
||||
return new DLong(bytes);
|
||||
public static Uint128 create(byte[] bytes) {
|
||||
return new Uint128(bytes);
|
||||
}
|
||||
|
||||
public static DLong read(ByteBuffer buffer) {
|
||||
public static Uint128 read(ByteBuffer buffer) {
|
||||
byte[] bs = new byte[16];
|
||||
buffer.get(bs);
|
||||
return new DLong(bs);
|
||||
return new Uint128(bs);
|
||||
}
|
||||
|
||||
public static ByteBuffer write(ByteBuffer buffer, DLong dlong) {
|
||||
public static ByteBuffer write(ByteBuffer buffer, Uint128 dlong) {
|
||||
buffer.put(dlong.value);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public static ByteArray write(ByteArray array, DLong dlong) {
|
||||
public static ByteArray write(ByteArray array, Uint128 dlong) {
|
||||
array.put(dlong.value);
|
||||
return array;
|
||||
}
|
||||
|
||||
public static ByteArray write(ByteArray array, int offset, DLong dlong) {
|
||||
public static ByteArray write(ByteArray array, int offset, Uint128 dlong) {
|
||||
array.put(offset, dlong.value);
|
||||
return array;
|
||||
}
|
||||
@@ -81,7 +81,7 @@ public final class DLong extends Number implements Comparable<DLong> {
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final DLong other = (DLong) obj;
|
||||
final Uint128 other = (Uint128) obj;
|
||||
return Arrays.equals(this.value, other.value);
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ public final class DLong extends Number implements Comparable<DLong> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(DLong o) {
|
||||
public int compareTo(Uint128 o) {
|
||||
if (o == null) {
|
||||
return 1;
|
||||
}
|
||||
Reference in New Issue
Block a user