From 8c625e93c73ac7840a816e0263963367a07cd810 Mon Sep 17 00:00:00 2001 From: redkale Date: Mon, 16 Oct 2023 20:07:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbson=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/redkale/convert/bson/BsonConvert.java | 12 ++--- .../java/org/redkale/net/client/Client.java | 44 +++++++++---------- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/src/main/java/org/redkale/convert/bson/BsonConvert.java b/src/main/java/org/redkale/convert/bson/BsonConvert.java index 2745bf686..7e57ec4f1 100644 --- a/src/main/java/org/redkale/convert/bson/BsonConvert.java +++ b/src/main/java/org/redkale/convert/bson/BsonConvert.java @@ -192,7 +192,7 @@ public class BsonConvert extends BinaryConvert { //------------------------------ convertTo ----------------------------------------------------------- @Override public byte[] convertTo(final Type type, final Object value) { - if (value == null) { + if (type == null && value == null) { final BsonWriter out = pollWriter(); out.writeNull(); byte[] result = out.toArray(); @@ -214,7 +214,7 @@ public class BsonConvert extends BinaryConvert { @Override public void convertToBytes(final Type type, final Object value, final ConvertBytesHandler handler) { final BsonWriter writer = pollWriter(); - if (type == null) { + if (type == null && type == null) { writer.writeNull(); } else { factory.loadEncoder(type).convertTo(writer, value); @@ -226,7 +226,7 @@ public class BsonConvert extends BinaryConvert { public void convertToBytes(final ByteArray array, final Type type, final Object value) { Objects.requireNonNull(array); final BsonWriter writer = configWrite(new BsonWriter(array).withFeatures(features)); - if (value == null) { + if (type == null && value == null) { writer.writeNull(); } else { factory.loadEncoder(type == null ? value.getClass() : type).convertTo(writer, value); @@ -239,7 +239,7 @@ public class BsonConvert extends BinaryConvert { } public void convertTo(final OutputStream out, final Type type, final Object value) { - if (value == null) { + if (type == null && value == null) { pollWriter(out).writeNull(); } else { factory.loadEncoder(type == null ? value.getClass() : type).convertTo(pollWriter(out), value); @@ -250,7 +250,7 @@ public class BsonConvert extends BinaryConvert { public ByteBuffer[] convertTo(final Supplier supplier, final Type type, final Object value) { Objects.requireNonNull(supplier); BsonByteBufferWriter writer = pollWriter(supplier); - if (value == null) { + if (type == null && value == null) { writer.writeNull(); } else { factory.loadEncoder(type == null ? value.getClass() : type).convertTo(writer, value); @@ -260,7 +260,7 @@ public class BsonConvert extends BinaryConvert { @Override public void convertTo(final BsonWriter writer, final Type type, final Object value) { - if (value == null) { + if (type == null && value == null) { //必须判断type==null writer.writeNull(); } else { factory.loadEncoder(type == null ? value.getClass() : type).convertTo(writer, value); diff --git a/src/main/java/org/redkale/net/client/Client.java b/src/main/java/org/redkale/net/client/Client.java index 5e0c42395..e4fff8d76 100644 --- a/src/main/java/org/redkale/net/client/Client.java +++ b/src/main/java/org/redkale/net/client/Client.java @@ -330,20 +330,18 @@ public abstract class Client, R extends ClientR if (authenticate != null) { future = future.thenCompose(authenticate); } - return future.thenCompose(c -> { - return CompletableFuture.supplyAsync(() -> { - c.setAuthenticated(true); - if (pool) { - this.connArray[connIndex] = c; - CompletableFuture f; - while ((f = waitQueue.poll()) != null) { - if (!f.isDone()) { - f.complete(c); - } + return future.thenApply(c -> { + c.setAuthenticated(true); + if (pool) { + this.connArray[connIndex] = c; + CompletableFuture f; + while ((f = waitQueue.poll()) != null) { + if (!f.isDone()) { + f.complete(c); } } - return c; - }, c.channel.getWriteIOThread()); + } + return c; }).whenComplete((r, t) -> { if (pool && t != null) { this.connOpenStates[connIndex].set(false); @@ -392,20 +390,18 @@ public abstract class Client, R extends ClientR if (authenticate != null) { future = future.thenCompose(authenticate); } - return future.thenCompose(c -> { - return CompletableFuture.supplyAsync(() -> { - c.setAuthenticated(true); - if (pool) { - entry.connection = c; - CompletableFuture f; - while ((f = waitQueue.poll()) != null) { - if (!f.isDone()) { - f.complete(c); - } + return future.thenApply(c -> { + c.setAuthenticated(true); + if (pool) { + entry.connection = c; + CompletableFuture f; + while ((f = waitQueue.poll()) != null) { + if (!f.isDone()) { + f.complete(c); } } - return c; - }, c.channel.getWriteIOThread()); + } + return c; }).whenComplete((r, t) -> { if (pool && t != null) { entry.connOpenState.set(false);