This commit is contained in:
@@ -80,7 +80,7 @@ public abstract class Factory<R extends Reader, W extends Writer> {
|
||||
this.register(java.util.Date.class, DateSimpledCoder.instance);
|
||||
this.register(BigInteger.class, BigIntegerSimpledCoder.instance);
|
||||
this.register(InetAddress.class, InetAddressSimpledCoder.instance);
|
||||
this.register(TwoLong.class, TwoLongSimpledCoder.instance);
|
||||
this.register(DLong.class, DLongSimpledCoder.instance);
|
||||
this.register(Class.class, TypeSimpledCoder.instance);
|
||||
this.register(InetSocketAddress.class, InetSocketAddressSimpledCoder.instance);
|
||||
this.register(InetSocketAddress.class, InetSocketAddressSimpledCoder.instance);
|
||||
|
||||
@@ -8,7 +8,7 @@ package com.wentch.redkale.convert.ext;
|
||||
import com.wentch.redkale.convert.Reader;
|
||||
import com.wentch.redkale.convert.Writer;
|
||||
import com.wentch.redkale.convert.SimpledCoder;
|
||||
import com.wentch.redkale.util.TwoLong;
|
||||
import com.wentch.redkale.util.DLong;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -16,12 +16,12 @@ import com.wentch.redkale.util.TwoLong;
|
||||
* @param <R>
|
||||
* @param <W>
|
||||
*/
|
||||
public final class TwoLongSimpledCoder<R extends Reader, W extends Writer> extends SimpledCoder<R, W, TwoLong> {
|
||||
public final class DLongSimpledCoder<R extends Reader, W extends Writer> extends SimpledCoder<R, W, DLong> {
|
||||
|
||||
public static final TwoLongSimpledCoder instance = new TwoLongSimpledCoder();
|
||||
public static final DLongSimpledCoder instance = new DLongSimpledCoder();
|
||||
|
||||
@Override
|
||||
public void convertTo(final W out, final TwoLong value) {
|
||||
public void convertTo(final W out, final DLong value) {
|
||||
if (value == null) {
|
||||
out.writeNull();
|
||||
} else {
|
||||
@@ -30,11 +30,11 @@ public final class TwoLongSimpledCoder<R extends Reader, W extends Writer> exten
|
||||
}
|
||||
|
||||
@Override
|
||||
public TwoLong convertFrom(R in) {
|
||||
public DLong convertFrom(R in) {
|
||||
String str = in.readString();
|
||||
if (str == null) return null;
|
||||
int pos = str.indexOf('_');
|
||||
return new TwoLong(Long.parseLong(str.substring(0, pos)), Long.parseLong(str.substring(pos + 1)));
|
||||
return new DLong(Long.parseLong(str.substring(0, pos)), Long.parseLong(str.substring(pos + 1)));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -46,8 +46,8 @@ public abstract class Sncp {
|
||||
return (rs < Integer.MAX_VALUE) ? rs | 0xF00000000L : rs;
|
||||
}
|
||||
|
||||
public static TwoLong hash(final java.lang.reflect.Method method) {
|
||||
if (method == null) return new TwoLong(-1L, -1L);
|
||||
public static DLong hash(final java.lang.reflect.Method method) {
|
||||
if (method == null) return new DLong(-1L, -1L);
|
||||
long rs1 = hash(method.getName());
|
||||
if (rs1 < Integer.MAX_VALUE) {
|
||||
rs1 |= (method.getParameterCount() + 0L) << 32;
|
||||
@@ -58,7 +58,7 @@ public abstract class Sncp {
|
||||
rs2 |= (method.getParameterCount() + 0L) << 32;
|
||||
}
|
||||
rs2 = (rs2 < Integer.MAX_VALUE) ? rs2 | 0xF00000000L : rs2;
|
||||
return new TwoLong(rs1, rs2);
|
||||
return new DLong(rs1, rs2);
|
||||
}
|
||||
|
||||
private static String wrapName(final java.lang.reflect.Method method) {
|
||||
|
||||
@@ -28,7 +28,7 @@ public final class SncpClient {
|
||||
|
||||
protected static final class SncpAction {
|
||||
|
||||
protected final TwoLong actionid;
|
||||
protected final DLong actionid;
|
||||
|
||||
protected final Method method;
|
||||
|
||||
@@ -38,7 +38,7 @@ public final class SncpClient {
|
||||
|
||||
protected final boolean async;
|
||||
|
||||
public SncpAction(Method method, TwoLong actionid) {
|
||||
public SncpAction(Method method, DLong actionid) {
|
||||
this.actionid = actionid;
|
||||
Type rt = method.getGenericReturnType();
|
||||
if (rt instanceof TypeVariable) {
|
||||
@@ -69,7 +69,7 @@ public final class SncpClient {
|
||||
this.serviceid = Sncp.hash(serviceClass);
|
||||
final List<SncpAction> methodens = new ArrayList<>();
|
||||
//------------------------------------------------------------------------------
|
||||
Set<TwoLong> actionids = new HashSet<>();
|
||||
Set<DLong> actionids = new HashSet<>();
|
||||
for (java.lang.reflect.Method method : serviceClass.getDeclaredMethods()) {
|
||||
if (method.isSynthetic()) continue;
|
||||
final int mod = method.getModifiers();
|
||||
@@ -116,7 +116,7 @@ public final class SncpClient {
|
||||
return convert.convertFrom(actions[index].resultTypes, send(convert, transport, index, params));
|
||||
}
|
||||
|
||||
private void fillHeader(ByteBuffer buffer, long seqid, TwoLong actionid, int frameCount, int frameIndex, int bodyLength) {
|
||||
private void fillHeader(ByteBuffer buffer, long seqid, DLong actionid, int frameCount, int frameIndex, int bodyLength) {
|
||||
//---------------------head----------------------------------
|
||||
buffer.putLong(seqid); //序列号
|
||||
buffer.putChar((char) HEADER_SIZE); //header长度
|
||||
@@ -140,7 +140,7 @@ public final class SncpClient {
|
||||
}
|
||||
final SncpAction action = actions[index];
|
||||
final long seqid = System.nanoTime();
|
||||
final TwoLong actionid = action.actionid;
|
||||
final DLong actionid = action.actionid;
|
||||
final ByteBuffer buffer = transport.pollBuffer();
|
||||
final AsyncConnection conn = transport.pollConnection();
|
||||
final int readto = conn.getReadTimeoutSecond();
|
||||
|
||||
@@ -30,14 +30,14 @@ public class SncpDynServlet extends SncpServlet {
|
||||
|
||||
private final long serviceid;
|
||||
|
||||
private final HashMap<TwoLong, SncpServletAction> actions = new HashMap<>();
|
||||
private final HashMap<DLong, SncpServletAction> actions = new HashMap<>();
|
||||
|
||||
public SncpDynServlet(final BsonConvert convert, final String serviceName, final Service service, final AnyValue conf) {
|
||||
this.conf = conf;
|
||||
final Class serviceClass = service.getClass();
|
||||
this.nameid = Sncp.hash(serviceName);
|
||||
this.serviceid = Sncp.hash(serviceClass);
|
||||
Set<TwoLong> actionids = new HashSet<>();
|
||||
Set<DLong> actionids = new HashSet<>();
|
||||
for (java.lang.reflect.Method method : serviceClass.getMethods()) {
|
||||
if (method.isSynthetic()) continue;
|
||||
if (Modifier.isStatic(method.getModifiers())) continue;
|
||||
@@ -48,7 +48,7 @@ public class SncpDynServlet extends SncpServlet {
|
||||
if (method.getName().equals("init") || method.getName().equals("destroy")) continue;
|
||||
Method onMethod = getOnMethod(serviceClass, method);
|
||||
if (onMethod != null) method = onMethod;
|
||||
final TwoLong actionid = Sncp.hash(method);
|
||||
final DLong actionid = Sncp.hash(method);
|
||||
SncpServletAction action = SncpServletAction.create(service, actionid, method);
|
||||
action.convert = convert;
|
||||
if (actionids.contains(actionid)) {
|
||||
@@ -132,7 +132,7 @@ public class SncpDynServlet extends SncpServlet {
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static SncpServletAction create(final Service service, final TwoLong actionid, final Method method) {
|
||||
public static SncpServletAction create(final Service service, final DLong actionid, final Method method) {
|
||||
final Class serviceClass = service.getClass();
|
||||
final String supDynName = SncpServletAction.class.getName().replace('.', '/');
|
||||
final String serviceName = serviceClass.getName().replace('.', '/');
|
||||
|
||||
@@ -31,7 +31,7 @@ public final class SncpRequest extends Request {
|
||||
|
||||
private long serviceid;
|
||||
|
||||
private TwoLong actionid;
|
||||
private DLong actionid;
|
||||
|
||||
private int bodylength;
|
||||
|
||||
@@ -60,7 +60,7 @@ public final class SncpRequest extends Request {
|
||||
}
|
||||
this.serviceid = buffer.getLong();
|
||||
this.nameid = buffer.getLong();
|
||||
this.actionid = new TwoLong(buffer.getLong(), buffer.getLong());
|
||||
this.actionid = new DLong(buffer.getLong(), buffer.getLong());
|
||||
this.framecount = buffer.get();
|
||||
this.frameindex = buffer.get();
|
||||
if (buffer.getInt() != 0) {
|
||||
@@ -158,7 +158,7 @@ public final class SncpRequest extends Request {
|
||||
return nameid;
|
||||
}
|
||||
|
||||
public TwoLong getActionid() {
|
||||
public DLong getActionid() {
|
||||
return actionid;
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ public final class SncpResponse extends Response<SncpRequest> {
|
||||
buffer.putChar((char) SncpRequest.HEADER_SIZE);
|
||||
buffer.putLong(request.getServiceid());
|
||||
buffer.putLong(request.getNameid());
|
||||
TwoLong actionid = request.getActionid();
|
||||
DLong actionid = request.getActionid();
|
||||
buffer.putLong(actionid.getFirst());
|
||||
buffer.putLong(actionid.getSecond());
|
||||
buffer.put((byte) frameCount); // frame count
|
||||
|
||||
@@ -9,13 +9,13 @@ package com.wentch.redkale.util;
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public final class TwoLong extends Number implements Comparable<TwoLong> {
|
||||
public final class DLong extends Number implements Comparable<DLong> {
|
||||
|
||||
private long first;
|
||||
private final long first;
|
||||
|
||||
private long second;
|
||||
private final long second;
|
||||
|
||||
public TwoLong(long one, long two) {
|
||||
public DLong(long one, long two) {
|
||||
this.first = one;
|
||||
this.second = two;
|
||||
}
|
||||
@@ -41,7 +41,7 @@ public final class TwoLong extends Number implements Comparable<TwoLong> {
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) return false;
|
||||
if (getClass() != obj.getClass()) return false;
|
||||
final TwoLong other = (TwoLong) obj;
|
||||
final DLong other = (DLong) obj;
|
||||
return (this.first == other.first && this.second == other.second);
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public final class TwoLong extends Number implements Comparable<TwoLong> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(TwoLong o) {
|
||||
public int compareTo(DLong o) {
|
||||
return (int) (first == o.first ? (second - o.second) : (first - o.first));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user