优化变量名

This commit is contained in:
Redkale
2022-12-12 19:24:15 +08:00
parent 348b27365b
commit bab765a8f8
3 changed files with 36 additions and 44 deletions

View File

@@ -52,7 +52,7 @@ public final class SncpClient {
protected final DLong serviceid; protected final DLong serviceid;
protected final int serviceversion; protected final int serviceVersion;
protected final SncpAction[] actions; protected final SncpAction[] actions;
@@ -83,7 +83,7 @@ public final class SncpClient {
Class<?> tn = serviceTypeOrImplClass; Class<?> tn = serviceTypeOrImplClass;
Version ver = tn.getAnnotation(Version.class); Version ver = tn.getAnnotation(Version.class);
this.serviceClass = serviceClass; this.serviceClass = serviceClass;
this.serviceversion = ver == null ? 0 : ver.value(); this.serviceVersion = ver == null ? 0 : ver.value();
this.clientSncpAddress = clientSncpAddress; this.clientSncpAddress = clientSncpAddress;
this.name = serviceName; this.name = serviceName;
tn = ResourceFactory.getResourceType(tn); tn = ResourceFactory.getResourceType(tn);
@@ -120,8 +120,8 @@ public final class SncpClient {
return serviceid; return serviceid;
} }
public int getServiceversion() { public int getServiceVersion() {
return serviceversion; return serviceVersion;
} }
public int getActionCount() { public int getActionCount() {
@@ -148,7 +148,7 @@ public final class SncpClient {
public String toString() { public String toString() {
String service = serviceClass.getName(); String service = serviceClass.getName();
if (remote) service = service.replace("DynLocalService", "DynRemoteService"); if (remote) service = service.replace("DynLocalService", "DynRemoteService");
return this.getClass().getSimpleName() + "(service = " + service + ", serviceid = " + serviceid + ", serviceversion = " + serviceversion + ", name = '" + name return this.getClass().getSimpleName() + "(service = " + service + ", serviceid = " + serviceid + ", serviceVersion = " + serviceVersion + ", name = '" + name
+ "', address = " + (clientSncpAddress == null ? "" : (clientSncpAddress.getHostString() + ":" + clientSncpAddress.getPort())) + "', address = " + (clientSncpAddress == null ? "" : (clientSncpAddress.getHostString() + ":" + clientSncpAddress.getPort()))
+ ", actions.size = " + actions.length + ")"; + ", actions.size = " + actions.length + ")";
} }
@@ -160,7 +160,7 @@ public final class SncpClient {
} }
String service = serviceClass.getAnnotation(SncpDyn.class) ==null? serviceClass.getName() : serviceClass.getSuperclass().getSimpleName(); String service = serviceClass.getAnnotation(SncpDyn.class) ==null? serviceClass.getName() : serviceClass.getSuperclass().getSimpleName();
if (remote) service = service.replace("DynLocalService", "DynRemoteService"); if (remote) service = service.replace("DynLocalService", "DynRemoteService");
return service + "(name = '" + name + "', serviceid = " + serviceid + ", serviceversion = " + serviceversion return service + "(name = '" + name + "', serviceid = " + serviceid + ", serviceVersion = " + serviceVersion
+ ", clientaddr = " + (clientSncpAddress == null ? "" : (clientSncpAddress.getHostString() + ":" + clientSncpAddress.getPort())) + ", clientaddr = " + (clientSncpAddress == null ? "" : (clientSncpAddress.getHostString() + ":" + clientSncpAddress.getPort()))
+ ((remoteGroups == null || remoteGroups.isEmpty()) ? "" : ", remoteGroups = " + remoteGroups) + ((remoteGroups == null || remoteGroups.isEmpty()) ? "" : ", remoteGroups = " + remoteGroups)
+ (remoteGroupTransport == null ? "" : ", remoteGroupTransport = " + Arrays.toString(remoteGroupTransport.getRemoteAddresses())) + (remoteGroupTransport == null ? "" : ", remoteGroupTransport = " + Arrays.toString(remoteGroupTransport.getRemoteAddresses()))
@@ -460,7 +460,7 @@ public final class SncpClient {
DLong rserviceid = DLong.read(buffer); DLong rserviceid = DLong.read(buffer);
if (!rserviceid.equals(this.serviceid)) throw new RuntimeException("sncp(" + action.method + ") response.serviceid = " + serviceid + ", but request.serviceid =" + rserviceid); if (!rserviceid.equals(this.serviceid)) throw new RuntimeException("sncp(" + action.method + ") response.serviceid = " + serviceid + ", but request.serviceid =" + rserviceid);
int version = buffer.getInt(); int version = buffer.getInt();
if (version != this.serviceversion) throw new RuntimeException("sncp(" + action.method + ") response.serviceversion = " + serviceversion + ", but request.serviceversion =" + version); if (version != this.serviceVersion) throw new RuntimeException("sncp(" + action.method + ") response.serviceVersion = " + serviceVersion + ", but request.serviceVersion =" + version);
DLong raction = DLong.read(buffer); DLong raction = DLong.read(buffer);
DLong actid = action.actionid; DLong actid = action.actionid;
if (!actid.equals(raction)) throw new RuntimeException("sncp(" + action.method + ") response.actionid = " + action.actionid + ", but request.actionid =(" + raction + ")"); if (!actid.equals(raction)) throw new RuntimeException("sncp(" + action.method + ") response.actionid = " + action.actionid + ", but request.actionid =(" + raction + ")");
@@ -477,7 +477,7 @@ public final class SncpClient {
offset += 2; offset += 2;
DLong.write(buffer, offset, this.serviceid); DLong.write(buffer, offset, this.serviceid);
offset += 16; offset += 16;
buffer.putInt(offset, this.serviceversion); buffer.putInt(offset, this.serviceVersion);
offset += 4; offset += 4;
DLong.write(buffer, offset, actionid); DLong.write(buffer, offset, actionid);
offset += 16; offset += 16;
@@ -498,7 +498,7 @@ public final class SncpClient {
// buffer.putLong(seqid); //序列号 // buffer.putLong(seqid); //序列号
// buffer.putChar((char) HEADER_SIZE); //header长度 // buffer.putChar((char) HEADER_SIZE); //header长度
// DLong.write(buffer, this.serviceid); // DLong.write(buffer, this.serviceid);
// buffer.putInt(this.serviceversion); // buffer.putInt(this.serviceVersion);
// DLong.write(buffer, actionid); // DLong.write(buffer, actionid);
// buffer.put(addrBytes); // buffer.put(addrBytes);
// buffer.putChar((char) this.addrPort); // buffer.putChar((char) this.addrPort);

View File

@@ -40,21 +40,21 @@ public class SncpRequest extends Request<SncpContext> {
protected int readState = READ_STATE_ROUTE; protected int readState = READ_STATE_ROUTE;
private int serviceversion; private int serviceVersion;
private DLong serviceid; private DLong serviceid;
private DLong actionid; private DLong actionid;
private int bodylength; private int bodyLength;
private int bodyoffset; private int bodyOffset;
private boolean ping; private boolean ping;
private byte[] body; private byte[] body;
private byte[] addrbytes = new byte[6]; private final byte[] addrBytes = new byte[6];
protected SncpRequest(SncpContext context) { protected SncpRequest(SncpContext context) {
super(context); super(context);
@@ -78,38 +78,30 @@ public class SncpRequest extends Request<SncpContext> {
return -1; return -1;
} }
this.serviceid = DLong.read(buffer); //16 this.serviceid = DLong.read(buffer); //16
this.serviceversion = buffer.getInt(); //4 this.serviceVersion = buffer.getInt(); //4
this.actionid = DLong.read(buffer); //16 this.actionid = DLong.read(buffer); //16
buffer.get(addrbytes); //ipaddr //6 buffer.get(addrBytes); //ipaddr //6
this.bodylength = buffer.getInt(); //4 this.bodyLength = buffer.getInt(); //4
if (buffer.getInt() != 0) { //4 if (buffer.getInt() != 0) { //4
if (context.getLogger().isLoggable(Level.FINEST)) context.getLogger().finest("sncp buffer header.retcode not 0"); if (context.getLogger().isLoggable(Level.FINEST)) context.getLogger().finest("sncp buffer header.retcode not 0");
return -1; return -1;
} }
this.body = new byte[this.bodylength]; this.body = new byte[this.bodyLength];
this.readState = READ_STATE_BODY; this.readState = READ_STATE_BODY;
} }
//---------------------body---------------------------------- //---------------------body----------------------------------
if (this.readState == READ_STATE_BODY) { if (this.readState == READ_STATE_BODY) {
int len = Math.min(this.bodylength, buffer.remaining()); int len = Math.min(this.bodyLength, buffer.remaining());
buffer.get(body, 0, len); buffer.get(body, 0, len);
this.bodyoffset = len; this.bodyOffset = len;
int rs = bodylength - len; int rs = bodyLength - len;
if (rs == 0) this.readState = READ_STATE_END; if (rs == 0) this.readState = READ_STATE_END;
return rs; return rs;
} }
return 0; return 0;
} }
// @Override
// protected int readBody(ByteBuffer buffer, int length) {
// final int framelen = buffer.remaining();
// int len = Math.min(framelen, length);
// buffer.get(this.body, this.bodyoffset, len);
// this.bodyoffset += len;
// return len;
// }
@Override @Override
protected void prepare() { protected void prepare() {
this.keepAlive = true; this.keepAlive = true;
@@ -122,9 +114,9 @@ public class SncpRequest extends Request<SncpContext> {
@Override @Override
public String toString() { public String toString() {
return SncpRequest.class.getSimpleName() + "{seqid=" + this.seqid return SncpRequest.class.getSimpleName() + "{seqid=" + this.seqid
+ ",serviceversion=" + this.serviceversion + ",serviceid=" + this.serviceid + ",serviceVersion=" + this.serviceVersion + ",serviceid=" + this.serviceid
+ ",actionid=" + this.actionid + ",bodylength=" + this.bodylength + ",actionid=" + this.actionid + ",bodyLength=" + this.bodyLength
+ ",bodyoffset=" + this.bodyoffset + ",remoteAddress=" + getRemoteAddress() + "}"; + ",bodyOffset=" + this.bodyOffset + ",remoteAddress=" + getRemoteAddress() + "}";
} }
@Override @Override
@@ -132,13 +124,13 @@ public class SncpRequest extends Request<SncpContext> {
this.seqid = 0; this.seqid = 0;
this.readState = READ_STATE_ROUTE; this.readState = READ_STATE_ROUTE;
this.serviceid = null; this.serviceid = null;
this.serviceversion = 0; this.serviceVersion = 0;
this.actionid = null; this.actionid = null;
this.bodylength = 0; this.bodyLength = 0;
this.bodyoffset = 0; this.bodyOffset = 0;
this.body = null; this.body = null;
this.ping = false; this.ping = false;
this.addrbytes[0] = 0; this.addrBytes[0] = 0;
super.recycle(); super.recycle();
} }
@@ -154,8 +146,8 @@ public class SncpRequest extends Request<SncpContext> {
return seqid; return seqid;
} }
public int getServiceversion() { public int getServiceVersion() {
return serviceversion; return serviceVersion;
} }
public DLong getServiceid() { public DLong getServiceid() {
@@ -167,9 +159,9 @@ public class SncpRequest extends Request<SncpContext> {
} }
public InetSocketAddress getRemoteAddress() { public InetSocketAddress getRemoteAddress() {
if (addrbytes[0] == 0) return null; if (addrBytes[0] == 0) return null;
return new InetSocketAddress((0xff & addrbytes[0]) + "." + (0xff & addrbytes[1]) + "." + (0xff & addrbytes[2]) + "." + (0xff & addrbytes[3]), return new InetSocketAddress((0xff & addrBytes[0]) + "." + (0xff & addrBytes[1]) + "." + (0xff & addrBytes[2]) + "." + (0xff & addrBytes[3]),
((0xff00 & (addrbytes[4] << 8)) | (0xff & addrbytes[5]))); ((0xff00 & (addrBytes[4] << 8)) | (0xff & addrBytes[5])));
} }
} }

View File

@@ -22,7 +22,7 @@ public class SncpResponse extends Response<SncpContext, SncpRequest> {
public static final int RETCODE_ILLSERVICEID = (1 << 1); //无效serviceid public static final int RETCODE_ILLSERVICEID = (1 << 1); //无效serviceid
public static final int RETCODE_ILLSERVICEVER = (1 << 2); //无效serviceversion public static final int RETCODE_ILLSERVICEVER = (1 << 2); //无效serviceVersion
public static final int RETCODE_ILLACTIONID = (1 << 3); //无效actionid public static final int RETCODE_ILLACTIONID = (1 << 3); //无效actionid
@@ -34,7 +34,7 @@ public class SncpResponse extends Response<SncpContext, SncpRequest> {
public static String getRetCodeInfo(int retcode) { public static String getRetCodeInfo(int retcode) {
if (retcode == RETCODE_ILLSERVICEID) return "The serviceid is invalid"; if (retcode == RETCODE_ILLSERVICEID) return "The serviceid is invalid";
if (retcode == RETCODE_ILLSERVICEVER) return "The serviceversion is invalid"; if (retcode == RETCODE_ILLSERVICEVER) return "The serviceVersion is invalid";
if (retcode == RETCODE_ILLACTIONID) return "The actionid is invalid"; if (retcode == RETCODE_ILLACTIONID) return "The actionid is invalid";
if (retcode == RETCODE_THROWEXCEPTION) return "Inner exception"; if (retcode == RETCODE_THROWEXCEPTION) return "Inner exception";
return null; return null;
@@ -84,7 +84,7 @@ public class SncpResponse extends Response<SncpContext, SncpRequest> {
offset += 2; offset += 2;
DLong.write(buffer, offset, request.getServiceid()); DLong.write(buffer, offset, request.getServiceid());
offset += 16; offset += 16;
buffer.putInt(offset, request.getServiceversion()); buffer.putInt(offset, request.getServiceVersion());
offset += 4; offset += 4;
DLong.write(buffer, offset, request.getActionid()); DLong.write(buffer, offset, request.getActionid());
offset += 16; offset += 16;
@@ -105,7 +105,7 @@ public class SncpResponse extends Response<SncpContext, SncpRequest> {
// buffer.putLong(request.getSeqid()); // buffer.putLong(request.getSeqid());
// buffer.putChar((char) SncpRequest.HEADER_SIZE); // buffer.putChar((char) SncpRequest.HEADER_SIZE);
// DLong.write(buffer, request.getServiceid()); // DLong.write(buffer, request.getServiceid());
// buffer.putInt(request.getServiceversion()); // buffer.putInt(request.getServiceVersion());
// DLong.write(buffer, request.getActionid()); // DLong.write(buffer, request.getActionid());
// buffer.put(addrBytes); // buffer.put(addrBytes);
// buffer.putChar((char) this.addrPort); // buffer.putChar((char) this.addrPort);