diff --git a/src/main/java/org/redkale/convert/ConvertFactory.java b/src/main/java/org/redkale/convert/ConvertFactory.java index 1a94a1b53..47c4c3618 100644 --- a/src/main/java/org/redkale/convert/ConvertFactory.java +++ b/src/main/java/org/redkale/convert/ConvertFactory.java @@ -116,7 +116,7 @@ public abstract class ConvertFactory { 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); diff --git a/src/main/java/org/redkale/convert/ext/DLongSimpledCoder.java b/src/main/java/org/redkale/convert/ext/Uint128SimpledCoder.java similarity index 62% rename from src/main/java/org/redkale/convert/ext/DLongSimpledCoder.java rename to src/main/java/org/redkale/convert/ext/Uint128SimpledCoder.java index cd344307f..28169923b 100644 --- a/src/main/java/org/redkale/convert/ext/DLongSimpledCoder.java +++ b/src/main/java/org/redkale/convert/ext/Uint128SimpledCoder.java @@ -19,15 +19,15 @@ import org.redkale.util.*; * @param Reader输入的子类型 * @param Writer输出的子类型 */ -public final class DLongSimpledCoder extends SimpledCoder { +public final class Uint128SimpledCoder extends SimpledCoder { 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 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 Reader输入的子类型 * @param Writer输出的子类型 */ - public static class DLongJsonSimpledCoder extends SimpledCoder { + public static class Uint128JsonSimpledCoder extends SimpledCoder { - 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 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)); } } } diff --git a/src/main/java/org/redkale/convert/json/JsonFactory.java b/src/main/java/org/redkale/convert/json/JsonFactory.java index 1e05c70f1..f86214712 100644 --- a/src/main/java/org/redkale/convert/json/JsonFactory.java +++ b/src/main/java/org/redkale/convert/json/JsonFactory.java @@ -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 { 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); diff --git a/src/main/java/org/redkale/net/sncp/Sncp.java b/src/main/java/org/redkale/net/sncp/Sncp.java index 0163eda0a..77aebe331 100644 --- a/src/main/java/org/redkale/net/sncp/Sncp.java +++ b/src/main/java/org/redkale/net/sncp/Sncp.java @@ -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) { diff --git a/src/main/java/org/redkale/net/sncp/SncpClient.java b/src/main/java/org/redkale/net/sncp/SncpClient.java index 6fbc33502..4b3263fe7 100644 --- a/src/main/java/org/redkale/net/sncp/SncpClient.java +++ b/src/main/java/org/redkale/net/sncp/SncpClient.java @@ -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 parseMethod(final Class serviceClass) { final List list = new ArrayList<>(); final List multis = new ArrayList<>(); - final Map actionids = new HashMap<>(); + final Map 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 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; diff --git a/src/main/java/org/redkale/net/sncp/SncpDispatcherServlet.java b/src/main/java/org/redkale/net/sncp/SncpDispatcherServlet.java index 1925fcbb5..b22c306bb 100644 --- a/src/main/java/org/redkale/net/sncp/SncpDispatcherServlet.java +++ b/src/main/java/org/redkale/net/sncp/SncpDispatcherServlet.java @@ -17,12 +17,12 @@ import org.redkale.util.*; * * @author zhangjx */ -public class SncpDispatcherServlet extends DispatcherServlet { +public class SncpDispatcherServlet extends DispatcherServlet { 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) { diff --git a/src/main/java/org/redkale/net/sncp/SncpDynServlet.java b/src/main/java/org/redkale/net/sncp/SncpDynServlet.java index 9f65968ab..bff6e056b 100644 --- a/src/main/java/org/redkale/net/sncp/SncpDynServlet.java +++ b/src/main/java/org/redkale/net/sncp/SncpDynServlet.java @@ -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 actions = new HashMap<>(); + private final HashMap 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 actionids = new HashSet<>(); + Set 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('.', '/'); diff --git a/src/main/java/org/redkale/net/sncp/SncpRequest.java b/src/main/java/org/redkale/net/sncp/SncpRequest.java index b6fa6ad47..746bb1db4 100644 --- a/src/main/java/org/redkale/net/sncp/SncpRequest.java +++ b/src/main/java/org/redkale/net/sncp/SncpRequest.java @@ -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 { 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 { } 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 { return serviceVersion; } - public DLong getServiceid() { + public Uint128 getServiceid() { return serviceid; } - public DLong getActionid() { + public Uint128 getActionid() { return actionid; } diff --git a/src/main/java/org/redkale/net/sncp/SncpResponse.java b/src/main/java/org/redkale/net/sncp/SncpResponse.java index f92285361..5c50126e8 100644 --- a/src/main/java/org/redkale/net/sncp/SncpResponse.java +++ b/src/main/java/org/redkale/net/sncp/SncpResponse.java @@ -90,19 +90,19 @@ public class SncpResponse extends Response { 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 diff --git a/src/main/java/org/redkale/net/sncp/SncpServer.java b/src/main/java/org/redkale/net/sncp/SncpServer.java index cabf900c7..a48365d7c 100644 --- a/src/main/java/org/redkale/net/sncp/SncpServer.java +++ b/src/main/java/org/redkale/net/sncp/SncpServer.java @@ -24,7 +24,7 @@ import org.redkale.util.*; * @author zhangjx */ @SuppressWarnings("unchecked") -public class SncpServer extends Server { +public class SncpServer extends Server { private final AtomicInteger maxTypeLength = new AtomicInteger(); diff --git a/src/main/java/org/redkale/net/sncp/SncpServlet.java b/src/main/java/org/redkale/net/sncp/SncpServlet.java index 41e9c2283..18b8b22b4 100644 --- a/src/main/java/org/redkale/net/sncp/SncpServlet.java +++ b/src/main/java/org/redkale/net/sncp/SncpServlet.java @@ -44,7 +44,7 @@ public abstract class SncpServlet extends Servlet * 详情见: https://redkale.org * * @author zhangjx */ -public final class DLong extends Number implements Comparable { +public final class Uint128 extends Number implements Comparable { - 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 { 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 { 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 { } @Override - public int compareTo(DLong o) { + public int compareTo(Uint128 o) { if (o == null) { return 1; }