BsonWriter.toBuffers存在并发问题
This commit is contained in:
@@ -35,8 +35,12 @@ public class BsonByteBufferWriter extends BsonWriter {
|
||||
this.supplier = supplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuffer[] toBuffers() {
|
||||
return toBuffers(supplier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuffer[] toBuffers(Supplier<ByteBuffer> supplier) {
|
||||
if (buffers == null) return new ByteBuffer[0];
|
||||
for (int i = index; i < this.buffers.length; i++) {
|
||||
ByteBuffer buf = this.buffers[i];
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
package org.redkale.convert.bson;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.function.Supplier;
|
||||
import org.redkale.convert.*;
|
||||
import org.redkale.util.*;
|
||||
|
||||
@@ -37,8 +38,8 @@ public class BsonWriter extends Writer {
|
||||
return newdata;
|
||||
}
|
||||
|
||||
public ByteBuffer[] toBuffers() {
|
||||
return new ByteBuffer[]{ByteBuffer.wrap(content, 0, count)};
|
||||
public ByteBuffer[] toBuffers(final Supplier<ByteBuffer> supplier) {
|
||||
return ByteBufferWriter.create(supplier).put(content, 0, count).toBuffers();
|
||||
}
|
||||
|
||||
protected BsonWriter(byte[] bs) {
|
||||
|
||||
@@ -367,7 +367,7 @@ public final class SncpClient {
|
||||
return future;
|
||||
}
|
||||
final AsyncConnection conn = conn0;
|
||||
final ByteBuffer[] sendBuffers = writer.toBuffers();
|
||||
final ByteBuffer[] sendBuffers = writer.toBuffers(transport.getBufferSupplier());
|
||||
fillHeader(sendBuffers[0], seqid, actionid, reqBodyLength);
|
||||
|
||||
final ByteBuffer buffer = transport.pollBuffer();
|
||||
|
||||
@@ -65,7 +65,7 @@ public final class SncpResponse extends Response<SncpContext, SncpRequest> {
|
||||
return;
|
||||
}
|
||||
final int respBodyLength = out.count(); //body总长度
|
||||
final ByteBuffer[] buffers = out.toBuffers();
|
||||
final ByteBuffer[] buffers = out.toBuffers(context.getBufferSupplier());
|
||||
fillHeader(buffers[0], respBodyLength - HEADER_SIZE, retcode);
|
||||
finish(buffers);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user