This commit is contained in:
地平线
2015-06-06 19:30:13 +08:00
parent 0ed4e01edc
commit 397eea2b72
8 changed files with 29 additions and 29 deletions

View File

@@ -80,7 +80,7 @@ public abstract class Factory<R extends Reader, W extends Writer> {
this.register(java.util.Date.class, DateSimpledCoder.instance); this.register(java.util.Date.class, DateSimpledCoder.instance);
this.register(BigInteger.class, BigIntegerSimpledCoder.instance); this.register(BigInteger.class, BigIntegerSimpledCoder.instance);
this.register(InetAddress.class, InetAddressSimpledCoder.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(Class.class, TypeSimpledCoder.instance);
this.register(InetSocketAddress.class, InetSocketAddressSimpledCoder.instance); this.register(InetSocketAddress.class, InetSocketAddressSimpledCoder.instance);
this.register(InetSocketAddress.class, InetSocketAddressSimpledCoder.instance); this.register(InetSocketAddress.class, InetSocketAddressSimpledCoder.instance);

View File

@@ -8,7 +8,7 @@ package com.wentch.redkale.convert.ext;
import com.wentch.redkale.convert.Reader; import com.wentch.redkale.convert.Reader;
import com.wentch.redkale.convert.Writer; import com.wentch.redkale.convert.Writer;
import com.wentch.redkale.convert.SimpledCoder; 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 <R>
* @param <W> * @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 @Override
public void convertTo(final W out, final TwoLong value) { public void convertTo(final W out, final DLong value) {
if (value == null) { if (value == null) {
out.writeNull(); out.writeNull();
} else { } else {
@@ -30,11 +30,11 @@ public final class TwoLongSimpledCoder<R extends Reader, W extends Writer> exten
} }
@Override @Override
public TwoLong convertFrom(R in) { public DLong convertFrom(R in) {
String str = in.readString(); String str = in.readString();
if (str == null) return null; if (str == null) return null;
int pos = str.indexOf('_'); 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)));
} }
} }

View File

