mq命名优化
This commit is contained in:
@@ -36,7 +36,9 @@ import org.redkale.util.*;
|
||||
*/
|
||||
public abstract class Sncp {
|
||||
|
||||
private static final byte[] PING_BYTES = new SncpHeader(null, Uint128.ZERO, Uint128.ZERO).writeTo(new ByteArray(SncpHeader.HEADER_SIZE), null, 0, 0, 0).getBytes();
|
||||
private static final byte[] PING_BYTES = new SncpHeader(null, Uint128.ZERO, Uint128.ZERO)
|
||||
.writeTo(new ByteArray(SncpHeader.HEADER_SIZE).putPlaceholder(SncpHeader.HEADER_SIZE), null, 0, 0, 0)
|
||||
.getBytes();
|
||||
|
||||
private static final byte[] PONG_BYTES = Arrays.copyOf(PING_BYTES, PING_BYTES.length);
|
||||
|
||||
|
||||
@@ -118,6 +118,9 @@ public class SncpHeader {
|
||||
if (newAddrBytes.length != 4) {
|
||||
throw new SncpException("address bytes length must be 4, but " + newAddrBytes.length);
|
||||
}
|
||||
if (array.length() < HEADER_SIZE) {
|
||||
throw new SncpException("ByteArray length must more " + HEADER_SIZE);
|
||||
}
|
||||
int offset = 0;
|
||||
array.putLong(offset, newSeqid); //8
|
||||
offset += 8;
|
||||
|
||||
@@ -36,6 +36,8 @@ public class SncpResponse extends Response<SncpContext, SncpRequest> {
|
||||
|
||||
protected final BsonWriter writer = new BsonWriter();
|
||||
|
||||
protected final ByteArray onlyHeaderData = new ByteArray(HEADER_SIZE).putPlaceholder(HEADER_SIZE);
|
||||
|
||||
protected final CompletionHandler realHandler = new CompletionHandler() {
|
||||
@Override
|
||||
public void completed(Object result, Object attachment) {
|
||||
@@ -168,9 +170,9 @@ public class SncpResponse extends Response<SncpContext, SncpRequest> {
|
||||
//调用此方法时out已写入SncpHeader
|
||||
public void finish(final int retcode, final BsonWriter out) {
|
||||
if (out == null) {
|
||||
final ByteArray buffer = new ByteArray(HEADER_SIZE);
|
||||
fillHeader(buffer, 0, retcode);
|
||||
finish(buffer);
|
||||
final ByteArray array = onlyHeaderData;
|
||||
fillHeader(array, 0, retcode);
|
||||
finish(array);
|
||||
return;
|
||||
}
|
||||
final ByteArray array = out.toByteArray();
|
||||
@@ -179,9 +181,9 @@ public class SncpResponse extends Response<SncpContext, SncpRequest> {
|
||||
finish(array);
|
||||
}
|
||||
|
||||
protected void fillHeader(ByteArray buffer, int bodyLength, int retcode) {
|
||||
protected void fillHeader(ByteArray array, int bodyLength, int retcode) {
|
||||
SncpHeader header = request.getHeader();
|
||||
header.writeTo(buffer, this.addrBytes, this.addrPort, header.getSeqid(), bodyLength, retcode);
|
||||
header.writeTo(array, this.addrBytes, this.addrPort, header.getSeqid(), bodyLength, retcode);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user