mq命名优化

This commit is contained in:
redkale
2023-04-03 09:32:44 +08:00
parent 188a74423b
commit 22fd2212de
10 changed files with 43 additions and 37 deletions

View File

@@ -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);

View File

@@ -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;

View File

@@ -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);
}
}