@@ -46,8 +46,8 @@ public abstract class Sncp {
return (rs < Integer.MAX_VALUE) ? rs | 0xF00000000L : rs; return (rs < Integer.MAX_VALUE) ? rs | 0xF00000000L : rs;
} }
public static TwoLong hash(final java.lang.reflect.Method method) { public static DLong hash(final java.lang.reflect.Method method) {
if (method == null) return new TwoLong(-1L, -1L); if (method == null) return new DLong(-1L, -1L);
long rs1 = hash(method.getName()); long rs1 = hash(method.getName());
if (rs1 < Integer.MAX_VALUE) { if (rs1 < Integer.MAX_VALUE) {
rs1 |= (method.getParameterCount() + 0L) << 32; rs1 |= (method.getParameterCount() + 0L) << 32;
@@ -58,7 +58,7 @@ public abstract class Sncp {
rs2 |= (method.getParameterCount() + 0L) << 32; rs2 |= (method.getParameterCount() + 0L) << 32;
} }
rs2 = (rs2 < Integer.MAX_VALUE) ? rs2 | 0xF00000000L : rs2; 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) { private static String wrapName(final java.lang.reflect.Method method) {

View File

@@ -28,7 +28,7 @@ public final class SncpClient {
protected static final class SncpAction { protected static final class SncpAction {
protected final TwoLong actionid; protected final DLong actionid;
protected final Method method; protected final Method method;
@@ -38,7 +38,7 @@ public final class SncpClient {
protected final boolean async; protected final boolean async;
public SncpAction(Method method, TwoLong actionid) { public SncpAction(Method method, DLong actionid) {
this.actionid = actionid; this.actionid = actionid;
Type rt = method.getGenericReturnType(); Type rt = method.getGenericReturnType();
if (rt instanceof TypeVariable) { if (rt instanceof TypeVariable) {
@@ -69,7 +69,7 @@ public final class SncpClient {
this.serviceid = Sncp.hash(serviceClass); this.serviceid = Sncp.hash(serviceClass);
final List<SncpAction> methodens = new ArrayList<>(); final List<SncpAction> methodens = new ArrayList<>();
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
Set<TwoLong> actionids = new HashSet<>(); Set<DLong> actionids = new HashSet<>();
for (java.lang.reflect.Method method : serviceClass.getDeclaredMethods()) { for (java.lang.reflect.Method method : serviceClass.getDeclaredMethods()) {
if (method.isSynthetic()) continue; if (method.isSynthetic()) continue;
final int mod = method.getModifiers(); final int mod = method.getModifiers();
@@ -116,7 +116,7 @@ public final class SncpClient {
return convert.convertFrom(actions[index].resultTypes, send(convert, transport, index, params)); 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---------------------------------- //---------------------head----------------------------------
buffer.putLong(seqid); //序列号 buffer.putLong(seqid); //序列号
buffer.putChar((char) HEADER_SIZE); //header长度 buffer.putChar((char) HEADER_SIZE); //header长度
@@ -140,7 +140,7 @@ public final class SncpClient {
} }
final SncpAction action = actions[index]; final SncpAction action = actions[index];
final long seqid = System.nanoTime(); final long seqid = System.nanoTime();
final TwoLong actionid = action.actionid; final DLong actionid = action.actionid;
final ByteBuffer buffer = transport.pollBuffer(); final ByteBuffer buffer = transport.pollBuffer();
final AsyncConnection conn = transport.pollConnection(); final AsyncConnection conn = transport.pollConnection();
final int readto = conn.getReadTimeoutSecond(); final int readto = conn.getReadTimeoutSecond();

View File

@@ -30,14 +30,14 @@ public class SncpDynServlet extends SncpServlet {
private final long serviceid; 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) { public SncpDynServlet(final BsonConvert convert, final String serviceName, final Service service, final AnyValue conf) {
this.conf = conf; this.conf = conf;
final Class serviceClass = service.getClass(); final Class serviceClass = service.getClass();
this.nameid = Sncp.hash(serviceName); this.nameid = Sncp.hash(serviceName);
this.serviceid = Sncp.hash(serviceClass); this.serviceid = Sncp.hash(serviceClass);
Set<TwoLong> actionids = new HashSet<>(); Set<DLong> actionids = new HashSet<>();
for (java.lang.reflect.Method method : serviceClass.getMethods()) { for (java.lang.reflect.Method method : serviceClass.getMethods()) {
if (method.isSynthetic()) continue; if (method.isSynthetic()) continue;
if (Modifier.isStatic(method.getModifiers())) 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; if (method.getName().equals("init") || method.getName().equals("destroy")) continue;
Method onMethod = getOnMethod(serviceClass, method); Method onMethod = getOnMethod(serviceClass, method);
if (onMethod != null) method = onMethod; if (onMethod != null) method = onMethod;
final TwoLong actionid = Sncp.hash(method); final DLong actionid = Sncp.hash(method);
SncpServletAction action = SncpServletAction.create(service, actionid, method); SncpServletAction action = SncpServletAction.create(service, actionid, method);
action.convert = convert; action.convert = convert;
if (actionids.contains(actionid)) { if (actionids.contains(actionid)) {
@@ -132,7 +132,7 @@ public class SncpDynServlet extends SncpServlet {
* @return * @return
*/ */
@SuppressWarnings("unchecked") @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 Class serviceClass = service.getClass();
final String supDynName = SncpServletAction.class.getName().replace('.', '/'); final String supDynName = SncpServletAction.class.getName().replace('.', '/');
final String serviceName = serviceClass.getName().replace('.', '/'); final String serviceName = serviceClass.getName().replace('.', '/');

View File

@@ -31,7 +31,7 @@ public final class SncpRequest extends Request {
private long serviceid; private long serviceid;
private TwoLong actionid; private DLong actionid;
private int bodylength; private int bodylength;
@@ -60,7 +60,7 @@ public final class SncpRequest extends Request {
} }
this.serviceid = buffer.getLong(); this.serviceid = buffer.getLong();
this.nameid = 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.framecount = buffer.get();
this.frameindex = buffer.get(); this.frameindex = buffer.get();
if (buffer.getInt() != 0) { if (buffer.getInt() != 0) {
@@ -158,7 +158,7 @@ public final class SncpRequest extends Request {
return nameid; return nameid;
} }
public TwoLong getActionid() { public DLong getActionid() {
return actionid; return actionid;
} }

View File

@@ -66,7 +66,7 @@ public final class SncpResponse extends Response<SncpRequest> {
buffer.putChar((char) SncpRequest.HEADER_SIZE); buffer.putChar((char) SncpRequest.HEADER_SIZE);
buffer.putLong(request.getServiceid()); buffer.putLong(request.getServiceid());
buffer.putLong(request.getNameid()); buffer.putLong(request.getNameid());
TwoLong actionid = request.getActionid(); DLong actionid = request.getActionid();
buffer.putLong(actionid.getFirst()); buffer.putLong(actionid.getFirst());
buffer.putLong(actionid.getSecond()); buffer.putLong(actionid.getSecond());
buffer.put((byte) frameCount); // frame count buffer.put((byte) frameCount); // frame count

View File

@@ -9,13 +9,13 @@ package com.wentch.redkale.util;
* *
* @author zhangjx * @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.first = one;
this.second = two; this.second = two;
} }
@@ -41,7 +41,7 @@ public final class TwoLong extends Number implements Comparable<TwoLong> {
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj == null) return false; if (obj == null) return false;
if (getClass() != obj.getClass()) 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); return (this.first == other.first && this.second == other.second);
} }
@@ -71,7 +71,7 @@ public final class TwoLong extends Number implements Comparable<TwoLong> {
} }
@Override @Override
public int compareTo(TwoLong o) { public int compareTo(DLong o) {
return (int) (first == o.first ? (second - o.second) : (first - o.first)); return (int) (first == o.first ? (second - o.second) : (first - o.first));
} }