SncpRequest

This commit is contained in:
redkale
2024-09-09 12:38:13 +08:00
parent d5c3841198
commit 588e1eca90
2 changed files with 10 additions and 3 deletions

View File

@@ -22,8 +22,6 @@ public class SncpDispatcherServlet
private final ReentrantLock updateLock = new ReentrantLock();
private final ThreadLocal<ByteArray> localArray = Utility.withInitialThreadLocal(ByteArray::new);
protected SncpDispatcherServlet() {
super();
}
@@ -84,7 +82,7 @@ public class SncpDispatcherServlet
public void execute(SncpRequest request, SncpResponse response) throws IOException {
try {
if (request.isPing()) {
ByteArray array = localArray.get().clear();
ByteArray array = request.getTempByteArray();
int headerSize = SncpHeader.calcHeaderSize(request);
array.putPlaceholder(headerSize);
response.writeHeader(array, 0, 0);

View File

@@ -9,6 +9,7 @@ import java.io.Serializable;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Objects;
import java.util.function.Function;
import java.util.logging.Level;
import org.redkale.convert.*;
import org.redkale.convert.bson.BsonReader;
@@ -31,6 +32,10 @@ public class SncpRequest extends Request<SncpContext> {
protected static final int READ_STATE_END = 4;
private static final String tbaName = "_tba";
private static final Function<String, ByteArray> tbaFunc = s -> new ByteArray();
protected final BsonReader reader = new BsonReader();
protected int readState = READ_STATE_ROUTE;
@@ -215,4 +220,8 @@ public class SncpRequest extends Request<SncpContext> {
public SncpHeader getHeader() {
return header;
}
public ByteArray getTempByteArray() {
return getSubobjectIfAbsent(tbaName, tbaFunc).clear();
}
}